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

Skip to content

Commit 80df1fd

Browse files
committed
Minor bug fix with --sql-query/shell when providing a statement with DISTINCT
1 parent 954a927 commit 80df1fd

5 files changed

Lines changed: 15 additions & 4 deletions

File tree

lib/core/agent.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ def limitQuery(self, num, query, field):
502502
if " ORDER BY " in limitedQuery:
503503
limitedQuery = limitedQuery[:limitedQuery.index(" ORDER BY ")]
504504

505+
notDistincts = re.findall("DISTINCT[\(\s+](.+?)\)*\s+", limitedQuery, re.I)
506+
507+
for notDistinct in notDistincts:
508+
limitedQuery = limitedQuery.replace("DISTINCT(%s)" % notDistinct, notDistinct)
509+
limitedQuery = limitedQuery.replace("DISTINCT %s" % notDistinct, notDistinct)
510+
505511
if limitedQuery.startswith("SELECT TOP ") or limitedQuery.startswith("TOP "):
506512
topNums = re.search(queries[kb.dbms].limitregexp, limitedQuery, re.I)
507513

@@ -517,11 +523,13 @@ def limitQuery(self, num, query, field):
517523
limitedQuery = limitedQuery.replace("TOP %s " % topNum, "")
518524

519525
if forgeNotIn:
520-
limitedQuery = limitedQuery.replace("SELECT ", (limitStr % 1), 1)
526+
limitedQuery = limitedQuery.replace("SELECT ", (limitStr % 1), 1)
527+
521528
if " WHERE " in limitedQuery:
522529
limitedQuery = "%s AND %s " % (limitedQuery, field)
523530
else:
524531
limitedQuery = "%s WHERE %s " % (limitedQuery, field)
532+
525533
limitedQuery += "NOT IN (%s" % (limitStr % num)
526534
limitedQuery += "%s %s)" % (field, fromFrom)
527535

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def parsePasswordHash(password):
510510
password += "%suppercase: %s" % (blank, hexPassword[54:])
511511

512512
return password
513-
513+
514514
def cleanQuery(query):
515515
upperQuery = query
516516

lib/core/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"select ",
7575
"show ",
7676
" top ",
77+
" distinct ",
7778
" from ",
7879
" from dual",
7980
" where ",

lib/request/inject.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ def getValue(expression, blind=True, inband=True, fromUser=False, expected=None,
350350
expression = expandAsteriskForColumns(expression)
351351
value = None
352352

353+
expression = expression.replace("DISTINCT ", "")
354+
353355
if inband and kb.unionPosition:
354356
if kb.dbms == "Oracle" and " ORDER BY " in expression:
355357
expression = expression[:expression.index(" ORDER BY ")]

plugins/generic/enumeration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,8 @@ def dumpAll(self):
10761076
dumper.dbTableValues(data)
10771077

10781078
def sqlQuery(self, query):
1079-
output = None
1080-
sqlType = None
1079+
output = None
1080+
sqlType = None
10811081

10821082
for sqlTitle, sqlStatements in SQL_STATEMENTS.items():
10831083
for sqlStatement in sqlStatements:

0 commit comments

Comments
 (0)