Skip to content

Commit ea74d17

Browse files
committed
add a xxe sink code
1 parent 0a9f1ec commit ea74d17

File tree

6 files changed

+72
-26
lines changed

6 files changed

+72
-26
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ This project can also be called Java vulnerability code.
1111

1212
Each vulnerability type code has a security vulnerability by default unless there is no vulnerability. The relevant fix code is in the comments or code. Specifically, you can view each vulnerability code and comments.
1313

14+
[Online demo](http://118.25.15.216:8080)
15+
16+
17+
18+
1419

1520
## Vulnerability Code
1621

@@ -73,11 +78,20 @@ spring.datasource.password=woshishujukumima
7378
### Docker
7479

7580

81+
Start docker:
7682

7783
```
84+
docker-compose pull
7885
docker-compose up
7986
```
8087

88+
89+
Stop docker:
90+
91+
```
92+
docker-compose down
93+
```
94+
8195
Docker's environment:
8296

8397
- Java 1.8.0_102

README_zh.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
每个漏洞类型代码默认存在安全漏洞(除非本身不存在漏洞),相关修复代码在注释里。具体可查看每个漏洞代码和注释。
1212

13+
[在线Demo](http://118.25.15.216:8080)
14+
1315

1416
## 漏洞代码
1517

@@ -70,10 +72,19 @@ spring.datasource.password=woshishujukumima
7072

7173
### Docker
7274

75+
开启应用:
76+
7377
```
78+
docker-compose pull
7479
docker-compose up
7580
```
7681

82+
关闭应用:
83+
84+
```
85+
docker-compose down
86+
```
87+
7788
Docker环境:
7889

7990
- Java 1.8.0_102

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

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

2323
private static String driver = "com.mysql.jdbc.Driver";
24-
private static String url = "jdbc:mysql://localhost:3306/java_sec_code";
24+
private static String url = "jdbc:mysql://127.0.0.1:3306/java_sec_code";
2525
private static String user = "root";
2626
private static String password = "woshishujukumima";
2727

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

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import org.dom4j.io.SAXReader;
5-
import org.springframework.stereotype.*;
65
import org.springframework.web.bind.annotation.*;
76
import javax.servlet.http.HttpServletRequest;
87
import org.w3c.dom.Document;
@@ -28,12 +27,11 @@
2827
* @author JoyChou @2017-12-22
2928
*/
3029

31-
@Controller
30+
@RestController
3231
@RequestMapping("/xxe")
3332
public class XXE {
3433

3534
@RequestMapping(value = "/xmlReader", method = RequestMethod.POST)
36-
@ResponseBody
3735
public String xxe_xmlReader(HttpServletRequest request) {
3836
try {
3937
String xml_con = Tools.getBody(request);
@@ -49,7 +47,6 @@ public String xxe_xmlReader(HttpServletRequest request) {
4947

5048

5149
@RequestMapping(value = "/xmlReader_fix", method = RequestMethod.POST)
52-
@ResponseBody
5350
public String xxe_xmlReader_fix(HttpServletRequest request) {
5451
try {
5552
String xml_con = Tools.getBody(request);
@@ -72,7 +69,6 @@ public String xxe_xmlReader_fix(HttpServletRequest request) {
7269

7370

7471
@RequestMapping(value = "/SAXBuilder", method = RequestMethod.POST)
75-
@ResponseBody
7672
public String xxe_SAXBuilder(HttpServletRequest request) {
7773
try {
7874
String xml_con = Tools.getBody(request);
@@ -88,7 +84,6 @@ public String xxe_SAXBuilder(HttpServletRequest request) {
8884
}
8985

9086
@RequestMapping(value = "/SAXBuilder_fix", method = RequestMethod.POST)
91-
@ResponseBody
9287
public String xxe_SAXBuilder_fix(HttpServletRequest request) {
9388
try {
9489
String xml_con = Tools.getBody(request);
@@ -107,7 +102,6 @@ public String xxe_SAXBuilder_fix(HttpServletRequest request) {
107102
}
108103

109104
@RequestMapping(value = "/SAXReader", method = RequestMethod.POST)
110-
@ResponseBody
111105
public String xxe_SAXReader(HttpServletRequest request) {
112106
try {
113107
String xml_con = Tools.getBody(request);
@@ -124,7 +118,6 @@ public String xxe_SAXReader(HttpServletRequest request) {
124118
}
125119

126120
@RequestMapping(value = "/SAXReader_fix", method = RequestMethod.POST)
127-
@ResponseBody
128121
public String xxe_SAXReader_fix(HttpServletRequest request) {
129122
try {
130123
String xml_con = Tools.getBody(request);
@@ -144,7 +137,6 @@ public String xxe_SAXReader_fix(HttpServletRequest request) {
144137
}
145138

146139
@RequestMapping(value = "/SAXParser", method = RequestMethod.POST)
147-
@ResponseBody
148140
public String xxe_SAXParser(HttpServletRequest request) {
149141
try {
150142
String xml_con = Tools.getBody(request);
@@ -163,7 +155,6 @@ public String xxe_SAXParser(HttpServletRequest request) {
163155

164156

165157
@RequestMapping(value = "/SAXParser_fix", method = RequestMethod.POST)
166-
@ResponseBody
167158
public String xxe_SAXParser_fix(HttpServletRequest request) {
168159
try {
169160
String xml_con = Tools.getBody(request);
@@ -184,7 +175,6 @@ public String xxe_SAXParser_fix(HttpServletRequest request) {
184175

185176

186177
@RequestMapping(value = "/Digester", method = RequestMethod.POST)
187-
@ResponseBody
188178
public String xxe_Digester(HttpServletRequest request) {
189179
try {
190180
String xml_con = Tools.getBody(request);
@@ -201,7 +191,6 @@ public String xxe_Digester(HttpServletRequest request) {
201191
}
202192

203193
@RequestMapping(value = "/Digester_fix", method = RequestMethod.POST)
204-
@ResponseBody
205194
public String xxe_Digester_fix(HttpServletRequest request) {
206195
try {
207196
String xml_con = Tools.getBody(request);
@@ -223,7 +212,6 @@ public String xxe_Digester_fix(HttpServletRequest request) {
223212

224213
// 有回显的XXE
225214
@RequestMapping(value = "/DocumentBuilder_return", method = RequestMethod.POST)
226-
@ResponseBody
227215
public String xxeDocumentBuilderReturn(HttpServletRequest request) {
228216
try {
229217
String xml_con = Tools.getBody(request);
@@ -257,7 +245,6 @@ public String xxeDocumentBuilderReturn(HttpServletRequest request) {
257245

258246

259247
@RequestMapping(value = "/DocumentBuilder", method = RequestMethod.POST)
260-
@ResponseBody
261248
public String DocumentBuilder(HttpServletRequest request) {
262249
try {
263250
String xml_con = Tools.getBody(request);
@@ -294,7 +281,6 @@ public String DocumentBuilder(HttpServletRequest request) {
294281

295282

296283
@RequestMapping(value = "/DocumentBuilder_fix", method = RequestMethod.POST)
297-
@ResponseBody
298284
public String xxe_DocumentBuilder_fix(HttpServletRequest request) {
299285
try {
300286
String xml_con = Tools.getBody(request);
@@ -319,7 +305,6 @@ public String xxe_DocumentBuilder_fix(HttpServletRequest request) {
319305

320306

321307
@RequestMapping(value = "/DocumentBuilder_xinclude", method = RequestMethod.POST)
322-
@ResponseBody
323308
public String xxe_xinclude_DocumentBuilder(HttpServletRequest request) {
324309
try {
325310
String xml_con = Tools.getBody(request);
@@ -356,7 +341,6 @@ public String xxe_xinclude_DocumentBuilder(HttpServletRequest request) {
356341

357342

358343
@RequestMapping(value = "/DocumentBuilder_xinclude_fix", method = RequestMethod.POST)
359-
@ResponseBody
360344
public String xxe_xinclude_DocumentBuilder_fix(HttpServletRequest request) {
361345
try {
362346
String xml_con = Tools.getBody(request);
@@ -395,4 +379,40 @@ public String xxe_xinclude_DocumentBuilder_fix(HttpServletRequest request) {
395379
}
396380

397381

382+
@PostMapping("/XMLReader/vul")
383+
public String XMLReaderVul(HttpServletRequest request) {
384+
try {
385+
String xml_con = Tools.getBody(request);
386+
System.out.println(xml_con);
387+
SAXParserFactory spf = SAXParserFactory.newInstance();
388+
SAXParser saxParser = spf.newSAXParser();
389+
XMLReader xmlReader = saxParser.getXMLReader();
390+
xmlReader.parse( new InputSource(new StringReader(xml_con)) );
391+
return "test";
392+
} catch (Exception e) {
393+
System.out.println(e.toString());
394+
return "except";
395+
}
396+
}
397+
398+
399+
@PostMapping("/XMLReader/fixed")
400+
public String XMLReaderSec(HttpServletRequest request) {
401+
try {
402+
String xml_con = Tools.getBody(request);
403+
System.out.println(xml_con);
404+
SAXParserFactory spf = SAXParserFactory.newInstance();
405+
SAXParser saxParser = spf.newSAXParser();
406+
XMLReader xmlReader = saxParser.getXMLReader();
407+
xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
408+
xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
409+
xmlReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
410+
xmlReader.parse( new InputSource(new StringReader(xml_con)) );
411+
return "test";
412+
} catch (Exception e) {
413+
System.out.println(e.toString());
414+
return "except";
415+
}
416+
}
417+
398418
}

src/main/java/org/joychou/controller/jsonp/JSONP.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
import com.alibaba.fastjson.JSON;
44
import com.alibaba.fastjson.JSONObject;
5+
56
import org.joychou.security.SecurityUtil;
67
import org.springframework.http.MediaType;
78
import org.springframework.security.web.csrf.CsrfToken;
9+
import org.springframework.stereotype.Controller;
810
import org.springframework.web.bind.annotation.*;
11+
912
import javax.servlet.http.HttpServletRequest;
1013
import java.security.Principal;
1114
import java.util.HashMap;
@@ -35,11 +38,11 @@ public static String getUserInfo(HttpServletRequest request) {
3538

3639
return JSON.toJSONString(m);
3740
}
41+
3842
/**
3943
* Set the response content-type to application/javascript.
40-
*
44+
* <p>
4145
* http://localhost:8080/jsonp/referer?callback=test
42-
*
4346
*/
4447
@RequestMapping(value = "/referer", produces = "application/javascript")
4548
private String referer(HttpServletRequest request) {
@@ -50,9 +53,8 @@ private String referer(HttpServletRequest request) {
5053
/**
5154
* Direct access does not check Referer, non-direct access check referer.
5255
* Developer like to do jsonp testing like this.
53-
*
56+
* <p>
5457
* http://localhost:8080/jsonp/emptyReferer?callback=test
55-
*
5658
*/
5759
@RequestMapping(value = "/emptyReferer", produces = "application/javascript")
5860
private String emptyReferer(HttpServletRequest request) {
@@ -72,7 +74,7 @@ private String emptyReferer(HttpServletRequest request) {
7274
* http://localhost:8080/jsonp/advice?_callback=test
7375
*
7476
* @return Only return object, AbstractJsonpResponseBodyAdvice can be used successfully.
75-
* Such as JSONOjbect or JavaBean. String type cannot be used.
77+
* Such as JSONOjbect or JavaBean. String type cannot be used.
7678
*/
7779
@RequestMapping(value = "/advice", produces = MediaType.APPLICATION_JSON_VALUE)
7880
public JSONObject advice(HttpServletRequest request) {
@@ -99,13 +101,12 @@ private String safecode(HttpServletRequest request) {
99101

100102
/**
101103
* http://localhost:8080/jsonp/getToken
102-
* @return token {"token":"115329a7-3a85-4c31-9c02-02fa1bd1fdf8","parameterName":"_csrf","headerName":"X-XSRF-TOKEN"}
103104
*
105+
* @return token {"token":"115329a7-3a85-4c31-9c02-02fa1bd1fdf8","parameterName":"_csrf","headerName":"X-XSRF-TOKEN"}
104106
*/
105107
@RequestMapping("/getToken")
106108
public CsrfToken csrf(CsrfToken token) {
107109
return token;
108110
}
109111

110-
111112
}

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/java_sec_code?useUnicode=true&characterEncoding=utf8&AllowPublicKeyRetrieval=True&useSSL=false&serverTimezone=GMT%2B8
2+
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/java_sec_code?useUnicode=true&characterEncoding=utf8&AllowPublicKeyRetrieval=true&useSSL=false&serverTimezone=GMT%2B8
33
spring.datasource.username=root
44
spring.datasource.password=woshishujukumima
55
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

0 commit comments

Comments
 (0)