11package org .joychou .controller ;
22
3+
34import org .springframework .stereotype .*;
45import org .springframework .web .bind .annotation .*;
56import javax .servlet .http .HttpServletRequest ;
89import org .w3c .dom .NodeList ;
910import org .xml .sax .helpers .XMLReaderFactory ;
1011import org .xml .sax .XMLReader ;
11- import java .io .StringReader ;
12+ import java .io .* ;
1213import org .xml .sax .InputSource ;
1314import javax .xml .parsers .DocumentBuilder ;
1415import javax .xml .parsers .DocumentBuilderFactory ;
2728@ RequestMapping ("/xxe" )
2829public class XXE {
2930
30- @ RequestMapping ("/xmlReader" )
31+ @ RequestMapping (value = "/xmlReader" , method = RequestMethod . POST )
3132 @ ResponseBody
32- public static String xxe_xmlReader (HttpServletRequest request ) {
33+ public String xxe_xmlReader (HttpServletRequest request ) {
3334 try {
34- String xml_con = request . getParameter ( "xml" ). toString ( );
35+ String xml_con = getBody ( request );
3536 System .out .println (xml_con );
3637 XMLReader xmlReader = XMLReaderFactory .createXMLReader ();
38+
3739 // fix code start
3840
3941// xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
@@ -50,12 +52,11 @@ public static String xxe_xmlReader(HttpServletRequest request) {
5052 }
5153 }
5254
53-
54- @ RequestMapping ("/SAXParser" )
55+ @ RequestMapping (value = "/SAXParser" , method = RequestMethod .POST )
5556 @ ResponseBody
56- public static String xxe_SAXParser (HttpServletRequest request ) {
57+ public String xxe_SAXParser (HttpServletRequest request ) {
5758 try {
58- String xml_con = request . getParameter ( "xml" ). toString ( );
59+ String xml_con = getBody ( request );
5960 System .out .println (xml_con );
6061 SAXParserFactory spf = SAXParserFactory .newInstance ();
6162
@@ -66,6 +67,7 @@ public static String xxe_SAXParser(HttpServletRequest request) {
6667// spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
6768
6869 // fix code end
70+
6971 SAXParser parser = spf .newSAXParser ();
7072 parser .parse (new InputSource (new StringReader (xml_con )), new DefaultHandler ()); // parse xml
7173 return "test" ;
@@ -75,11 +77,11 @@ public static String xxe_SAXParser(HttpServletRequest request) {
7577 }
7678 }
7779
78- @ RequestMapping ("/Digester" )
80+ @ RequestMapping (value = "/Digester" , method = RequestMethod . POST )
7981 @ ResponseBody
80- public static String xxe_Digester (HttpServletRequest request ) {
82+ public String xxe_Digester (HttpServletRequest request ) {
8183 try {
82- String xml_con = request . getParameter ( "xml" ). toString ( );
84+ String xml_con = getBody ( request );
8385 System .out .println (xml_con );
8486 Digester digester = new Digester ();
8587
@@ -100,11 +102,11 @@ public static String xxe_Digester(HttpServletRequest request) {
100102 }
101103
102104
103- @ RequestMapping ("/DocumentBuilder" )
105+ @ RequestMapping (value = "/DocumentBuilder" , method = RequestMethod . POST )
104106 @ ResponseBody
105- public static String xxe_DocumentBuilder (HttpServletRequest request ) {
107+ public String xxe_DocumentBuilder (HttpServletRequest request ) {
106108 try {
107- String xml_con = request . getParameter ( "xml" ). toString ( );
109+ String xml_con = getBody ( request );
108110 System .out .println (xml_con );
109111 DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance ();
110112
@@ -129,11 +131,11 @@ public static String xxe_DocumentBuilder(HttpServletRequest request) {
129131 }
130132
131133
132- @ RequestMapping ("/DocumentBuilder_xinclude" )
134+ @ RequestMapping (value = "/DocumentBuilder_xinclude" , method = RequestMethod . POST )
133135 @ ResponseBody
134- public static String xxe_xinclude_DocumentBuilder (HttpServletRequest request ) {
136+ public String xxe_xinclude_DocumentBuilder (HttpServletRequest request ) {
135137 try {
136- String xml_con = request . getParameter ( "xml" ). toString ( );
138+ String xml_con = getBody ( request );
137139 System .out .println (xml_con );
138140 DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance ();
139141
@@ -173,6 +175,22 @@ public static String xxe_xinclude_DocumentBuilder(HttpServletRequest request) {
173175 }
174176 }
175177
176-
178+ // 获取body数据
179+ private String getBody (HttpServletRequest request ) throws IOException {
180+ InputStream in = request .getInputStream ();
181+ BufferedReader br = new BufferedReader (new InputStreamReader (in ));
182+ StringBuffer sb = new StringBuffer ("" );
183+ String temp ;
184+ while ((temp = br .readLine ()) != null ) {
185+ sb .append (temp );
186+ }
187+ if (in != null ) {
188+ in .close ();
189+ }
190+ if (br != null ) {
191+ br .close ();
192+ }
193+ return sb .toString ();
194+ }
177195
178196}
0 commit comments