
A fully refactored, Python 3 compatible exploit script for Tomcat Ghostcat (CVE-2020-1938 / CNVD-2020-10487) AJP Local File Inclusion
This project provides a Python verification script for verifying the Apache Tomcat AJP protocol local file inclusion vulnerability (commonly known as Ghostcat, CVE-2020-1938 / CNVD-2020-10487).
This script is a complete refactoring and fix based on the originally circulated Python 2 version. It is fully compatible with Python 3 environments, fixing compatibility issues with StringIO, base64 encoding, and concatenation of binary data and strings, enhancing stability on modern operating systems.
When Apache Tomcat processes the AJP (Apache JServ Protocol) protocol, port 8009 is enabled by default, and strict security checks are not performed on incoming request attributes.
Attackers can inject attributes such as javax.servlet.include.request_uri, javax.servlet.include.path_info, and javax.servlet.include.servlet_path by crafting malicious AJP requests:
DefaultServlet into reading any file within the web application directory (e.g., WEB-INF/web.xml, configuration files, etc.).JspServlet to parse and compile that file as a JSP, thereby achieving remote command execution.Note: This vulnerability only supports local file inclusion (LFI), not direct remote file inclusion (RFI).
Command line syntax:
python CNVD-2020-10487-Tomcat-Ajp-lfi.py <target IP> [-p target port] [-f target file path]
target (required): IP address or domain name of the target host.-p, --port (optional): AJP port, default is 8009.-f, --file (optional): Relative path of the target file to read, default is WEB-INF/web.xml.Basic Check (read default web.xml):
python CNVD-2020-10487-Tomcat-Ajp-lfi.py 127.0.0.1
Specify port and file (read custom configuration file):
python CNVD-2020-10487-Tomcat-Ajp-lfi.py 192.168.1.100 -p 8009 -f WEB-INF/classes/application.properties
If your system is affected by this vulnerability, it is recommended to take the following protective measures immediately:
<Connector port="8009" protocol="AJP/1.3" ... /> configuration directly in conf/server.xml.requiredSecret property (in Tomcat 8.5.51/9.0.31 and later versions, it's secret) to the AJP Connector to enforce authentication.This script is only for cybersecurity research, education, and internal enterprise compliance security audits. Do not use this script for unauthorized probing or attacks against targets. Users must comply with local laws and regulations when using this script. Any consequences resulting from improper or illegal use shall be borne by the user.