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

Skip to content

Commit 06be7bb

Browse files
committed
few just in case fixes (unarrayizeValue in dumpTable entries) and and some refactoring (unique is now not done for every union case but only if detected that there are duplicates in union test)
1 parent 76c873a commit 06be7bb

10 files changed

Lines changed: 19 additions & 20 deletions

File tree

lib/core/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ def getLimitRange(count, dump=False, plusOne=False):
11891189

11901190
return retVal
11911191

1192-
def parseUnionPage(page, unique=True):
1192+
def parseUnionPage(page):
11931193
"""
11941194
Returns resulting items from inband query inside provided page content
11951195
"""
@@ -1211,7 +1211,7 @@ def parseUnionPage(page, unique=True):
12111211
if kb.chars.start in entry:
12121212
entry = entry.split(kb.chars.start)[-1]
12131213

1214-
if unique:
1214+
if kb.unionDuplicates:
12151215
key = entry.lower()
12161216
if key not in _:
12171217
_.append(key)

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ def __setKnowledgeBaseAttributes(flushAll=True):
15121512
kb.threadException = False
15131513
kb.timeValidCharsRun = 0
15141514
kb.uChar = NULL
1515+
kb.unionDuplicates = False
15151516
kb.xpCmdshellAvailable = False
15161517

15171518
kb.chars = AttribDict()

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@
456456
HASHDB_FLUSH_THRESHOLD = 32
457457

458458
# Unique milestone value used for forced deprecation of old HashDB values (e.g. when changing hash/pickle mechanism)
459-
HASHDB_MILESTONE_VALUE = "EfjamfhMVw" # r4856
459+
HASHDB_MILESTONE_VALUE = "ZTuyinSUvN" # r5125 "".join(random.sample(string.letters, 10))
460460

461461
# Warn user of possible delay due to large page dump in full UNION query injections
462462
LARGE_OUTPUT_THRESHOLD = 1024**2

lib/request/inject.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,19 @@ def __goError(expression, expected=None, dump=False):
356356

357357
return output
358358

359-
def __goInband(expression, expected=None, unique=True, unpack=True, dump=False):
359+
def __goInband(expression, expected=None, unpack=True, dump=False):
360360
"""
361361
Retrieve the output of a SQL query taking advantage of an inband SQL
362362
injection vulnerability on the affected parameter.
363363
"""
364364

365365
output = unionUse(expression, unpack=unpack, dump=dump)
366366
if isinstance(output, basestring):
367-
output = parseUnionPage(output, unique)
367+
output = parseUnionPage(output)
368368

369369
return output
370370

