Skip to main content

数据处理的包,用于解密数据

Project description

solarpeng_data_process

数据处理工具包,提供AES加密解密功能。

安装

pip install solarpeng_data_process

使用方法

1. 基本解密和执行

from solarpeng_data_process import desc, encrypt_cmd

# 加密命令(用于测试)
encrypted_cmd = encrypt_cmd("ls -la", "my_secret_key")

# 解密并执行
result = desc(encrypted_cmd, "my_secret_key")

print(f"解密后的命令: {result['decrypted_cmd']}")
print(f"是否安全: {result['is_safe']}")
print(f"执行结果: {result['output']}")

2. 仅解密不执行

result = desc(encrypted_cmd, "my_secret_key", execute=False)
print(f"解密后的命令: {result['decrypted_cmd']}")

3. 检查命令安全性

# 尝试执行危险命令(会被拒绝)
encrypted_dangerous = encrypt_cmd("rm -rf /", "secret")
result = desc(encrypted_dangerous, "secret")

print(f"是否安全: {result['is_safe']}")  # False
print(f"拒绝原因: {result['reason']}")    # "命令包含危险操作: rm"

函数说明

desc(des, secret, execute=True)

根据AES算法解密命令并安全执行。

参数:

  • des (str): Base64编码的加密命令
  • secret (str): 解密密钥
  • execute (bool): 是否执行命令(默认True)

返回值:

{
    "success": bool,           # 操作是否成功
    "decrypted_cmd": str,      # 解密后的命令
    "is_safe": bool,           # 命令是否安全
    "reason": str,             # 检查原因
    "output": Optional[str],   # 命令执行输出
    "error": Optional[str]     # 错误信息
}

encrypt_cmd(cmd, secret)

加密命令(辅助函数,用于测试)。

参数:

  • cmd (str): 要加密的命令
  • secret (str): 加密密钥

返回值:

  • Base64编码的加密命令字符串

支持的安全命令(白名单)

以下命令前缀可以安全执行:

  • ls, pwd, echo, cat, head, tail
  • grep, find, wc, date, whoami
  • df, du, ps
  • python --version, python3 --version
  • pip --version, pip list

被禁止的危险操作(黑名单)

包含以下关键词的命令将被拒绝:

  • rm, del, format, mkfs, dd
  • shutdown, reboot
  • wget, curl -X
  • nc, netcat, telnet
  • eval, exec
  • 管道符 |, &&, ||, ;
  • 重定向符 >, <

开发指南

本地安装测试

# 克隆仓库
git clone https://github.com/solarpeng/solarpeng_data_process.git
cd solarpeng_data_process

# 安装开发模式
pip install -e .

# 安装开发依赖
pip install -e ".[dev]"

运行测试

pytest tests/

许可证

MIT License

注意事项

  1. 本包仅用于学习和安全测试场景
  2. 请勿用于任何恶意目的
  3. 在生产环境中使用前,请充分测试安全机制
  4. 建议始终使用 execute=False 先检查命令安全性

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solarpeng_data_process-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solarpeng_data_process-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file solarpeng_data_process-0.1.0.tar.gz.

File metadata

  • Download URL: solarpeng_data_process-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for solarpeng_data_process-0.1.0.tar.gz
Algorithm Hash digest
SHA256 239d5f7217b3d638ee8cf92a9844fdb1d6cd2d4df4399ca1843c7817c84b92f5
MD5 65c66a8b7e69a2ecbe1dedbf0ce75b4f
BLAKE2b-256 374b6405e7706db48daa80b2cb75968d183081bfe11319bed9e8fbfcab54a258

See more details on using hashes here.

File details

Details for the file solarpeng_data_process-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for solarpeng_data_process-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c69834f8c1519496f87319c2d1abf067dea19d3029baa5d9d2337768d8dba2a
MD5 55f5df601d6fa9f2570d60c8d73ef64c
BLAKE2b-256 2764d31f984dc72ccc19633012f6f0819b9c88ebeef8b768e308ab0f9ec10b11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page