22
33
44import org .dom4j .io .SAXReader ;
5- import org .springframework .stereotype .*;
65import org .springframework .web .bind .annotation .*;
76import javax .servlet .http .HttpServletRequest ;
87import org .w3c .dom .Document ;
2827 * @author JoyChou @2017-12-22
2928 */
3029
31- @ Controller
30+ @ RestController
3231@ RequestMapping ("/xxe" )
3332public 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}
0 commit comments