@@ -267,6 +267,121 @@ def __setGoogleDorking():
267267 errMsg += "have GET parameters to test for SQL injection"
268268 raise sqlmapGenericException , errMsg
269269
270+ def __setRequestFromFile ():
271+ """
272+ This function checks if the way to make a HTTP request is through supplied
273+ textual file, parses it and saves the information into the knowledge base.
274+ """
275+
276+ if not conf .requestFile :
277+ return
278+
279+ conf .requestFile = os .path .expanduser (conf .requestFile )
280+
281+ debugMsg = "parsing HTTP request from '%s'" % conf .requestFile
282+ logger .debug (debugMsg )
283+
284+ if not os .path .isfile (conf .requestFile ):
285+ errMsg = "the specified HTTP request file "
286+ errMsg += "'%s' does not exist" % conf .requestFile
287+ raise sqlmapFilePathException , errMsg
288+
289+ fp = open (conf .requestFile , "r" )
290+ fread = fp .read ()
291+ fread = fread .replace ("\r " , "" )
292+ fp .close ()
293+
294+ lines = fread .split ("\n " )
295+
296+ if len (lines ) == 0 :
297+ errMsg = "the specified HTTP request file "
298+ errMsg += "'%s' has no content" % conf .requestFile
299+ raise sqlmapFilePathException , errMsg
300+
301+ if not (lines [0 ].startswith ("GET " ) or lines [0 ].startswith ("POST " )):
302+ errMsg = "the specified HTTP request file "
303+ errMsg += "doesn't start with GET or POST keyword"
304+ raise sqlmapFilePathException , errMsg
305+
306+
307+ if lines [0 ].upper ().startswith ("GET " ):
308+ index = 4
309+ else :
310+ index = 5
311+
312+ if lines [0 ].find (" HTTP/" ) == - 1 :
313+ errMsg = "the specified HTTP request file "
314+ errMsg += "has a syntax error at line: 1"
315+ raise sqlmapFilePathException , errMsg
316+
317+ host = None
318+ headers = ""
319+ page = lines [0 ][index :lines [0 ].index (" HTTP/" )]
320+
321+ if conf .method :
322+ warnMsg = "HTTP method previously set. overriding it with "
323+ warnMsg += "the value supplied from the HTTP request file"
324+ logger .warn (warnMsg )
325+ conf .method = lines [0 ][:index - 1 ]
326+
327+ for index in xrange (1 , len (lines ) - 1 ):
328+ line = lines [index ]
329+ valid = True
330+
331+ if len (line ) == 0 :
332+ break
333+
334+ headers += line + "\n "
335+
336+ items = line .split (': ' )
337+ if len (items ) != 2 :
338+ valid = False
339+ else :
340+ if items [0 ].upper () == "HOST" :
341+ host = items [1 ]
342+
343+ if not valid :
344+ errMsg = "the specified HTTP request file"
345+ errMsg += "has a syntax error at line: %d" % (index + 1 )
346+ raise sqlmapFilePathException , errMsg
347+
348+ if conf .headers and headers :
349+ warnMsg = "HTTP headers previously set. overriding it with "
350+ warnMsg += "the value(s) supplied from the HTTP request file"
351+ logger .warn (warnMsg )
352+ conf .headers = headers .strip ("\n " )
353+
354+ if fread .find ("\n \n " ) != - 1 :
355+ if conf .data :
356+ warnMsg = "HTTP POST data previously set. overriding it with "
357+ warnMsg += "the value supplied from the HTTP request file"
358+ logger .warn (warnMsg )
359+ conf .data = fread [fread .index ('\n \n ' )+ 2 :].strip ("\n " )
360+
361+ if conf .url :
362+ warnMsg = "target url previously set. overriding it with "
363+ warnMsg += "the value supplied from the HTTP request file"
364+ logger .warn (warnMsg )
365+
366+ if host :
367+ conf .url = "%s%s" % (host , page )
368+ elif conf .url : #insert page into here
369+ index = conf .url .find ("://" )
370+ if index != - 1 :
371+ index += len ("://" )
372+ else :
373+ index = 0
374+
375+ index = conf .url .find ("/" , index )
376+ if index != - 1 :
377+ conf .url = "%s%s" % (conf .url [:conf .url .find ("/" , index )], page )
378+ else :
379+ conf .url = "%s%s" % (conf .url , page )
380+ pass #mirek
381+ else :
382+ errMsg = "target url is not known"
383+ raise sqlmapFilePathException , errMsg
384+
270385def __setMetasploit ():
271386 if not conf .osPwn and not conf .osSmb and not conf .osBof :
272387 return
@@ -1004,6 +1119,8 @@ def init(inputOptions=advancedDict()):
10041119 __setKnowledgeBaseAttributes ()
10051120 __cleanupOptions ()
10061121
1122+ __setRequestFromFile ()
1123+
10071124 parseTargetUrl ()
10081125
10091126 __setHTTPTimeout ()
0 commit comments