@@ -227,6 +227,29 @@ def __setMultipleTargets():
227227 infoMsg += "testable requests from the targets list"
228228 logger .info (infoMsg )
229229
230+ def __setRequestFromFile ():
231+ """
232+ This function checks if the way to make a HTTP request is through supplied
233+ textual file, parses it and saves the information into the knowledge base.
234+ """
235+
236+ if not conf .requestFile :
237+ return
238+
239+ addedTargetUrls = set ()
240+
241+ conf .requestFile = os .path .expanduser (conf .requestFile )
242+
243+ infoMsg = "parsing HTTP request from '%s'" % conf .requestFile
244+ logger .info (infoMsg )
245+
246+ if not os .path .isfile (conf .requestFile ):
247+ errMsg = "the specified HTTP request file "
248+ errMsg += "does not exist"
249+ raise sqlmapFilePathException , errMsg
250+
251+ __feedTargetsDict (conf .requestFile , addedTargetUrls )
252+
230253def __setGoogleDorking ():
231254 """
232255 This function checks if the way to request testable hosts is through
@@ -274,109 +297,6 @@ def __setGoogleDorking():
274297 errMsg += "have GET parameters to test for SQL injection"
275298 raise sqlmapGenericException , errMsg
276299
277- def __setRequestFromFile ():
278- """
279- This function checks if the way to make a HTTP request is through supplied
280- textual file, parses it and saves the information into the knowledge base.
281- """
282-
283- if not conf .requestFile :
284- return
285-
286- conf .requestFile = os .path .expanduser (conf .requestFile )
287-
288- infoMsg = "parsing HTTP request from '%s'" % conf .requestFile
289- logger .info (infoMsg )
290-
291- if not os .path .isfile (conf .requestFile ):
292- errMsg = "the specified HTTP request file "
293- errMsg += "'%s' does not exist" % conf .requestFile
294- raise sqlmapFilePathException , errMsg
295-
296- fp = open (conf .requestFile , "r" )
297- fread = fp .read ()
298- fread = fread .replace ("\r " , "" )
299- fp .close ()
300-
301- lines = fread .split ("\n " )
302-
303- if len (lines ) == 0 :
304- errMsg = "the specified HTTP request file "
305- errMsg += "'%s' has no content" % conf .requestFile
306- raise sqlmapFilePathException , errMsg
307-
308- if not (lines [0 ].upper ().startswith ("GET " ) or lines [0 ].upper ().startswith ("POST " )):
309- errMsg = "the specified HTTP request file "
310- errMsg += "doesn't start with GET or POST keyword"
311- raise sqlmapFilePathException , errMsg
312-
313-
314- if lines [0 ].upper ().startswith ("GET " ):
315- index = 4
316- else :
317- index = 5
318-
319- if lines [0 ].upper ().find (" HTTP/" ) == - 1 :
320- errMsg = "the specified HTTP request file "
321- errMsg += "has a syntax error at line: 1"
322- raise sqlmapFilePathException , errMsg
323-
324- host = None
325- headers = ""
326- page = lines [0 ][index :lines [0 ].index (" HTTP/" )]
327-
328- if conf .method :
329- warnMsg = "HTTP method previously set. overriding it with "
330- warnMsg += "the value supplied from the HTTP request file"
331- logger .warn (warnMsg )
332- conf .method = lines [0 ][:index - 1 ]
333-
334- for index in xrange (1 , len (lines ) - 1 ):
335- line = lines [index ]
336- valid = True
337-
338- if len (line ) == 0 :
339- break
340-
341- headers += line + "\n "
342-
343- items = line .split (': ' )
344- if len (items ) != 2 :
345- valid = False
346- else :
347- if items [0 ].upper () == "HOST" :
348- host = items [1 ]
349-
350- if not valid :
351- errMsg = "the specified HTTP request file"
352- errMsg += "has a syntax error at line: %d" % (index + 1 )
353- raise sqlmapFilePathException , errMsg
354-
355- if conf .headers and headers :
356- warnMsg = "HTTP headers previously set. overriding it with "
357- warnMsg += "the value(s) supplied from the HTTP request file"
358- logger .warn (warnMsg )
359- conf .headers = headers .strip ("\n " )
360-
361- if fread .find ("\n \n " ) != - 1 :
362- if conf .data :
363- warnMsg = "HTTP POST data previously set. overriding it with "
364- warnMsg += "the value supplied from the HTTP request file"
365- logger .warn (warnMsg )
366- conf .data = fread [fread .index ('\n \n ' )+ 2 :].strip ("\n " )
367-
368- if conf .url :
369- warnMsg = "target url previously set. overriding it with "
370- warnMsg += "the value supplied from the HTTP request file"
371- logger .warn (warnMsg )
372-
373- if host :
374- conf .url = "%s%s" % (host , page )
375- else :
376- errMsg = "mandatory HTTP header HOST is missing in "
377- errMsg += "the HTTP request file"
378- raise sqlmapFilePathException , errMsg
379-
380300def __setMetasploit ():
381301 if not conf .osPwn and not conf .osSmb and not conf .osBof :
382302 return
0 commit comments