Skip to content

Commit 7b8e03e

Browse files
committed
Fix for MSSQL row retrieval losing duplicates (OFFSET/FETCH for 2012+ and Azure)
1 parent e85b1bb commit 7b8e03e

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎lib/core/agent.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,11 @@ def limitQuery(self, num, query, field=None, uniqueField=None):
12671267
orderBy = limitedQuery[limitedQuery.index(" ORDER BY "):]
12681268
limitedQuery = limitedQuery[:limitedQuery.index(" ORDER BY ")]
12691269

1270+
# Note: Microsoft SQL Server 2012+ (and Azure) supports OFFSET/FETCH (row position based), while the (old) NOT IN forging is value based (i.e. collapses duplicate values)
1271+
if Backend.isDbms(DBMS.MSSQL) and (Backend.isVersionGreaterOrEqualThan("2012") or Backend.isVersionWithin(("Azure",))) and not re.search(r"(?i)\A(SELECT\s+)?(TOP|DISTINCT)\b", limitedQuery):
1272+
limitedQuery = "%s%s OFFSET %d ROWS FETCH NEXT 1 ROWS ONLY" % (limitedQuery, orderBy or " ORDER BY %s" % (uniqueField or '1'), num)
1273+
return limitedQuery
1274+
12701275
notDistincts = re.findall(r"DISTINCT[\(\s+](.+?)\)*\s+", limitedQuery, re.I)
12711276

12721277
for notDistinct in notDistincts:

‎lib/core/settings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from thirdparty import six
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.10.11.24"
22+
VERSION = "1.10.11.25"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

0 commit comments

Comments
 (0)