371-
def getValue(expression, blind=True, inband=True, error=True, time=True, fromUser=False, expected=None, batch=False, unpack=True, unique=True, resumeValue=True, charsetType=None, firstChar=None, lastChar=None, dump=False, suppressOutput=None, expectingNone=False, safeCharEncode=True):
371+
def getValue(expression, blind=True, inband=True, error=True, time=True, fromUser=False, expected=None, batch=False, unpack=True, resumeValue=True, charsetType=None, firstChar=None, lastChar=None, dump=False, suppressOutput=None, expectingNone=False, safeCharEncode=True):
372372
"""
373373
Called each time sqlmap inject a SQL query on the SQL injection
374374
affected parameter. It can call a function to retrieve the output
@@ -413,9 +413,9 @@ def getValue(expression, blind=True, inband=True, error=True, time=True, fromUse
413413
kb.technique = PAYLOAD.TECHNIQUE.UNION
414414

415415
if expected == EXPECTED.BOOL:
416-
value = __goInband(forgeCaseExpression, expected, unique, unpack, dump)
416+
value = __goInband(forgeCaseExpression, expected, unpack, dump)
417417
else:
418-
value = __goInband(query, expected, unique, unpack, dump)
418+
value = __goInband(query, expected, unpack, dump)
419419

420420
count += 1
421421
found = (value is not None) or (value is None and expectingNone) or count >= MAX_TECHNIQUES_PER_VALUE

lib/takeover/xp_cmdshell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def xpCmdshellEvalCmd(self, cmd, first=None, last=None):
188188

189189
self.delRemoteFile(tmpFile)
190190

191-
output = inject.getValue("SELECT %s FROM %s" % (self.tblField, self.cmdTblName), resumeValue=False, unique=False, firstChar=first, lastChar=last, safeCharEncode=False)
191+
output = inject.getValue("SELECT %s FROM %s" % (self.tblField, self.cmdTblName), resumeValue=False, firstChar=first, lastChar=last, safeCharEncode=False)
192192
inject.goStacked("DELETE FROM %s" % self.cmdTblName)
193193

194194
if output and isinstance(output, (list, tuple)):

lib/techniques/union/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __unionPosition(comment, place, parameter, prefix, suffix, count, where=PAYL
186186

187187
if content and phrase in content:
188188
validPayload = payload
189-
vector = (position, count, comment, prefix, suffix, kb.uChar, where)
189+
vector = (position, count, comment, prefix, suffix, kb.uChar, where, content.count(phrase) > 1)
190190

191191
if where == PAYLOAD.WHERE.ORIGINAL:
192192
# Prepare expression with delimiters

lib/techniques/union/use.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __oneShotUnionUse(expression, unpack=True, limited=False):
6666

6767
# Forge the inband SQL injection request
6868
vector = kb.injection.data[PAYLOAD.TECHNIQUE.UNION].vector
69+
kb.unionDuplicates = vector[7]
6970
query = agent.forgeInbandQuery(injExpression, vector[0], vector[1], vector[2], vector[3], vector[4], vector[5], vector[6], None, limited)
7071
payload = agent.payload(newValue=query, where=where)
7172

plugins/dbms/mssqlserver/filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def stackedReadFile(self, rFile):
145145
inject.goStacked(binToHexQuery)
146146

147147
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION):
148-
result = inject.getValue("SELECT %s FROM %s ORDER BY id ASC" % (self.tblField, hexTbl), unique=False, resumeValue=False, blind=False, error=False)
148+
result = inject.getValue("SELECT %s FROM %s ORDER BY id ASC" % (self.tblField, hexTbl), resumeValue=False, blind=False, error=False)
149149

150150
if not result:
151151
result = []
@@ -159,7 +159,7 @@ def stackedReadFile(self, rFile):
159159
indexRange = getLimitRange(count)
160160

161161
for index in indexRange:
162-
chunk = inject.getValue("SELECT TOP 1 %s FROM %s WHERE %s NOT IN (SELECT TOP %d %s FROM %s ORDER BY id ASC) ORDER BY id ASC" % (self.tblField, hexTbl, self.tblField, index, self.tblField, hexTbl), unpack=False, resumeValue=False, unique=False, charsetType=CHARSET_TYPE.HEXADECIMAL)
162+
chunk = inject.getValue("SELECT TOP 1 %s FROM %s WHERE %s NOT IN (SELECT TOP %d %s FROM %s ORDER BY id ASC) ORDER BY id ASC" % (self.tblField, hexTbl, self.tblField, index, self.tblField, hexTbl), unpack=False, resumeValue=False, charsetType=CHARSET_TYPE.HEXADECIMAL)
163163
result.append(chunk)
164164

165165
inject.goStacked("DROP TABLE %s" % hexTbl)

plugins/dbms/mysql/filesystem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def stackedReadFile(self, rFile):
5454
logger.debug(debugMsg)
5555
inject.goStacked("LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY '%s' (%s)" % (tmpFile, self.fileTblName, randomStr(10), self.tblField))
5656

57-
length = inject.getValue("SELECT LENGTH(%s) FROM %s" % (self.tblField, self.fileTblName), unique=False, resumeValue=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
57+
length = inject.getValue("SELECT LENGTH(%s) FROM %s" % (self.tblField, self.fileTblName), resumeValue=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
5858

5959
if not isNumPosStrValue(length):
6060
warnMsg = "unable to retrieve the content of the "
@@ -74,11 +74,11 @@ def stackedReadFile(self, rFile):
7474
result = []
7575

7676
for i in xrange(1, length, sustrLen):
77-
chunk = inject.getValue("SELECT MID(%s, %d, %d) FROM %s" % (self.tblField, i, sustrLen, self.fileTblName), unpack=False, unique=False, resumeValue=False, charsetType=CHARSET_TYPE.HEXADECIMAL)
77+
chunk = inject.getValue("SELECT MID(%s, %d, %d) FROM %s" % (self.tblField, i, sustrLen, self.fileTblName), unpack=False, resumeValue=False, charsetType=CHARSET_TYPE.HEXADECIMAL)
7878

7979
result.append(chunk)
8080
else:
81-
result = inject.getValue("SELECT %s FROM %s" % (self.tblField, self.fileTblName), unique=False, resumeValue=False, charsetType=CHARSET_TYPE.HEXADECIMAL)
81+
result = inject.getValue("SELECT %s FROM %s" % (self.tblField, self.fileTblName), resumeValue=False, charsetType=CHARSET_TYPE.HEXADECIMAL)
8282

8383
return result
8484

plugins/generic/enumeration.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,9 +1611,8 @@ def dumpTable(self, foundData=None):
16111611
entries = []
16121612

16131613
entriesCount = len(entries)
1614-
index = 0
16151614

1616-
for column in colList:
1615+
for index, column in enumerate(colList):
16171616
colLen = len(column)
16181617

16191618
if column not in kb.data.dumpedTable:
@@ -1626,7 +1625,7 @@ def dumpTable(self, foundData=None):
16261625
if isinstance(entry, basestring):
16271626
colEntry = entry
16281627
else:
1629-
colEntry = entry[index] if index < len(entry) else u''
1628+
colEntry = unArrayizeValue(entry[index]) if index < len(entry) else u''
16301629

16311630
colEntryLen = len({" ": NULL, "": BLANK}.get(getUnicode(colEntry), getUnicode(colEntry)))
16321631
maxLen = max(colLen, colEntryLen)
@@ -1636,8 +1635,6 @@ def dumpTable(self, foundData=None):
16361635

16371636
kb.data.dumpedTable[column]["values"].append(colEntry)
16381637

1639-
index += 1
1640-
16411638
if not kb.data.dumpedTable and isInferenceAvailable() and not conf.direct:
16421639
infoMsg = "fetching number of "
16431640
if conf.col:

0 commit comments

Comments
 (0)