Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da138c4

Browse files
committed
added support for displaying HTTP error codes (particularly interesting ones are 403 and 406 which screw up data retrieval and DBMS fingerprinting badly)
1 parent ec44401 commit da138c4

5 files changed

Lines changed: 27 additions & 10 deletions

File tree

lib/controller/controller.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from lib.core.common import paramToDict
2424
from lib.core.common import parseTargetUrl
2525
from lib.core.common import readInput
26+
from lib.core.common import showHttpErrorCodes
2627
from lib.core.data import conf
2728
from lib.core.data import kb
2829
from lib.core.data import logger
@@ -432,6 +433,9 @@ def start():
432433
logger.critical(e)
433434
return False
434435

436+
finally:
437+
showHttpErrorCodes()
438+
435439
if conf.loggedToOut:
436440
logger.info("Fetched data logged to text files under '%s'" % conf.outputPath)
437441

lib/core/common.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import ntpath
2222
import posixpath
2323
import subprocess
24+
import httplib
2425

2526
from ConfigParser import DEFAULTSECT
2627
from ConfigParser import RawConfigParser
@@ -419,14 +420,13 @@ def filePathToString(filePath):
419420
return strRepl
420421

421422
def dataToStdout(data, forceOutput=False):
422-
if (forceOutput or conf.verbose > 0)\
423-
and not ('threadException' in kb and kb.threadException)\
424-
and not ('disableStdOut' in kb and kb.disableStdOut):
425-
try:
426-
sys.stdout.write(data)
427-
sys.stdout.flush()
428-
except UnicodeEncodeError:
429-
print data.encode(conf.dataEncoding)
423+
if not ('threadException' in kb and kb.threadException):
424+
if forceOutput or (conf.verbose > 0) and not ('disableStdOut' in kb and kb.disableStdOut):
425+
try:
426+
sys.stdout.write(data)
427+
sys.stdout.flush()
428+
except UnicodeEncodeError:
429+
print data.encode(conf.dataEncoding)
430430

431431
def dataToSessionFile(data):
432432
if not conf.sessionFile:
@@ -1956,3 +1956,11 @@ def unicodeToSafeHTMLValue(value):
19561956

19571957
def getErrorParsedDBMS():
19581958
return kb.htmlFp[0] if kb.htmlFp else None
1959+
1960+
def showHttpErrorCodes():
1961+
if kb.httpErrorCodes:
1962+
warnMsg = "HTTP error codes detected during testing:\n"
1963+
warnMsg += ", ".join("%d (%s) - %d times" % (code, httplib.responses[code]\
1964+
if code in httplib.responses else '?', count)\
1965+
for code, count in kb.httpErrorCodes.items())
1966+
logger.warn(warnMsg)

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ def __setKnowledgeBaseAttributes(flushAll=True):
11561156
kb.docRoot = None
11571157
kb.dynamicMarkings = []
11581158
kb.endDetection = False
1159+
kb.httpErrorCodes = {}
11591160
kb.errorIsNone = True
11601161
kb.formNames = []
11611162
kb.headersCount = 0

lib/request/connect.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ def getPage(**kwargs):
252252

253253
threadData.lastHTTPError = (threadData.lastRequestUID, code)
254254

255+
if code not in kb.httpErrorCodes:
256+
kb.httpErrorCodes[code] = 0
257+
kb.httpErrorCodes[code] += 1
258+
255259
try:
256260
page = e.read()
257261
responseHeaders = e.info()

sqlmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ def main():
115115
closeDumper(True)
116116

117117
finally:
118+
dataToStdout("\n[*] shutting down at: %s\n\n" % time.strftime("%X"), forceOutput=True)
119+
118120
kb.threadContinue = False
119121
kb.threadException = True
120122

121-
dataToStdout("\n[*] shutting down at: %s\n\n" % time.strftime("%X"), forceOutput=True)
122-
123123
if __name__ == "__main__":
124124
main()

0 commit comments

Comments
 (0)