@@ -141,9 +141,9 @@ def formatDBMSfp(versions=None):
141141
142142
143143def formatFingerprintString (values , chain = " or " ):
144- string = "|" .join ([v for v in values ])
144+ strJoin = "|" .join ([v for v in values ])
145145
146- return string .replace ("|" , chain )
146+ return strJoin .replace ("|" , chain )
147147
148148
149149def formatFingerprint (target , info ):
@@ -224,73 +224,91 @@ def getHtmlErrorFp():
224224
225225
226226def getDocRoot ():
227- """
228- This method returns the web application document root based on the
229- detected absolute files paths in the knowledge base.
230- """
231-
232227 docRoot = None
233228
234- if kb .absFilePaths :
235- logMsg = "retrieved the possible injectable "
236- logMsg += "file absolute system paths: "
237- logMsg += "'%s'" % ", " .join (path for path in kb .absFilePaths )
238- logger .info (logMsg )
229+ if kb .os == "Windows" :
230+ defaultDocRoot = "C:\\ Inetput\\ wwwroot\\ "
239231 else :
240- warnMsg = "unable to retrieve the injectable file "
241- warnMsg += "absolute system path"
242- logger .warn (warnMsg )
232+ defaultDocRoot = "/var/www/"
243233
244- for absFilePath in kb .absFilePaths :
245- if conf .path in absFilePath :
246- index = absFilePath .index (conf .path )
247- docRoot = absFilePath [:index ]
248- break
234+ if kb .absFilePaths :
235+ for absFilePath in kb .absFilePaths :
236+ absFilePathWin = None
237+
238+ if re .search ("([\w]\:[\/\\ \\ ]+)" , absFilePath ):
239+ absFilePathWin = absFilePath
240+ absFilePath = absFilePath [2 :].replace ("\\ " , "/" )
241+
242+ absFilePath = os .path .normpath (absFilePath )
243+
244+ if os .path .dirname (conf .path ) in absFilePath :
245+ index = absFilePath .index (conf .path )
246+ docRoot = absFilePath [:index ]
247+
248+ if absFilePathWin :
249+ docRoot = "C:\\ %s" % docRoot .replace ("/" , "\\ " )
250+
251+ break
249252
250253 if docRoot :
251- logMsg = "retrieved the remote web server "
252- logMsg += "document root: '%s'" % docRoot
253- logger .info (logMsg )
254+ infoMsg = "retrieved the web server document root: '%s'" % docRoot
255+ logger .info (infoMsg )
254256 else :
255- warnMsg = "unable to retrieve the remote web server "
256- warnMsg += "document root"
257+ warnMsg = "unable to retrieve the web server document root"
257258 logger .warn (warnMsg )
258259
259- return docRoot
260+ message = "please provide the web server document root "
261+ message += "[%s]: " % defaultDocRoot
262+ inputDocRoot = readInput (message , default = defaultDocRoot )
260263
264+ if inputDocRoot :
265+ docRoot = inputDocRoot
266+ else :
267+ docRoot = defaultDocRoot
261268
262- def getDirectories ():
263- """
264- This method calls a function that returns the web application document
265- root and injectable file absolute system path.
269+ return docRoot
266270
267- @return: a set of paths (document root and absolute system path).
268- @rtype: C{set}
269- @todo: replace this function with a site crawling functionality.
270- """
271271
272+ def getDirs ():
272273 directories = set ()
273274
274- kb .docRoot = getDocRoot ()
275+ if kb .os == "Windows" :
276+ defaultDir = "C:\\ Inetput\\ wwwroot\\ test\\ "
277+ else :
278+ defaultDir = "/var/www/test/"
279+
280+ if kb .absFilePaths :
281+ infoMsg = "retrieved web server full paths: "
282+ infoMsg += "'%s'" % ", " .join (path for path in kb .absFilePaths )
283+ logger .info (infoMsg )
275284
276- if kb .docRoot :
277- directories .add (kb .docRoot )
285+ for absFilePath in kb .absFilePaths :
286+ directories .add (os .path .dirname (absFilePath ))
287+ else :
288+ warnMsg = "unable to retrieve any web server path"
289+ logger .warn (warnMsg )
278290
279- pagePath = re .search ("^/(.*)/" , conf .path )
291+ message = "please provide any additional web server full path to try "
292+ message += "to upload the agent [%s]: " % defaultDir
293+ inputDirs = readInput (message , default = defaultDir )
280294
281- if kb .docRoot and pagePath :
282- pagePath = pagePath .groups ()[0 ]
295+ if inputDirs :
296+ inputDirs = inputDirs .replace (", " , "," )
297+ inputDirs = inputDirs .split ("," )
283298
284- directories .add ("%s/%s" % (kb .docRoot , pagePath ))
299+ for inputDir in inputDirs :
300+ directories .add (inputDir )
301+ else :
302+ directories .add (defaultDir )
285303
286304 return directories
287305
288306
289307def filePathToString (filePath ):
290- string = filePath .replace ("/" , "_" ).replace ("\\ " , "_" )
291- string = string .replace (" " , "_" ).replace (":" , "_" )
308+ strRepl = filePath .replace ("/" , "_" ).replace ("\\ " , "_" )
309+ strRepl = strRepl .replace (" " , "_" ).replace (":" , "_" )
292310
293- return string
311+ return strRepl
294312
295313
296314def dataToStdout (data ):
@@ -326,18 +344,18 @@ def dataToOutFile(data):
326344 return rFilePath
327345
328346
329- def strToHex (string ):
347+ def strToHex (inpStr ):
330348 """
331- @param string: string to be converted into its hexadecimal value.
332- @type string : C{str}
349+ @param inpStr: inpStr to be converted into its hexadecimal value.
350+ @type inpStr : C{str}
333351
334- @return: the hexadecimal converted string .
352+ @return: the hexadecimal converted inpStr .
335353 @rtype: C{str}
336354 """
337355
338356 hexStr = ""
339357
340- for character in string :
358+ for character in inpStr :
341359 if character == "\n " :
342360 character = " "
343361
@@ -457,17 +475,17 @@ def randomStr(length=5, lowercase=False):
457475 return rndStr
458476
459477
460- def sanitizeStr (string ):
478+ def sanitizeStr (inpStr ):
461479 """
462- @param string: string to sanitize: cast to str datatype and replace
480+ @param inpStr: inpStr to sanitize: cast to str datatype and replace
463481 newlines with one space and strip carriage returns.
464- @type string : C{str}
482+ @type inpStr : C{str}
465483
466- @return: sanitized string
484+ @return: sanitized inpStr
467485 @rtype: C{str}
468486 """
469487
470- cleanString = str (string )
488+ cleanString = str (inpStr )
471489 cleanString = cleanString .replace ("\n " , " " ).replace ("\r " , "" )
472490
473491 return cleanString
@@ -483,8 +501,8 @@ def checkFile(filename):
483501 raise sqlmapFilePathException , "unable to read file '%s'" % filename
484502
485503
486- def replaceNewlineTabs (string ):
487- replacedString = string .replace ("\n " , "__NEWLINE__" ).replace ("\t " , "__TAB__" )
504+ def replaceNewlineTabs (inpStr ):
505+ replacedString = inpStr .replace ("\n " , "__NEWLINE__" ).replace ("\t " , "__TAB__" )
488506 replacedString = replacedString .replace (temp .delimiter , "__DEL__" )
489507
490508 return replacedString
0 commit comments