1010import javax .swing .JMenu ;
1111import javax .swing .JMenuItem ;
1212
13+ import org .apache .commons .lang3 .StringUtils ;
1314import org .json .JSONArray ;
1415import org .json .JSONException ;
1516import org .json .JSONObject ;
2829
2930/**
3031 * 将某个payload插入所有的插入点,比如XSS
31- * @author bit4woo
32+ *
33+ * @author bit4woo
3234 */
3335
3436//reference XXE_Menu.java
3537public class CustomPayloadForAllInsertpointMenu extends JMenu {
3638 /**
37- *
39+ *
3840 */
3941 private static final long serialVersionUID = 1L ;
4042 public BurpExtender burp ;
4143
42- public CustomPayloadForAllInsertpointMenu (BurpExtender burp ){
44+ public CustomPayloadForAllInsertpointMenu (BurpExtender burp ) {
4345 try {
4446 this .setText ("^_^ Insert Payload For All" );
4547 this .burp = burp ;
4648
4749 List <ConfigEntry > configs = GUI .getConfigTableModel ().getConfigByType (ConfigEntry .Config_Custom_Payload );
48- List <ConfigEntry > configs1 = GUI .getConfigTableModel ().getConfigByType (ConfigEntry .Config_Custom_Payload_Base64 );
50+ List <ConfigEntry > configs1 = GUI .getConfigTableModel ()
51+ .getConfigByType (ConfigEntry .Config_Custom_Payload_Base64 );
4952 configs .addAll (configs1 );
50- for (ConfigEntry config : configs ){
53+ for (ConfigEntry config : configs ) {
5154 String name = config .getKey ();
5255 JMenuItem item = new JMenuItem (name );
53- item .addActionListener (new ForAllInserpointListener (burp ,config ));
56+ item .addActionListener (new ForAllInserpointListener (burp , config ));
5457 add (item );
5558 }
5659 } catch (Exception e ) {
@@ -68,7 +71,7 @@ class ForAllInserpointListener implements ActionListener {
6871 public IBurpExtenderCallbacks callbacks ;
6972 public BurpExtender burp ;
7073
71- public ForAllInserpointListener (BurpExtender burp ,ConfigEntry config ) {
74+ public ForAllInserpointListener (BurpExtender burp , ConfigEntry config ) {
7275 this .burp = burp ;
7376 this .invocation = burp .invocation ;
7477 this .helpers = burp .helpers ;
@@ -82,51 +85,55 @@ public ForAllInserpointListener(BurpExtender burp,ConfigEntry config) {
8285 public void actionPerformed (ActionEvent event ) {
8386 IHttpRequestResponse [] selectedItems = invocation .getSelectedMessages ();
8487 IHttpRequestResponse messageInfo = selectedItems [0 ];
85- byte [] newRequest = messageInfo .getRequest ();//为了不影响原始request,通过final进行一次转换
88+ byte [] newRequest = messageInfo .getRequest ();// 为了不影响原始request,通过final进行一次转换
8689
8790 HelperPlus getter = new HelperPlus (helpers );
8891 List <IParameter > paras = getter .getParameters (messageInfo );
8992
9093 String charset = CharsetUtils .detectCharset (newRequest );
91- String xsspayload = config .getFinalValue (messageInfo );
92- if (xsspayload == null ) return ;
94+ if (StringUtils .isEmpty (charset )) {
95+ charset = "UTF-8" ;
96+ }
97+ String xsspayload = config .getFinalValue (messageInfo );
98+ if (xsspayload == null )
99+ return ;
93100
94101 boolean jsonHandled = false ;
95- for (IParameter para : paras ) {
102+ for (IParameter para : paras ) {
96103 String value = para .getValue ();
97104 byte type = para .getType ();
98105 if (type == IParameter .PARAM_COOKIE || isInt (value )) {
99106 continue ;
100- }else if (type == IParameter .PARAM_JSON ) {//json参数的更新方法,这里只是针对body是json
101- if (!jsonHandled ){
102- //stdout.println(para.getValue());
107+ } else if (type == IParameter .PARAM_JSON ) {// json参数的更新方法,这里只是针对body是json
108+ if (!jsonHandled ) {
109+ // stdout.println(para.getValue());
103110 List <String > headers = helpers .analyzeRequest (newRequest ).getHeaders ();
104111 try {
105- String body = new String (HelperPlus .getBody (true ,newRequest ),charset );
106- if (isJSON (body )){
107- body = updateJSONValue (body ,xsspayload );
108- newRequest = helpers .buildHttpMessage (headers ,body .getBytes (charset ));
112+ String body = new String (HelperPlus .getBody (true , newRequest ), charset );
113+ if (isJSON (body )) {
114+ body = updateJSONValue (body , xsspayload );
115+ newRequest = helpers .buildHttpMessage (headers , body .getBytes (charset ));
109116 jsonHandled = true ;
110117 }
111118 } catch (Exception e ) {
112119 e .printStackTrace (stderr );
113120 }
114121 }
115- }else {
116- if (type == IParameter .PARAM_URL ) {//url中的参数需要编码
122+ } else {
123+ if (type == IParameter .PARAM_URL ) {// url中的参数需要编码
117124 value = helpers .urlDecode (value );
118125 }
119- if (isJSON (value )){//当参数的值是json格式
126+ if (isJSON (value )) {// 当参数的值是json格式
120127 try {
121- value = updateJSONValue (value ,xsspayload );
128+ value = updateJSONValue (value , xsspayload );
122129 } catch (Exception e ) {
123130 e .printStackTrace (stderr );
124131 }
125- }else {
126- value = value + xsspayload ;
132+ } else {
133+ value = value + xsspayload ;
127134 }
128135
129- if (type == IParameter .PARAM_URL ) {//url中的参数需要编码
136+ if (type == IParameter .PARAM_URL ) {// url中的参数需要编码
130137 value = helpers .urlEncode (value );
131138 }
132139 IParameter newPara = helpers .buildParameter (para .getName (), value , para .getType ());
@@ -144,7 +151,7 @@ public static boolean isInt(String input) {
144151 try {
145152 long l = Long .valueOf (input );
146153 return true ;
147- }catch (Exception e1 ) {
154+ } catch (Exception e1 ) {
148155
149156 }
150157 return false ;
@@ -154,12 +161,12 @@ public static boolean isInt(String input) {
154161 public static boolean isJSON (String test ) {
155162 if (isJSONObject (test ) || isJSONArray (test )) {
156163 return true ;
157- }else {
164+ } else {
158165 return false ;
159166 }
160167 }
161168
162- //org.json
169+ // org.json
163170 public static boolean isJSONObject (String test ) {
164171 try {
165172 new JSONObject (test );
@@ -169,7 +176,6 @@ public static boolean isJSONObject(String test) {
169176 }
170177 }
171178
172-
173179 public static boolean isJSONArray (String test ) {
174180 try {
175181 new JSONArray (test );
@@ -179,57 +185,56 @@ public static boolean isJSONArray(String test) {
179185 }
180186 }
181187
182- //org.json
188+ // org.json
183189 public static String updateJSONValue (String JSONString , String payload ) throws Exception {
184190
185191 if (isJSONObject (JSONString )) {
186192 JSONObject obj = new JSONObject (JSONString );
187193 Iterator <String > iterator = obj .keys ();
188194 while (iterator .hasNext ()) {
189- String key = (String ) iterator .next (); // We need to know keys of Jsonobject
195+ String key = (String ) iterator .next (); // We need to know keys of Jsonobject
190196 String value = obj .get (key ).toString ();
191197
192-
193198 if (isJSONObject (value )) {// if it's jsonobject
194199 String newValue = updateJSONValue (value , payload );
195- obj .put (key ,new JSONObject (newValue ));
196- }else if (isJSONArray (value )) {// if it's jsonarray
200+ obj .put (key , new JSONObject (newValue ));
201+ } else if (isJSONArray (value )) {// if it's jsonarray
197202 String newValue = updateJSONValue (value , payload );
198- obj .put (key ,new JSONArray (newValue ));
199- }else {
200- if (!isBooleanOrNumber (value )){
201- obj .put (key , value + payload );
203+ obj .put (key , new JSONArray (newValue ));
204+ } else {
205+ if (!isBooleanOrNumber (value )) {
206+ obj .put (key , value + payload );
202207 }
203208 }
204209 }
205210 return obj .toString ();
206- }else if (isJSONArray (JSONString )) {
211+ } else if (isJSONArray (JSONString )) {
207212 JSONArray jArray = new JSONArray (JSONString );
208213
209214 ArrayList <String > newjArray = new ArrayList <String >();
210- for (int i = 0 ; i < jArray .length ();i ++) {//无论Array中的元素是JSONObject还是String都转换成String进行处理即可
215+ for (int i = 0 ; i < jArray .length (); i ++) {// 无论Array中的元素是JSONObject还是String都转换成String进行处理即可
211216 String item = jArray .get (i ).toString ();
212- String newitem = updateJSONValue (item ,payload );
217+ String newitem = updateJSONValue (item , payload );
213218 newjArray .add (newitem );
214219 }
215220 return newjArray .toString ();
216- }else {
217- return JSONString + payload ;
221+ } else {
222+ return JSONString + payload ;
218223 }
219224 }
220225
221226 public static boolean isBooleanOrNumber (String input ) {
222- if (input .equalsIgnoreCase ("true" ) || input .equalsIgnoreCase ("false" )){
227+ if (input .equalsIgnoreCase ("true" ) || input .equalsIgnoreCase ("false" )) {
223228 return true ;
224- }else {
229+ } else {
225230 return isNumeric (input );
226231 }
227232 }
228233
229- public static boolean isNumeric (String str ){
230- for (int i = str .length ();--i >= 0 ;){
231- int chr = str .charAt (i );
232- if (chr < 48 || chr > 57 ) {
234+ public static boolean isNumeric (String str ) {
235+ for (int i = str .length (); --i >= 0 ;) {
236+ int chr = str .charAt (i );
237+ if (chr < 48 || chr > 57 ) {
233238 return false ;
234239 }
235240 }
0 commit comments