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

Skip to content

Commit 428e817

Browse files
committed
some refactoring
1 parent 212035e commit 428e817

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

lib/controller/checks.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from lib.core.common import extractRegexResult
1717
from lib.core.common import findDynamicContent
1818
from lib.core.common import getCompiledRegex
19+
from lib.core.common import getErrorParsedDBMS
1920
from lib.core.common import getInjectionTests
2021
from lib.core.common import getUnicode
2122
from lib.core.common import popValue
@@ -139,17 +140,17 @@ def checkSqlInjection(place, parameter, value):
139140

140141
continue
141142

142-
if kb.htmlFp and kb.htmlFp[-1] and kb.htmlFp[-1] != dbms\
143+
if getErrorParsedDBMS() and getErrorParsedDBMS() != dbms\
143144
and kb.skipTests is None:
144-
message = "heuristic test showed that the back-end DBMS could be '%s'." % kb.htmlFp[-1]
145+
message = "heuristic test showed that the back-end DBMS could be '%s'." % getErrorParsedDBMS()
145146
message += " do you want to skip test payloads specific for other DBMSes? [Y/n]"
146147
kb.skipTests = conf.realTest or readInput(message, default="Y") not in ("n", "N")
147148

148149
if kb.skipTests:
149150
debugMsg = "skipping test '%s' because " % title
150151
debugMsg += "the heuristic test showed that "
151152
debugMsg += "the back-end DBMS could be "
152-
debugMsg += "%s" % kb.htmlFp[-1]
153+
debugMsg += "%s" % getErrorParsedDBMS()
153154
logger.debug(debugMsg)
154155

155156
continue
@@ -472,7 +473,7 @@ def heuristicCheckSqlInjection(place, parameter, value):
472473
infoMsg += "parameter '%s' might " % parameter
473474

474475
if result:
475-
infoMsg += "be injectable (possible DBMS: %s)" % (kb.htmlFp[-1] if kb.htmlFp else 'Unknown')
476+
infoMsg += "be injectable (possible DBMS: %s)" % (getErrorParsedDBMS() or 'Unknown')
476477
logger.info(infoMsg)
477478
else:
478479
infoMsg += "not be injectable"

lib/controller/handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
See the file 'doc/COPYING' for copying permission
88
"""
99

10+
from lib.core.common import getErrorParsedDBMS
1011
from lib.core.common import popValue
1112
from lib.core.common import pushValue
1213
from lib.core.data import conf
@@ -62,7 +63,7 @@ def setHandler():
6263
( SYBASE_ALIASES, SybaseMap, SybaseConn ),
6364
]
6465

65-
inferencedDbms = (kb.htmlFp[-1] if kb.htmlFp else None) or kb.dbms
66+
inferencedDbms = getErrorParsedDBMS() or kb.dbms
6667

6768
for injection in kb.injections:
6869
if hasattr(injection, "dbms") and injection.dbms:

lib/core/common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,8 +1919,8 @@ def getInjectionTests():
19191919
detected DBMS from error messages
19201920
"""
19211921
retVal = conf.tests
1922-
if kb.htmlFp:
1923-
dbms = kb.htmlFp[-1]
1922+
if getErrorParsedDBMS():
1923+
dbms = getErrorParsedDBMS()
19241924
retVal = sorted(retVal, key=lambda test: False\
19251925
if 'details' in test and 'dbms' in test.details\
19261926
and test.details.dbms == dbms else True)
@@ -1953,3 +1953,6 @@ def unicodeToSafeHTMLValue(value):
19531953
if ord(char) > 127:
19541954
retVal = retVal.replace(char, "&#%d;" % ord(char))
19551955
return retVal
1956+
1957+
def getErrorParsedDBMS():
1958+
return kb.htmlFp[0] if kb.htmlFp else None

0 commit comments

Comments
 (0)