Analysis of CVE-2020-9484 in Apache Tomcat: patch diff review, lab setup with PersistentManager/FileStore, and JDWP debugging to trace the session path traversal to deserialization RCE.

Быстрый сканер уязвимостей на основе YAML с шаблонным движком обнаружения для автоматизированного тестирования безопасности веб-приложений, API, сетей, DNS и облачной инфраструктуры.

Сканер безопасности веб-приложений с открытым исходным кодом для автоматического обнаружения уязвимостей, ручного тестирования на проникновение и тестирования безопасности API с помощью прокси-движка перехвата.

CVE-2020-9484 is a security vulnerability belonging to the Insecure Deserialization class, present in Apache Tomcat's session persistence mechanism. This vulnerability can allow an attacker to achieve Remote Code Execution (RCE) under certain conditions.
The affected Apache Tomcat versions include:
To successfully exploit the vulnerability, the following conditions must be met simultaneously:
PersistentManager in combination with FileStore.PersistentManager is configured with sessionAttributeValueClassNameFilter="null" or a filter loose enough to allow deserialization of attacker-supplied objects.FileStore session storage directory to the file controlled by the attacker.The root cause of CVE-2020-9484 lies in the fact that FileStore uses the client-controlled Session ID to construct the path to the session file without fully validating the storage directory boundary. When PersistentManager attempts to restore a session that does not exist in memory, an attacker can leverage Path Traversal to cause Tomcat to read and deserialize a malicious file located outside the session-store, thereby leading to RCE if the exploitation conditions are met.
The CVE-2020-9484 patch adds a file path validation mechanism in the file(String id) method of the FileStore class.
private File file(String id) throws IOException {
- if (this.directory == null) {
+ File storageDir = directory();
+ if (storageDir == null) {
return null;
}
String filename = id + FILE_EXT;
- File file = new File(directory(), filename);
+ File file = new File(storageDir, filename);
+
+ // Check the file is within the storage directory
+ if (!file.getCanonicalPath().startsWith(storageDir.getCanonicalPath())) {
+ log.warn(sm.getString("fileStore.invalid", file.getPath(), id));
+ return null;
+ }
return file;
}
Before being patched, FileStore.file(String id) used the Session ID directly to construct the path to the session file without checking whether the resulting path still resided within the storage directory. This allowed an attacker to use Path Traversal to access files outside the session-store.
To fix this, the patch adds a comparison of file.getCanonicalPath() with storageDir.getCanonicalPath(). If the file path does not start with the storage directory path, the method logs a warning and returns null.
Thus, the patch aims to prevent the Session ID from being used to reference files located outside the session storage directory.
To analyze CVE-2020-9484, I built a test environment using Apache Tomcat 9.0.34, a version affected by the vulnerability. The environment was deployed on an Ubuntu Server virtual machine via VirtualBox, while a Windows 11 machine served to send HTTP requests and perform remote debugging with IntelliJ IDEA.
The components used in the test environment include:
| Component | Configuration |
|---|---|
| Host OS | Windows 11 |
| Virtualization | VirtualBox |
| Guest OS | Ubuntu Server |
| Apache Tomcat | 9.0.34 |
| Java | Eclipse Temurin JDK 8u514 |
| Build Tool | Apache Ant 1.10.18 |
| Debugger | IntelliJ IDEA |
| Network | NAT + Host-only |
| Target IP | 192.168.56.103 |
| HTTP Port | 8080 |
| Debug Port | 5005 |
Apache Tomcat 9.0.34 was compiled directly from source code using Apache Ant to support source code analysis and breakpoint setting.
Tomcat is configured with two paths:
CATALINA_HOME=/opt/tomcat-lab/runtime/buildCATALINA_BASE=/opt/tomcat-lab/instance/cve-2020-9484To meet the exploitation conditions for CVE-2020-9484, Tomcat is configured to use PersistentManager in combination with FileStore instead of the default session management mechanism.
The session storage directory is set at:
/opt/tomcat-lab/instance/cve-2020-9484/session-store
In addition, I deployed a simple web application named session-lab, accessible at:
http://192.168.56.103:8080/session-lab/
This application supports two functions:
action=set: Creates or accesses a session and stores a value in a session attribute.action=read: Accesses an existing session and reads the stored session attribute value.The application is used to generate HTTP requests for observing the session handling process inside Tomcat.
Outside Tomcat's session storage directory, I planned to create a separate directory on the Ubuntu Server to hold a file named exploit.session.
For example, the directory structure in the lab is as follows:
/opt/tomcat-lab/
├── runtime/
│ └── build/
├── instance/
│ └── cve-2020-9484/
│ ├── conf/
│ ├── logs/
│ ├── webapps/
│ ├── work/
│ └── session-store/
└── attacker-files/
└── exploit.session
Where:
session-store/: The directory configured in FileStore for storing application sessions.attacker-files/: A separate directory simulating a location where an attacker could potentially control file contents on the system.exploit.session: A file prepared to simulate attacker-controlled data, for researching deserialization behavior.In this scenario, I assume the attacker already has the ability to place a file with a controlled name and content onto the server's filesystem, and that the file can be read by the Tomcat process. The process of uploading or writing the file to the server is outside the scope of the test.
Unlike the session files normally stored by Tomcat, exploit.session is placed outside the session-store directory. The purpose of this arrangement is to test whether a client-supplied Session ID can cause Tomcat to access a file located outside the configured session storage directory.
To monitor the execution process, Tomcat is started with Java Debug Wire Protocol (JDWP), using port 5005 on the Ubuntu Server.
The Windows machine connects to the debugger through an SSH tunnel, forwarding port 127.0.0.1:5005 on Windows to the JDWP port of the virtual machine.
Then, IntelliJ IDEA is configured with Remote JVM Debug to connect to the running Tomcat process.
With this environment, I can send HTTP requests from Windows to the session-lab application, while using breakpoints in IntelliJ IDEA to observe how Tomcat processes the Session ID and interacts with session files on the filesystem.
In particular, the separately placed exploit.session file serves the process of examining and identifying the root cause of CVE-2020-9484 in the Debugging & Root Cause Analysis section.
CoyoteAdapter is the intermediary component between the HTTP protocol handling layer (Coyote) and the Servlet Container layer (Catalina) of Apache Tomcat. This class is responsible for preparing the HTTP request before it is passed into the Servlet Container's processing.
During request processing, the postParseRequest() method is responsible for determining the Session ID supplied by the client through the configured session tracking mechanisms, such as URL, Cookie, or SSL.
After the Session ID is extracted, this value is stored in the requestedSessionId attribute of the Request object. However, this does not mean that the corresponding session already exists or is valid.
When the application requests access to a session, Tomcat uses the doGetSession(boolean create) method in the Request class to look up or create a session.
Этот репозиторий содержит компонент сканера для Greenbone Community Edition.