1+ #This script adds some junk data to the selected request and sends it to a new requester tab
2+ #Script created to work as https://github.com/assetnote/nowafpls
3+ #Written by @5ubterranean_
4+ #If you want to put a Custom Size select "Custom" as the size
5+
6+ import java .awt .event ;
7+
8+ import json
9+ import re
10+ from org .parosproxy .paros .view import AbstractFrame
11+ from javax .swing import JLabel
12+ from javax .swing import JMenuBar
13+ from javax .swing import JMenu
14+ from javax .swing import JMenuItem
15+ from javax .swing import JFrame
16+ from javax .swing import JTextField
17+ from javax .swing import JButton
18+ from javax .swing import JComboBox
19+ requester = control .getExtensionLoader ().getExtension ("ExtensionRequester" )
20+
21+ #Checks generated with IA will check the Content-type header first
22+ def is_json (Ctype , text ):
23+ if "application/json" in Ctype :
24+ return True
25+ try :
26+ json .loads (text )
27+ return True
28+ except :
29+ return False
30+
31+ def is_xml (Ctype , xml_string ):
32+ if "application/xml" in Ctype :
33+ return True
34+
35+ if xml_string [0 ] != "<" or xml_string [- 1 ] != ">" :
36+ return False
37+
38+ # Remove leading and trailing whitespace
39+ xml_string = xml_string .strip ()
40+
41+ # Check if the string starts with XML declaration (optional)
42+ xml_declaration_pattern = r'^\s*<\?xml\s+version="1\.0"\s*\?>'
43+ if re .match (xml_declaration_pattern , xml_string ):
44+ # Remove the XML declaration from the string
45+ xml_string = re .sub (xml_declaration_pattern , '' , xml_string )
46+
47+ # Check for well-formedness
48+ # A simplistic approach to check if tags are properly nested and closed
49+ tag_pattern = r'</?([a-zA-Z_][\w.-]*)\s*[^>]*>'
50+ tags = re .findall (tag_pattern , xml_string )
51+
52+ stack = []
53+ print (tags )
54+ #Checks if tag appears twice (open and close), will fail with autoclosing tags
55+ for tag in tags :
56+ if tag not in stack :
57+ stack .append (tag )
58+ else :
59+ stack .remove (tag )
60+
61+ # Check if stack is empty at the end
62+ print (stack )
63+ return len (stack ) == 0
64+
65+ def is_http_post_form (Ctype , text ):
66+ if "application/x-www-form-urlencoded" in Ctype :
67+ return True
68+ # Simple check for key=value pairs. This is a basic check and may not cover all cases.
69+ return bool (re .match (r'^(?:[^\s=&]+=[^\s=&]+)(?:&[^\s=&]+=[^\s=&]+)*$' , text ))
70+
71+ def is_multipart_data (Ctype , text ):
72+
73+ if "multipart/form-data" in Ctype :
74+ return True
75+ # Check if the text has the typical structure of multipart/form-data
76+ boundary_pattern = r'--([a-zA-Z0-9]+)'
77+ parts = text .split ('\n ' )
78+
79+ if len (parts ) < 2 :
80+ return False
81+
82+ for part in parts :
83+ if re .search (boundary_pattern , part ):
84+ return True
85+ return False
86+
87+ def check_format (Ctype , text ):
88+ if is_json (Ctype , text ):
89+ return "JSON"
90+ elif is_xml (Ctype , text ):
91+ return "XML"
92+ elif is_http_post_form (Ctype , text ):
93+ return "POST FORM"
94+ elif is_multipart_data (Ctype , text ):
95+ return "MULTIPART DATA"
96+
97+ def padXML (HTTPBody , padding ):
98+ padBody = "<!--" + "a" * (padding - 7 ) + "-->" + HTTPBody
99+ return padBody
100+
101+ def padJSON (HTTPBody , padding ):
102+ padBody = '{"junk":"' + "0" * (padding - 10 ) + '"' + ',' + HTTPBody [1 :len (HTTPBody )]
103+ return padBody
104+
105+ def padFORM (HTTPBody , padding ):
106+ padBody = "a=" + "0" * (padding - 2 ) + "&" + HTTPBody
107+ return padBody
108+
109+ def padMultipart (cType , HTTPBody , padding ):
110+ typeSplit = cType .split (";" )
111+ i = 0
112+ while i < len (typeSplit ):
113+ if "boundary" in typeSplit [i ]:
114+ boundary = typeSplit [i ]
115+ break
116+ else :
117+ i = i + 1
118+ padBody = "--" + boundary [10 :len (boundary )] + "\n " + 'Content-Disposition: form-data; name="junk_data"' + "\n \n " + "0" * (padding - (len (boundary [10 :len (boundary )]) + 48 )) + "\n \n " + HTTPBody
119+ return padBody
120+
121+ def invokeWith (msg ):
122+ #Clonning request first to avoid making changes to the original request
123+ cloned = msg .cloneRequest ()
124+ #Defines values for pop up box
125+ frame = JFrame ("Junk size" )
126+ frame .setLocation (100 ,100 )
127+ frame .setSize (460 ,180 )
128+ frame .setLayout (None )
129+ lbl1 = JLabel ("Type: " )
130+ lbl1 .setBounds (60 ,20 ,60 ,20 )
131+ typelist = ["JSON" ,"XML" , "POST FORM" ,"MULTIPART DATA" ]
132+ txt1 = JComboBox (typelist )
133+ txt1 .setBounds (130 ,20 ,200 ,20 )
134+ lbl2 = JLabel ("Size: " )
135+ lbl2 .setBounds (60 ,50 ,60 ,20 )
136+ choices = ["8 KB" ,"16 KB" , "32 KB" ,"64 KB" ,"128 KB" ,"1024 KB" ,"CUSTOM" ]
137+ txt2 = JComboBox (choices )
138+ txt2 .setBounds (130 ,50 ,200 ,20 )
139+ lbl3 = JLabel ("Custom: " )
140+ lbl3 .setBounds (60 ,80 ,100 ,20 )
141+ txt3 = JTextField (100 )
142+ txt3 .setBounds (130 ,80 ,200 ,20 )
143+
144+ def getValues (event ):
145+ #Reading Size for the junk data
146+ if str (txt2 .getSelectedItem ()) == "8 KB" :
147+ padSize = 8000
148+ elif str (txt2 .getSelectedItem ()) == "16 KB" :
149+ padSize = 16000
150+ elif str (txt2 .getSelectedItem ()) == "32 KB" :
151+ padSize = 32000
152+ elif str (txt2 .getSelectedItem ()) == "64 KB" :
153+ padSize = 64000
154+ elif str (txt2 .getSelectedItem ()) == "128 KB" :
155+ padSize = 128000
156+ elif str (txt2 .getSelectedItem ()) == "1024 KB" :
157+ padSize = 1024000
158+ elif str (txt2 .getSelectedItem ()) == "CUSTOM" :
159+ padSize = int (txt3 .getText ())
160+
161+ #Select content type according to what is selected on the combo box, done in case user changed the type due the autodetect failing
162+ contentFormat = txt1 .getSelectedItem ()
163+
164+ #Create new body with the junk data added
165+ if contentFormat == "JSON" :
166+ newBody = padJSON (cloned .getRequestBody ().toString (), padSize )
167+ elif contentFormat == "XML" :
168+ newBody = padXML (cloned .getRequestBody ().toString (), padSize )
169+ elif contentFormat == "POST FORM" :
170+ newBody = padFORM (cloned .getRequestBody ().toString (), padSize )
171+ elif contentFormat == "MULTIPART DATA" :
172+ Ctype = cloned .getRequestHeader ().getHeader ("Content-Type" )
173+ newBody = padMultipart (Ctype , cloned .getRequestBody ().toString (), padSize )
174+ cloned .setRequestBody (newBody )
175+ cloned .getRequestHeader ().setContentLength (cloned .getRequestBody ().length ())
176+ #Sends request to a new requester tab
177+ requester .newRequesterPane (cloned )
178+ #Closes pop up box
179+ frame .dispose ()
180+
181+ btn = JButton ("Submit" , actionPerformed = getValues )
182+ btn .setBounds (160 ,110 ,100 ,20 )
183+ frame .add (lbl1 )
184+ frame .add (txt1 )
185+ frame .add (lbl2 )
186+ frame .add (txt2 )
187+ frame .add (lbl3 )
188+ frame .add (txt3 )
189+ frame .add (btn )
190+ frame .setVisible (True )
191+ Ctype = cloned .getRequestHeader ().getHeader ("Content-Type" )
192+ contentFormat = check_format (Ctype , cloned .getRequestBody ().toString ())
193+ if contentFormat == "JSON" :
194+ txt1 .setSelectedIndex (0 )
195+ elif contentFormat == "XML" :
196+ txt1 .setSelectedIndex (1 )
197+ elif contentFormat == "POST FORM" :
198+ txt1 .setSelectedIndex (2 )
199+ elif contentFormat == "MULTIPART DATA" :
200+ txt1 .setSelectedIndex (3 )
0 commit comments