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

Skip to content

Commit 2d87a33

Browse files
committed
Fixed custom MSSQL "limited" query support also for Partial UNION query technique
1 parent 9c42a88 commit 2d87a33

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/core/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,15 @@ def limitQuery(self, num, query, field):
481481
if " ORDER BY " in limitedQuery:
482482
limitedQuery = limitedQuery[:limitedQuery.index(" ORDER BY ")]
483483

484-
if not limitedQuery.startswith("SELECT TOP "):
484+
if not limitedQuery.startswith("SELECT TOP ") and not limitedQuery.startswith("TOP "):
485485
limitedQuery = limitedQuery.replace("SELECT ", (limitStr % 1), 1)
486486
limitedQuery = "%s WHERE %s " % (limitedQuery, field)
487487
limitedQuery += "NOT IN (%s" % (limitStr % num)
488488
limitedQuery += "%s %s)" % (field, fromFrom)
489489
else:
490-
topNums = re.search("\ASELECT\s+TOP\s+([\d]+)\s+.+?\s+FROM\s+.+?\s+WHERE\s+.+?\s+NOT\s+IN\s+\(SELECT\s+TOP\s+([\d]+)\s+", limitedQuery, re.I).groups()
490+
topNums = re.search("TOP\s+([\d]+)\s+.+?\s+FROM\s+.+?\s+WHERE\s+.+?\s+NOT\s+IN\s+\(SELECT\s+TOP\s+([\d]+)\s+", limitedQuery, re.I).groups()
491491
quantityTopNums = topNums[0]
492-
limitedQuery = limitedQuery.replace("SELECT TOP %s" % quantityTopNums, "SELECT TOP 1", 1)
492+
limitedQuery = limitedQuery.replace("TOP %s" % quantityTopNums, "TOP 1", 1)
493493
startTopNums = topNums[1]
494494
limitedQuery = limitedQuery.replace(" (SELECT TOP %s" % startTopNums, " (SELECT TOP %d" % num)
495495

lib/techniques/inband/union/use.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ def unionUse(expression, direct=False, unescape=True, resetCounter=False):
216216
untilLimitChar = expression.index(queries[kb.dbms].limitstring)
217217
expression = expression[:untilLimitChar]
218218

219+
elif kb.dbms == "Microsoft SQL Server":
220+
stopLimit += startLimit
221+
219222
if not stopLimit or stopLimit <= 1:
220223
if kb.dbms == "Oracle" and expression.endswith("FROM DUAL"):
221224
test = False

xml/queries.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
<isnull query="ISNULL(%s, ' ')"/>
170170
<delimiter query="+"/>
171171
<limit query="SELECT TOP %d "/>
172-
<limitregexp query="SELECT\s+TOP\s+([\d]+)\s+.+?\s+FROM\s+.+?\s+WHERE\s+.+?\s+NOT\s+IN\s+\(SELECT\s+TOP\s+([\d]+)\s+"/>
172+
<limitregexp query="TOP\s+([\d]+)\s+.+?\s+FROM\s+.+?\s+WHERE\s+.+?\s+NOT\s+IN\s+\(SELECT\s+TOP\s+([\d]+)\s+"/>
173173
<limitgroupstart query="2"/>
174174
<limitgroupstop query="1"/>
175175
<limitstring/>

0 commit comments

Comments
 (0)