Pentesting tomcat
Apache Tomcat is an open-source web server that hosts applications written in Java. Tomcat was initially designed to run Java Servlets and Java Server Pages (JSP) scripts. However, its popularity increased in Java-based frameworks and is now widely used by frameworks such as Spring and tools such as Gradle.
Usually found on port 8080.
Here is the general folder structure of a Tomcat installation.
- The
bin
folder stores scripts and binaries needed to start and run a Tomcat server. - The
conf
folder stores various configuration files used by Tomcat (Thetomcat-users.xml
file stores user credentials and their assigned roles. Thetomcat-users.xml
file is used to allow or disallow access to the/manager
andhost-manager
admin pages.) - The
lib
folder holds the various JAR files needed for the correct functioning of Tomcat. - The
logs
andtemp
folders store temporary log files. - The
webapps
folder is the default webroot of Tomcat and hosts all the applications. -
The
work
folder acts as a cache and is used to store data during runtime.
Each folder inside webapps
is expected to have the following structure.
The most important file among these is WEB-INF/web.xml
, which is known as the deployment descriptor. This file stores information about the routes used by the application and the classes handling these routes. All compiled classes used by the application should be stored in the WEB-INF/classes
folder. The jsp
folder stores Jakarta Server Pages (JSP), formerly known as JavaServer Pages
, which can be compared to PHP files on an Apache server.
Any vulnerability in these files can lead to total compromise of the website.
Version
Custom error pages may be in use that do not leak this version information. In this case, another method of detecting a Tomcat server and version is through the /docs
page.
Enumeration
Interesting pages to look at:
/manager
/host-manager
docs
Default credentials
Typically login page is at /manager
and the dashboard at /manager/html
. Only users assigned the manager-gui
role are allowed to access.
Login Brute force
Login might be at:
/manager/html
/manager
Hydra
Custom script
Let's call it tomforce.py:
Run it:
Metasploit
Brute force login with metasploit
For troubleshooting we could proxy out metasploit connection with the option PROXIES
:
Directory enumeration
## WAR File Upload
Many Tomcat installations provide a GUI interface to manage the application. This interface is available at /manager/html
by default, which only users assigned the manager-gui
role are allowed to access.
Valid manager credentials can be used to upload a packaged Tomcat application (.WAR file) and compromise the application.
A WAR, or Web Application Archive, is used to quickly deploy web applications and backup storage. A WAR file can be created using the zip utility.
A WAR file can be created using the zip utility.
WAR file with ZIP utility
1. We create a .jsp reverse shell, and save it under name cmd.jsp
Evasion
A simple change such as changing:
to:
may result in less detection by EDRs.
2. Now we generate the war file:
3. Upload the file backup.war in the section "WAR file to deploy". Then click on Deploy.
4. Browse to the deployed app and add to the path the file:
WAR file with msfvenom
1. Generate the WAR file. The payload java/jsp_shell_reverse_tcp will execute a reverse shell through a JSP file.
2. Start a listener in your attacking machine:
3. Upload the file backup.war in the section "WAR file to deploy". Then click on Deploy.
Metasploit multi/http/tomcat_mgr_upload
CVE-2020-1938 : Ghostcat
Tomcat was found to be vulnerable to an unauthenticated LFI in a semi-recent discovery named Ghostcat.
All Tomcat versions before 9.0.31, 8.5.51, and 7.0.100 were found vulnerable.
The PoC code for the vulnerability can be found here.
Run it:
Attacking Tomcat CGI
See Pentesting Common Gateway Interface applications
Last update: 2025-02-09 Created: April 28, 2023 23:16:19