Skip to content

Commit dbe5d64

Browse files
committed
添加反序列化漏洞接口
1 parent ce08363 commit dbe5d64

File tree

9 files changed

+146
-6
lines changed

9 files changed

+146
-6
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Java Security Code
1+
# Java Security Code
22

33

44
- [XMLInject](https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/controller/XMLInjection.java)
@@ -8,10 +8,13 @@
88
- [XSS](https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/controller/XSS.java)
99
- [CRLFInjection](https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/controller/CRLFInjection.java)
1010
- [RCE](https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/controller/Rce.java)
11+
- [Deserialize](https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/controller/deserialize.java)
1112

12-
### Usage
13+
## Usage
1314

1415

16+
### Tomcat
17+
1518
1. 生成war包 `mvn clean package`
1619
2. 将target目录的war包,cp到Tomcat的webapps目录
1720
3. 重启Tomcat应用
@@ -25,4 +28,11 @@ http://localhost:8080/java-sec-code-1.0.0/rce/exec?cmd=whoami
2528

2629
```
2730
Viarus
28-
```
31+
```
32+
33+
### IDEA
34+
35+
如果想在IDEA中直接运运行,需要进行两个操作:
36+
37+
1. 覆盖适配IDEA的pom.xml `mv pom.xml.idea pom.xml`
38+
2. 覆盖适配IDEA的Application.java文件 `mv Application.java.idea Application.java`

java-sec-code.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.6.RELEASE" level="project" />
7474
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.tomcat:tomcat-servlet-api:8.0.36" level="project" />
7575
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
76+
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.1" level="project" />
7677
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
7778
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
7879
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.6" level="project" />
@@ -87,6 +88,5 @@
8788
<orderEntry type="library" name="Maven: cglib:cglib:2.2.2" level="project" />
8889
<orderEntry type="library" name="Maven: asm:asm:3.3.1" level="project" />
8990
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.3" level="project" />
90-
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
9191
</component>
9292
</module>

poc

1.81 KB
Binary file not shown.

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
<version>21.0</version>
4343
</dependency>
4444

45+
<dependency>
46+
<groupId>commons-collections</groupId>
47+
<artifactId>commons-collections</artifactId>
48+
<version>3.1</version>
49+
</dependency>
50+
4551
<dependency>
4652
<groupId>commons-lang</groupId>
4753
<artifactId>commons-lang</artifactId>

pom.xml.idea

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>sec</groupId>
8+
<artifactId>java-sec-code</artifactId>
9+
<version>1.0.0</version>
10+
11+
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.5.1.RELEASE</version>
17+
</parent>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-web</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>com.google.guava</groupId>
27+
<artifactId>guava</artifactId>
28+
<version>21.0</version>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>commons-lang</groupId>
33+
<artifactId>commons-lang</artifactId>
34+
<version>2.4</version> </dependency>
35+
36+
<dependency>
37+
<groupId>org.apache.httpcomponents</groupId>
38+
<artifactId>httpclient</artifactId>
39+
<version>4.3.6</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.httpcomponents</groupId>
43+
<artifactId>fluent-hc</artifactId>
44+
<version>4.3.6</version>
45+
</dependency>
46+
47+
48+
<dependency>
49+
<groupId>org.apache.logging.log4j</groupId>
50+
<artifactId>log4j-core</artifactId>
51+
<version>2.8.2</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.squareup.okhttp</groupId>
56+
<artifactId>okhttp</artifactId>
57+
<version>2.5.0</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>commons-collections</groupId>
62+
<artifactId>commons-collections</artifactId>
63+
<version>3.1</version>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>org.apache.commons</groupId>
68+
<artifactId>commons-digester3</artifactId>
69+
<version>3.2</version>
70+
</dependency>
71+
72+
</dependencies>
73+
74+
75+
76+
77+
</project>

src/main/java/org/joychou/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ public static void main(String[] args) throws Exception {
1818
SpringApplication.run(Application.class, args);
1919
}
2020

21-
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.joychou;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) throws Exception {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.joychou.controller;
2+
3+
4+
import org.springframework.stereotype.Controller;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.ResponseBody;
7+
8+
import javax.servlet.http.HttpServletRequest;
9+
import java.io.FileInputStream;
10+
import java.io.ObjectInputStream;
11+
12+
/**
13+
* @author: JoyChou
14+
* @Date: 2018年06月14日
15+
* @Desc:将根目录的poc放到/tmp/poc就能在mac上弹计算器。该应用必须有Commons-Collections包才能利用反序列化。
16+
*/
17+
18+
@Controller
19+
@RequestMapping("/deserialize")
20+
public class Deserialize {
21+
22+
@RequestMapping("/test")
23+
@ResponseBody
24+
public static String deserialize_test(HttpServletRequest request) throws Exception{
25+
try {
26+
ObjectInputStream in = new ObjectInputStream(new FileInputStream("/tmp/poc"));
27+
in.readObject(); // 触发漏洞
28+
in.close();
29+
return "test";
30+
}catch (Exception e){
31+
return "exception";
32+
}
33+
34+
}
35+
}

src/main/java/org/joychou/controller/Rce.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Rce {
2222

2323
@RequestMapping("/exec")
2424
@ResponseBody
25-
public String CommandExec(HttpServletRequest request){
25+
public String CommandExec(HttpServletRequest request) {
2626
String cmd = request.getParameter("cmd").toString();
2727
Runtime run = Runtime.getRuntime();
2828
String lineStr = "";

0 commit comments

Comments
 (0)