Tomcat
101
Apache Tomcat is an open-source Java servlet container that hosts Java-based web applications. It is primarily used internally within organizations rather than as a public-facing web server.
A typical folder structure of a Tomcat installation:
βββ bin # stores scripts and bins needed to start and run Tomcat
βββ conf # config files
β βββ catalina.policy
β βββ catalina.properties
β βββ context.xml
β βββ tomcat-users.xml # user creds and roles, IMPORTANT FILE!!!
β βββ tomcat-users.xsd
β βββ web.xml
βββ lib # JAR files needed for proper functioning
βββ logs # temp log files
βββ temp # temp log files
βββ webapps # default webroot, hosts all apps
β βββ manager
β β βββ images
β β βββ META-INF
β β βββ WEB-INF
| | βββ web.xml
β βββ ROOT
β βββ WEB-INF
βββ work # acts as a cache during runtime
βββ Catalina
βββ localhost The tomcat-users.xml file is used to control access to the /manager and /host-manager admin pages:
A typical webapps file structure:
The web.xml file stores info about the routes used by the app and their classes:
The above configuration defines a new servlet (AdminServlet) that is mapped to the com.inlanefreight.api.AdminServlet class. Java uses the dot notation to create package names, meaning the path on disk for this class would be:
Next, a new servlet mapping is created to map requests to /admin with AdminServlet. This configuration will send any request received for /admin to the AdminServlet.class class.
Footprinting
Tomcat servers can often be identified by the Server header in HTTP responses. If a reverse proxy is in place, accessing an invalid URL may still reveal Tomcatβs version:

Another method to detect Tomcat and its version is by visiting the default /docs page, which is usually left accessible unless explicitly removed by administrators:
Attacks
BFA
A Brute Force attack can be performed using MSF's tomcat_mgr_login module:
RCE
A Web Application Archive (WAR) file is a convenient format used to deploy Java web applications on Tomcat quickly and to store backups of those applications. Tomcatβs GUI for managing deployments is located at /manager/html by default and is accessible only to users assigned the manager-gui role. Through this interface, an attacker with access can upload a malicious WAR file to compromise the server.

A JSP webshell can be packaged into a WAR file by simply zipping the webshell JSP file. Once uploaded via the manager interface, the WAR file is automatically extracted and deployed by Tomcat.
A more stealthy version of the JSP web shell can also be used in order to minimize footprint (<1KB) and possibly evade detections for standard JSP web shells. The default web shell gets detected by 2/58 AVs and a simple change drops that number down to 0.
msfvenom can be used to generate a malicious WAR file:
The tomcat_mgr_upload MSF module can be used to automate the process:
Accessing the uploaded shell through its URL (e.g., /backup/cmd.jsp) allows remote command execution on the server.
Note that simply browsing to /backup redirects to /backup/ and typically returns a 404 error, so the full path to the JSP shell must be specified.

Cleanup: return to the Tomcat Manager page and Undeploy the application; this removes the uploaded WAR file and its extracted contents, restoring the serverβs state.
Last updated
Was this helpful?