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.2.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.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: solarpeng_data_process-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 223fc4d64eaddd798f9e485b38f13a51bc5a6701eb15fde9f0bc4b3b72d06ed7
MD5 26f16e1378f8bbd2c5216e06f46e64ea
BLAKE2b-256 7aca4c144894a22ce42f266da413b6b3d0d432b7b37f770fab676fe56afd858e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for solarpeng_data_process-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df38d15aeac0422355e8bf23e6db2d29c56162c01ef17d71c9c4c4d19131910a
MD5 b883d31329a641b5193e1983645571a1
BLAKE2b-256 4054a5589a54f23e86f684a14821fd4db3a73834f6665b04e157c641b86e5298

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