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

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:

Attacks

BFA

A Brute Force attack can be performed using MSF's tomcat_mgr_loginarrow-up-right 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 webshellarrow-up-right 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 versionarrow-up-right 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.

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.

circle-exclamation

Last updated

Was this helpful?