memN0ps/doublepulsar-rs
GitHub: memN0ps/doublepulsar-rs
基于 Rust 的 Cobalt Strike 反射式加载器,集成模块镂空、堆栈欺骗、休眠混淆和系统调用等多层次 EDR 规避技术。
Stars: 3 | Forks: 0
## DoublePulsar
Cobalt Strike 用户自定义反射式加载器 (UDRL),使用 Rust 开发,实现了 Shellcode 反射式 DLL 注入 (sRDI)。这是一个约 65KB 的位置无关反射式加载器,具备模块镂空、合成调用堆栈欺骗、休眠混淆、内存加密、返回地址欺骗、IAT Hook 和堆隔离 功能。
以 [DoublePulsar](https://en.wikipedia.org/wiki/DoublePulsar) 命名,这是由 NSA 的 [Equation Group](https://en.wikipedia.org/wiki/Equation_Group) 开发的植入程序,于 2017 年被 Shadow Brokers 泄露。
## 前置加载器架构
与 Stephen Fewer 的原始方法(反射式加载器位于 PE 的 `.text` 节内)不同,DoublePulsar 采用前置架构,将 `ReflectiveLoader()` 放置在 PE 文件之前。这允许加载器成为完全位置无关的 shellcode,在运行时解密并映射 beacon payload。

*图表来自 Robert Bearsby / [Cobalt Strike](https://www.cobaltstrike.com/) 的 [Revisiting the UDRL Part 1](https://www.cobaltstrike.com/blog/revisiting-the-udrl-part-1-simplifying-development)*
## 功能特性
- 适用于 Cobalt Strike 的位置无关 Rust 反射式加载器(前置加载器)
- 模块镂空(将 beacon 加载到合法模块的内存中,默认启用)
- 合成调用堆栈欺骗(每次调用随机化,默认通过 `spoof-uwd` 启用)。需要模块镂空或调用堆栈欺骗之一,但首选模块镂空。调用堆栈欺骗作为备选方案
- 动态内存加密(为 beacon 分配新的堆,在休眠期间加密)
- 代码混淆和加密(不可执行 + 休眠期间加密)
- 返回地址欺骗(InternetConnectA, NtWaitForSingleObject, RtlAllocateHeap)
- IAT Hook
- 堆隔离
- 通过 SystemFunction032 进行 RC4 加密
- 可选的 syscall 调度(虽然有点尴尬,但它就在那里 :roll_eyes:)(`spoof-syscall` 功能,需要 `spoof-uwd`)。在未挂钩时使用 [Hell's Gate](https://github.com/am0nsec/HellsGate) 进行直接系统调用,在检测到挂钩时回退到 Halo's Gate / [Tartarus Gate](https://github.com/trickster0/TartarusGate) 进行间接系统调用
- 多种休眠混淆技术:
| 功能 | 技术 | 描述 |
|---------|-----------|-------------|
| `sleep-ekko` | Ekko | 基于定时器 (TpAllocTimer/TpSetTimer) + RC4 + NtContinue 链 + fiber 支持 **(默认)** |
| `sleep-foliage` | FOLIAGE | 基于 APC (NtQueueApcThread) + RC4 + NtContinue 链 + fiber 支持 |
| `sleep-zilean` | Zilean | 基于等待 (TpAllocWait/TpSetWait) + RC4 + NtContinue 链 + fiber 支持 |
| `sleep-xor` | XOR | XOR 节掩盖 + 普通 Sleep (无 CONTEXT 链,无 fiber 模式) |
## 工作原理
在生成 shellcode 之前导入 `Titan.cna` 脚本。该脚本:
1. 获取您的原始 beacon payload
2. 使用随机的 16 字节密钥对其进行 RC4 加密
3. 将 `[CONFIG (key + size)][Encrypted Beacon]` 附加到加载器
4. 在运行时,加载器在内存中解密 beacon 并执行它
## 构建
仅支持 x64。不支持 x86。
建议:在 Ubuntu/WSL 上构建,以避免 Windows 上的 MinGW 重定位问题。
### 系统要求
- 具有 `x86_64-pc-windows-gnu` 目标的 Rust nightly
- MinGW-w64
- [cargo-make](https://github.com/sagiegurari/cargo-make)
- nasm
### Ubuntu/WSL 设置(推荐)
```
# 安装 Rust nightly 并添加 target
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup toolchain install nightly
rustup default nightly
rustup target add x86_64-pc-windows-gnu
# 安装 MinGW-w64 和 nasm
sudo apt update
sudo apt install -y mingw-w64 nasm
# 安装 cargo-make
cargo install cargo-make
# 构建
cd udrl
cargo make x64
```
### 构建命令
```
cargo make x64 # x64 release
cargo make x64-debug # x64 with debug logging (DbgPrint)
cargo make clean # clean build artifacts
```
### 休眠功能选择
一次只能启用一个休眠功能。它们是互斥的。选择非默认技术时请使用 `--no-default-features`。
```
# Ekko (默认)
cargo make x64
# FOLIAGE
cargo build --release --target x86_64-pc-windows-gnu --features sleep-foliage --no-default-features
# Zilean
cargo build --release --target x86_64-pc-windows-gnu --features sleep-zilean --no-default-features
# XOR (无 ROP chain, 无 fiber)
cargo build --release --target x86_64-pc-windows-gnu --features sleep-xor --no-default-features
```
### 输出
```
bin/Titan.x64.bin - x64 shellcode
```
## 检测
在 Windows 10 (Build 19045) 和 Windows 11 (Build 22631) 上针对 Elastic 9.0.1 (试用版) 进行了测试,测试环境为预防模式,启用了激进设置和以下集成:Elastic Defend、Elastic Agent、Fleet Server、Prebuilt Security Detection Rules、Elastic Synthetics、System 和 Windows。Cobalt Strike 设置:Stageless Windows Executable、Raw 输出、x64 payload、Process exit function、winhttp 库。实验环境:[Ludus](https://docs.ludus.cloud/docs/environment-guides/goad) 上的 [GOAD](https://github.com/Orange-Cyberdefense/GOAD)。
用于检测的 YARA 规则在 [doublepulsar.yar](doublepulsar.yar) 中提供。
## 已知问题
- 与依赖 shellcode 线程保持活跃的加载器不兼容
- Windows 构建可能会在较新的 MinGW 版本中遇到重定位错误(请使用 WSL)
- 当过多的日志条目刷屏时,AllocConsole 日志记录可能会导致崩溃,请改用 DbgPrint
## 许可证和免责声明
**许可证**:MIT。参见 [LICENSE](./LICENSE)
**免责声明**:本项目仅用于授权的安全测试、教育目的和合法的安全研究。
**允许的用途包括:**
- 授权的渗透测试和红队活动
- 紫队、对手模拟和威胁仿真
- 检测工程、威胁追踪和安全运营
- 蓝队和 SOC 活动,包括恶意软件逆向工程
- CTF 竞赛和安全研究
- 教育和培训目的
**禁止的用途包括:**
- 未经授权访问系统或网络
- 任何违反适用法律或法规的活动
- 未经明确书面授权针对系统的使用
**责任**:作者对因使用本软件而产生的滥用、损害或法律后果不承担任何责任。用户应全权负责确保遵守所有适用的法律、法规和组织政策。使用本软件即表示您同意您对与之交互的任何系统拥有适当的授权。
## 作者
[memN0ps](https://github.com/memN0ps)
标签:Beacon, Cobalt Strike, DNS 反向解析, DoublePulsar, EDR 绕过, Evasion, IAT Hook, Red Team, Return Address Spoofing, Rust, Shellcode, Shell模拟, sRDI, 位置无关代码, 内存加密, 反射式加载, 可视化界面, 堆隔离, 技术调研, 攻击诱捕, 模块覆盖, 睡眠混淆, 绕过检测, 网络流量审计, 调用栈欺骗, 通知系统