Tomcat Attacks
Discovery/Footprinting
general folder structure of a Tomcat installation.
The
bin
folder stores scripts and binaries needed to start and run a Tomcat serverThe
conf
folder stores various configuration files used by Tomcat.The
tomcat-users.xml
file stores user credentials and their assigned roles.The
lib
folder holds the various JAR files needed for the correct functioning of Tomcat. Thelogs
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 descriptorThis 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.These classes might contain important business logic as well as sensitive information
Any vulnerability in these files can lead to total compromise of the website.
The
lib
folder stores the libraries needed by that particular application.Here’s an example web.xml file.
The
web.xml
configuration above defines a new servlet namedAdminServlet
that is mapped to the classcom.inlanefreight.api.AdminServlet
.Java uses the dot notation to create package names, meaning the path on disk for the class defined above would be:
classes/com/inlanefreight/api/AdminServlet.class
Next, a new servlet mapping is created to map requests to
/admin
withAdminServlet
This configuration will send any request received for
/admin
to theAdminServlet.class
class for processing.
The
web.xml
descriptor holds a lot of sensitive information and is an important file to check when leveraging a Local File Inclusion (LFI) vulnerability.The
tomcat-users.xml
file is used to allow or disallow access to the/manager
andhost-manager
admin pages.
The file shows us what each of the roles
manager-gui
,manager-script
,manager-jmx
, andmanager-status
provide access to.In this example, we can see that a user
tomcat
with the passwordtomcat
has themanager-gui
role, and a second weak passwordadmin
is set for the user accountadmin
Enumeration
After fingerprinting the Tomcat instance, unless it has a known vulnerability, we'll typically want to look for the
/manager
and the/host-manager
pagesWe can attempt to locate these with a tool such as
Gobuster
or just browse directly to them.
We may be able to either log in to one of these using weak credentials such as
tomcat:tomcat
,admin:admin
, etcIf these first few tries don't work, we can try a password brute force attack against the login page, covered in the next section.
Attacking Tomcat
if we can access the
/manager
or/host-manager
endpoints, we can likely achieve remote code execution on the Tomcat server
Tomcat Manager - Login Brute Force
This is a very straightforward script that takes a few arguments. We can run the script with
-h
to see what it requires to run.
Tomcat Manager - 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 themanager-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.
browse to
http://web01.inlanefreight.local:8180/manager/html
and enter the credentials.
The manager web app allows us to instantly deploy new applications by uploading WAR files. A WAR file can be created using the zip utility
Click on
Browse
to select the .war file and then click onDeploy
.
This file is uploaded to the manager GUI, after which the
/backup
application will be added to the table.
Browsing to
http://web01.inlanefreight.local:8180/backup/cmd.jsp
will present us with a web shell that we can use to run commands on the Tomcat server
Using Metasploit
We could also use
msfvenom
to generate a malicious WAR file.Browse to the Tomcat console and deploy this file.
Tomcat automatically extracts the WAR file contents and deploys it.
Start a Netcat listener and click on
/backup
to execute the shell.
cmd.jsp
Without it, browsing to an uploaded
cmd.jsp
would render nothing.This is an excellent option to minimize our footprint and possibly evade detections for standard JSP web shells (though the JSP code may need to be modified a bit).
Last updated