Nariod/RustPacker

GitHub: Nariod/RustPacker

一款基于 Rust 的模板化 shellcode 打包工具,专为渗透测试和红队设计,可将原始 shellcode 转换为具备多种规避能力的 Windows 二进制文件。

Stars: 333 | Forks: 33



只需一条命令,即可在任何操作系统上,将原始 shellcode 转换为具有规避能力的 Windows 二进制文件。
专为经过授权的渗透测试人员和红队操作人员设计。

## 🤔 新手入门?请先阅读本节 ### 什么是 RustPacker? **Shellcode** 是由 C2 框架(Metasploit、Sliver、Cobalt Strike 等)生成的一小段机器码,用作 payload。它本身只是一串字节,需要一个*加载器*才能在目标 Windows 机器上运行。 **RustPacker 就是这样一个加载器生成器。** 它会获取你的 shellcode,并将其封装在一个 Rust 程序中,该程序负责处理: - **加密** — 使 payload 在磁盘和内存中看起来像随机字节 - **注入** — 将代码映射到 Windows 进程中并执行 - **规避** — 降低被 EDR/AV 传感器检测到的几率 最终生成的是一个 `.exe` 或 `.dll` 文件,供你在经过授权的测试项目中投递给目标。 ### ✨ 核心功能 - **多种注入模板** — CRT、APC、Fibers、EarlyCascade 等… - **加密** — XOR、AES-256、UUID 编码 - **Syscall 规避** — 使用间接 syscall 绕过 EDR 的用户态 hooks - **EXE 和 DLL 输出** — 包括 DLL 代理 / 侧加载 - **沙箱规避** — 域名锁定可防止在分析沙箱中被触发执行 - **跨平台构建** — 通过 Podman 或 Docker 在 Linux、Windows、macOS 上运行 ## 🚀 快速开始(Linux — 推荐方案) ### 第 1 步 — 安装 Podman ``` # Ubuntu / Debian sudo apt install podman # Fedora / RHEL sudo dnf install podman ``` 验证:`podman --version` ### 第 2 步 — 克隆并构建容器 ``` git clone https://github.com/Nariod/RustPacker.git cd RustPacker/ podman build -t rustpacker -f Dockerfile ``` 此步骤只需执行**一次**。之后镜像将在本地缓存。 ### 第 3 步 — 你的首次构建 1. 使用 msfvenom 生成测试 shellcode(一个无害的 `MessageBox` 弹窗): ``` msfvenom -p windows/x64/messagebox TEXT="RustPacker works!" TITLE="Test" -f raw -o shared/test.raw ``` 2. 打包: ``` podman run --rm -v $(pwd)/shared:/usr/src/RustPacker/shared:z rustpacker RustPacker \ -f shared/test.raw -i ntcrt -e aes -b exe -t notepad.exe ``` 3. 查找你的二进制文件: ``` [+] Source binary has been renamed to: "shared/output_1234567890/target/x86_64-pc-windows-gnu/release/AbCdEfGh.exe" ``` 编译后的 `.exe` 位于 `shared/output_/target/x86_64-pc-windows-gnu/release/` 目录中。 ### 创建别名以方便使用 将其添加到你的 `~/.bashrc` 或 `~/.zshrc` 中,以避免每次都输入完整的 `podman run` 命令: ``` alias rustpacker='podman run --rm -v $(pwd)/shared:/usr/src/RustPacker/shared:z rustpacker RustPacker' ``` 然后直接使用: ``` rustpacker -f shared/payload.raw -i syscrt -e aes -b exe -t explorer.exe ```
🪟 Windows 设置说明 ### 第 1 步:安装容器运行环境 **选项 A — Podman Desktop(推荐):** 1. 下载并安装 [Podman Desktop](https://podman-desktop.io/) 2. 启动 Podman Desktop 并按照引导设置初始化 Podman 机器 3. 验证:`podman --version` **选项 B — Docker Desktop:** 1. 下载并安装 [Docker Desktop](https://www.docker.com/products/docker-desktop/) 2. 在安装过程中启用 WSL 2 后端(推荐) 3. 验证:`docker --version` ### 第 2 步:克隆并构建 ``` git clone https://github.com/Nariod/RustPacker.git cd RustPacker podman build -t rustpacker -f Dockerfile ``` ### 第 3 步:打包 Shellcode ``` # 将你的 shellcode 放置在 shared 文件夹中 copy C:\path\to\payload.raw shared\ # PowerShell podman run --rm -v ${PWD}/shared:/usr/src/RustPacker/shared:z rustpacker RustPacker ` -f shared/payload.raw -i ntcrt -e aes -b exe -t notepad.exe # cmd.exe podman run --rm -v %cd%/shared:/usr/src/RustPacker/shared:z rustpacker RustPacker ^ -f shared/payload.raw -i ntcrt -e aes -b exe -t notepad.exe ``` **PowerShell 别名:** ``` function rustpacker { podman run --rm -v "${PWD}/shared:/usr/src/RustPacker/shared:z" rustpacker RustPacker @args } ```
🍎 macOS 设置说明 ``` brew install podman podman machine init podman machine start git clone https://github.com/Nariod/RustPacker.git cd RustPacker/ podman build -t rustpacker -f Dockerfile alias rustpacker='podman run --rm -v $(pwd)/shared:/usr/src/RustPacker/shared:z rustpacker RustPacker' rustpacker -f shared/payload.raw -i ntcrt -e aes -b exe -t notepad.exe ```
🦀 替代方案:原生模式(需要 Rust 工具链) 如果你已经安装了 Rust,可以直接运行 RustPacker,而无需先构建容器。它会**自动检测** Podman 或 Docker,并仅在交叉编译时使用容器: ``` git clone https://github.com/Nariod/RustPacker.git cd RustPacker/ cargo build --release # Linux / macOS cargo run -- -f shared/your_shellcode.raw -i ntcrt -e aes -b exe -t notepad.exe # Windows (PowerShell) cargo run -- -f shared\your_shellcode.raw -i ntcrt -e aes -b exe -t notepad.exe ``` 首次运行会构建一次 `rustpacker-builder` 镜像。后续运行将重用缓存的镜像和共享的 cargo registry 卷,以实现快速构建。
## 🛠️ 选择模板 | 我想要… | 推荐模板 | |------------|---------------------| | 注入到**另一个进程**(例如 notepad、explorer) | `ntcrt`(隐蔽)或 `syscrt`(最大程度规避) | | 在**当前进程**内运行(自注入) | `ntapc` 或 `ntfiber` | | 作为** DLL** 运行,在加载时触发 | `ntapc`、`winfiber`、`ntfiber` 或 `sysfiber` | | 最大程度的 **syscall 规避** | `syscrt`(远程)或 `sysfiber`(自身) | | 最小依赖,快速测试 | `wincrt`(远程)或 `winfiber`(自身) | | Shim 引擎 / EarlyCascade 技术 | `earlycascade` | ### 进程注入模板(与 `-t ` 配合使用) 这些模板将 shellcode 注入到远程进程中。默认目标:`dllhost.exe`。 | 模板 | API 级别 | 间接 Syscalls | 动态 API | 描述 | |----------|-----------|:-----------------:|:-----------:|-------------| | `wincrt` | 高 (Windows-rs) | ❌ | ❌ | 通过官方 Windows crate 调用 CreateRemoteThread | | `ntcrt` | 低 (ntapi) | ❌ | ✅ | 通过动态解析 NT API 调用 NtCreateThreadEx | | `syscrt` | Syscall | ✅ | ❌ | 通过间接 syscall 调用 NtCreateThreadEx | | `earlycascade` | 低 (winapi) | ❌ | ❌ | 通过劫持 shim 引擎回调实现 EarlyCascade 注入 | ### 自执行模板(无需 `-t`) 这些模板在当前进程内执行 shellcode。 | 模板 | API 级别 | 间接 Syscalls | 动态 API | 描述 | |----------|-----------|:-----------------:|:-----------:|-------------| | `ntapc` | 低 | ❌ | ✅ | 通过动态解析 NT API 向当前线程队列发送 APC | | `winfiber` | 高 (windows-sys) | ❌ | ❌ | 通过 Windows API 进行基于 Fiber 的执行 | | `ntfiber` | 低 (ntapi + windows-sys) | ❌ | ✅ | 通过动态解析 NT API 进行基于 Fiber 的执行 | | `sysfiber` | Syscall (ntapi + windows-sys) | ✅ | ❌ | 通过间接 syscall 进行基于 Fiber 的执行 | ## 📖 命令行选项 ``` Usage: RustPacker -f -b -i