norniy/auto-cyberchef
GitHub: norniy/auto-cyberchef
一款自动检测与解码多层嵌套编码的 CLI 工具,提升 CTF 与安全分析效率。
Stars: 58 | Forks: 28
# AutoCyberChef 🔍
[](https://www.python.org/)
[](LICENSE)
[]()
[]()
## ✨ 为什么选择 AutoCyberChef?
在参加 CTF 挑战或进行安全分析时,你经常会遇到类似以下字符串:
```
U0dWc2JIOD0=
```
它是 Base64 吗?双重编码?Hex 中的 ROT13?手动一层层剥开会浪费时间。
AutoCyberChef 可以**自动**检测并解开编码层——在数秒内给出答案,而不是几分钟。
```
$ python main.py auto U0dWc2JIOD0=
Layer 1: [Base64] → SGVsbG8=
Layer 2: [Base64] → Hello
Final result: Hello
```
## 🚀 快速开始
```
git clone https://github.com/norniy/auto-cyberchef.git
cd auto-cyberchef
pip install -r requirements.txt
python main.py shell
```
## 📦 安装
**要求:** Python 3.9 或更高版本。无重量级依赖——核心功能仅使用标准库。
```
# 克隆仓库
git clone https://github.com/norniy/auto-cyberchef.git
cd auto-cyberchef
# 安装可选开发依赖(pytest 用于运行测试)
pip install -r requirements.txt
# 验证安装
python main.py --version
```
## 🎮 功能特性
| 功能 | 描述 |
|---|---|
| **自动检测** | 识别 Base64、Hex、二进制、URL、ROT13、Morse、HTML、凯撒密码、Base32 |
| **自动解码** | 自动解开最多 10 层嵌套编码 |
| **编码** | 将明文编码为 Base64、Base32、Hex、二进制、URL、HTML、ROT13、Morse |
| **交互式 Shell** | 支持命令历史与 Tab 补全的 REPL |
| **批量文件解码** | 一条命令解码文件的每一行 |
| **暴力模式** | 同时尝试所有解码器并显示所有结果 |
| **置信度评分** | 为每种检测到的编码提供概率评分 |
| **JSON 输出** | 机器可读的输出,便于流水线集成 |
## 📖 使用方法
### 交互式 Shell(推荐)
```
python main.py shell
```
```
autochef > decode SGVsbG8=
Detected: Base64
Result: Hello
autochef > encode Hello -e base64
Encoding: base64
Result: SGVsbG8=
autochef > detect 48656c6c6f
Possible encodings:
- Hex
- Base64
autochef > auto U0dWc2JIOD0=
2 layer(s) found:
Layer 1: [Base64] → SGVsbG8=
Layer 2: [Base64] → Hello
Final: Hello
autochef > brute "Uryyb Jbeyq"
✓ ROT13 Hello World
✓ Caesar Hello World
autochef > history
autochef > exit
```
Shell 在 Unix/macOS 上支持使用 ↑/↓ 方向键进行命令历史导航。
### 单次命令
#### `decode` — 解码字符串
```
# 自动检测编码并解码
python main.py decode SGVsbG8=
# 强制使用特定编码
python main.py decode 48656c6c6f -e hex
python main.py decode "Uryyb Jbeyq" -e rot13
python main.py decode ".... . .-.. .-.. ---" -e morse
# 输出为 JSON
python main.py decode SGVsbG8= --json
```
**输出:**
```
Detected encoding: Base64
Decoded result: Hello
```
#### `encode` — 编码字符串
```
# 将明文编码为目标格式
python main.py encode "Hello" -e base64
python main.py encode "Hello" -e hex
python main.py encode "Hello World" -e morse
python main.py encode "Hello" -e binary
python main.py encode "Hello World!" -e url
python main.py encode "Hello" -e html
python main.py encode "Hello" -e rot13
# 输出为 JSON
python main.py encode "Hello" -e base64 --json
```
**输出:**
```
Encoded [base64]:
SGVsbG8=
Encoded [morse]:
.... . .-.. .-.. --- / .-- --- .-. .-.. -..
```
#### `detect` — 识别编码类型
```
# 列出可能的编码
python main.py detect SGVsbG8=
# 显示置信度分数
python main.py detect SGVsbG8= --confidence
```
**输出:**
```
Possible encodings:
- Base64
Encoding confidence scores:
Base64 ████████████████████ 95.0%
```
#### `auto` — 多层自动解码
```
# 自动展开所有层
python main.py auto U0dWc2JIOD0=
# 显示逐步进度
python main.py auto U0dWc2JIOD0= --verbose
# 限制解码深度
python main.py auto U0dWc2JIOD0= --max-layers 5
```
**输出:**
```
Auto-decode: 2 layer(s) found
Layer 1: [Base64] → SGVsbG8=
Layer 2: [Base64] → Hello
Final result: Hello
```
#### `decode-file` — 批量解码文件
```
# 逐行解码文件
python main.py decode-file encoded.txt
# 保存输出到文件
python main.py decode-file encoded.txt -o decoded.txt
# 显示逐层详细信息
python main.py decode-file encoded.txt --layers
# 强制所有行使用特定编码
python main.py decode-file encoded.txt -e base64
# 输出为 JSON
python main.py decode-file encoded.txt --json
```
示例输入文件(`encoded.txt`):
```
SGVsbG8=
48656c6c6f
.... . .-.. .-.. ---
```
输出:
```
Hello
Hello
HELLO
Processed 3 line(s): 3 decoded, 0 failed
```
#### `brute` — 尝试所有解码器
```
# 尝试所有解码器
python main.py brute SGVsbG8=
# 同时显示失败的尝试
python main.py brute SGVsbG8= --show-failures
# 包含全部 25 种凯撒移位
python main.py brute "Khoor" --caesar
```
#### `stats` — 文件编码统计
```
python main.py stats encoded.txt
```
**输出:**
```
File statistics: encoded.txt
Total lines: 10
Decoded lines: 9
Failed lines: 1
Encoding breakdown:
Base64 6
Hex 3
```
## 🔤 支持的编码
| 编码 | 解码 | 编码 | 解码示例 | 编码示例 |
|---|---|---|---|---|
| Base64 | ✅ | ✅ | `SGVsbG8=` → `Hello` | `Hello` → `SGVsbG8=` |
| Base32 | ✅ | ✅ | `JBSWY3DP` → `Hello` | `Hello` → `JBSWY3DP` |
| 十六进制 | ✅ | ✅ | `48656c6c6f` → `Hello` | `Hello` → `48656c6c6f` |
| 二进制 | ✅ | ✅ | `01001000...` → `Hello` | `Hello` → `01001000 01100101...` |
| URL 编码 | ✅ | ✅ | `Hello%20World%21` → `Hello World!` | `Hello World!` → `Hello%20World%21` |
| HTML 实体 | ✅ | ✅ | `He...` → `Hello` | `Hi` → `<b>Hi</b>` |
| ROT13 | ✅ | ✅ | `Uryyb` → `Hello` | `Hello` → `Uryyb` |
| Morse 码 | ✅ | ✅ | `.... . .-.. .-.. ---` → `HELLO` | `HELLO` → `.... . .-.. .-.. ---` |
| 凯撒密码 | ✅ | ❌ | `Khoor`(位移 3)→ `Hello` | — |
## 🏗️ 项目结构
```
auto-cyberchef/
│
├── autochef/
│ ├── __init__.py # Package entry point and public API
│ ├── detector.py # Encoding detection (regex + heuristics + confidence scoring)
│ ├── decoder.py # Individual decode implementations for all formats
│ ├── pipeline.py # Multi-layer auto-decode orchestration
│ ├── file_handler.py # Batch file processing and JSON output
│ └── utils.py # Shared helpers (entropy, printability, string analysis)
│
├── tests/
│ └── test_basic.py # 84 unit tests covering all modules
│
├── main.py # CLI entry point (argparse + interactive shell)
├── requirements.txt
└── README.md
```
## 🔌 作为 Python 库使用
AutoCyberChef 可以直接导入到你的脚本中:
```
from autochef.detector import detect_encoding, get_encoding_confidence
from autochef.decoder import decode_base64, decode_hex, decode_by_name
from autochef.pipeline import auto_decode
# 检测编码
encodings = detect_encoding("SGVsbG8=")
print(encodings) # ['Base64']
# 获取置信度分数
scores = get_encoding_confidence("SGVsbG8=")
print(scores) # {'Base64': 0.95}
# 按格式解码
result, success = decode_base64("SGVsbG8=")
print(result) # Hello
# 按名称解码
result, success = decode_by_name("hex", "48656c6c6f")
print(result) # Hello
# 自动多层解码
steps, final = auto_decode("U0dWc2JIOD0=")
print(final) # Hello
for encoding, before, after in steps:
print(f"{encoding}: {before} -> {after}")
```
## 🧪 运行测试
```
# 运行全部 84 个测试
python -m unittest tests.test_basic -v
# 运行特定测试类
python -m unittest tests.test_basic.TestPipeline -v
# 使用 pytest 运行(如果已安装)
pytest tests/ -v
```
## 🤝 贡献
欢迎贡献!以下是一些入门方式:
- 🐛 **报告错误**:通过 [问题](https://github.com/norniy/auto-cyberchef/issues) 提交
- ✨ **请求功能**:通过 `enhancement` 标签的问题提出
- 🔧 **修复错误或添加功能**:提交拉取请求
### 适合新手的任务
寻找标记为 [`good first issue`](https://github.com/norniy/auto-cyberchef/issues?q=label%3A%22good+first+issue%22) 的问题:
- 添加对新编码的支持(Base58、XOR 等)
- 添加更多测试用例
- 修复拼写错误或文档空白
### 开发环境设置
```
git clone https://github.com/norniy/auto-cyberchef.git
cd auto-cyberchef
pip install -r requirements.txt
python -m unittest tests.test_basic -v # make sure all tests pass before contributing
```
## 📄 许可证
本项目根据 [MIT 许可证](LICENSE) 授权。
## 🔗 相关项目
- [CyberChef](https://github.com/gchq/CyberChef) — 原始的基于 Web 的“瑞士军刀”
- [Ciphey](https://github.com/Ciphey/Ciphey) — AI 驱动的自动解密工具
AutoCyberChef 不同:**无需浏览器,无重量级 ML 依赖**——仅需 Python 3.9+ 和标准库。
为 CTF 选手、安全研究人员以及任何在手动解码字符串上花费太多时间的人而制作。
如果此工具为您节省了时间,请考虑给它一个 ⭐
标签:API安全, Base32, Base64, CLI, Hex, HTML编码, JSON输出, Morse码, PoC, Python, Python3.9+, REPL, ROT13, URL编码, WiFi技术, 二进制, 二进制发布, 云资产清单, 交互式shell, 代码行数统计, 凯撒密码, 动态分析, 字符编码, 开源工具, 批量处理, 文本解码, 无后门, 暴力破解, 编码检测, 网络安全, 置信度评分, 自动剥层, 自动化分析, 自动解码, 跨站脚本, 逆向工具, 逆向工程, 隐私保护