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

Skip to content

Commit f2c2864

Browse files
committed
Couple of trivial updates
1 parent 9eda11d commit f2c2864

10 files changed

Lines changed: 39 additions & 26 deletions

File tree

lib/core/agent.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def cleanupPayload(self, payload, origValue=None):
334334

335335
if origValue is not None:
336336
origValue = getUnicode(origValue)
337+
337338
if "[ORIGVALUE]" in payload:
338339
payload = getUnicode(payload).replace("[ORIGVALUE]", origValue if origValue.isdigit() else unescaper.escape("'%s'" % origValue))
339340
if "[ORIGINAL]" in payload:
@@ -352,6 +353,7 @@ def cleanupPayload(self, payload, origValue=None):
352353
inferenceQuery = inference.query
353354

354355
payload = payload.replace(INFERENCE_MARKER, inferenceQuery)
356+
355357
elif not kb.testMode:
356358
errMsg = "invalid usage of inference payload without "
357359
errMsg += "knowledge of underlying DBMS"
@@ -394,7 +396,7 @@ def hexConvertField(self, field):
394396
if "hex" in rootQuery:
395397
hexField = rootQuery.hex.query % field
396398
else:
397-
warnMsg = "switch '--hex' is currently not supported on DBMS %s" % Backend.getIdentifiedDbms()
399+
warnMsg = "switch '--hex' is currently not supported on DBMS '%s'" % Backend.getIdentifiedDbms()
398400
singleTimeWarnMessage(warnMsg)
399401

400402
return hexField
@@ -1008,7 +1010,7 @@ def limitQuery(self, num, query, field=None, uniqueField=None):
10081010
limitedQuery = "%s WHERE %s " % (limitedQuery, self.nullAndCastField(uniqueField or field))
10091011

10101012
limitedQuery += "NOT IN (%s" % (limitStr % num)
1011-
limitedQuery += "%s %s ORDER BY %s) ORDER BY %s" % (self.nullAndCastField(uniqueField or field), fromFrom, uniqueField or "1", uniqueField or "1")
1013+
limitedQuery += "%s %s ORDER BY %s) ORDER BY %s" % (self.nullAndCastField(uniqueField or field), fromFrom, uniqueField or '1', uniqueField or '1')
10121014
else:
10131015
match = re.search(r" ORDER BY (\w+)\Z", query)
10141016
field = match.group(1) if match else field
@@ -1082,7 +1084,7 @@ def removePayloadDelimiters(self, value):
10821084
Removes payload delimiters from inside the input string
10831085
"""
10841086

1085-
return value.replace(PAYLOAD_DELIMITER, '') if value else value
1087+
return value.replace(PAYLOAD_DELIMITER, "") if value else value
10861088

10871089
def extractPayload(self, value):
10881090
"""

lib/core/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import random
1515
import sys
16+
import time
1617
import uuid
1718

1819
class WichmannHill(random.Random):
@@ -40,7 +41,6 @@ def seed(self, a=None):
4041
try:
4142
a = int(binascii.hexlify(os.urandom(16)), 16)
4243
except NotImplementedError:
43-
import time
4444
a = int(time.time() * 256) # use fractional seconds
4545

4646
if not isinstance(a, int):
@@ -132,7 +132,6 @@ def __whseed(self, x=0, y=0, z=0):
132132
raise ValueError('seeds must be in range(0, 256)')
133133
if 0 == x == y == z:
134134
# Initialize from current time
135-
import time
136135
t = int(time.time() * 256)
137136
t = int((t & 0xffffff) ^ (t >> 24))
138137
t, x = divmod(t, 256)
@@ -204,6 +203,7 @@ def round(x, d=0):
204203
else:
205204
return float(math.ceil((x * p) - 0.5)) / p
206205

206+
# Reference: https://code.activestate.com/recipes/576653-convert-a-cmp-function-to-a-key-function/
207207
def cmp_to_key(mycmp):
208208
"""Convert a cmp= function into a key= function"""
209209
class K(object):

lib/core/enums.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ class HASHDB_KEYS(object):
244244
OS = "OS"
245245

246246
class REDIRECTION(object):
247-
YES = "Y"
248-
NO = "N"
247+
YES = 'Y'
248+
NO = 'N'
249249

250250
class PAYLOAD(object):
251251
SQLINJECTION = {

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.8.30"
21+
VERSION = "1.3.8.31"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -333,6 +333,9 @@
333333
# String representation for current database
334334
CURRENT_DB = "CD"
335335

336+
# String representation for current user
337+
CURRENT_USER = "CU"
338+
336339
# Name of SQLite file used for storing session data
337340
SESSION_SQLITE_FILE = "session.sqlite"
338341

lib/takeover/metasploit.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,15 @@ def _selectPayload(self):
227227

228228
if not choice or choice == "2":
229229
_payloadStr = "windows/meterpreter"
230-
231230
break
232231

233232
elif choice == "3":
234233
_payloadStr = "windows/shell"
235-
236234
break
237235

238236
elif choice == "1":
239237
if Backend.isDbms(DBMS.PGSQL):
240238
logger.warn("beware that the VNC injection might not work")
241-
242239
break
243240

244241
elif Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")):

lib/techniques/error/use.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False):
7676

7777
threadData.resumed = retVal is not None and not partialValue
7878

79-
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL, DBMS.ORACLE)) and kb.errorChunkLength is None and not chunkTest and not kb.testMode:
79+
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL, DBMS.SYBASE, DBMS.ORACLE)) and kb.errorChunkLength is None and not chunkTest and not kb.testMode:
8080
debugMsg = "searching for error chunk length..."
8181
logger.debug(debugMsg)
8282

@@ -117,7 +117,7 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False):
117117
if field:
118118
nulledCastedField = agent.nullAndCastField(field)
119119

120-
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL, DBMS.ORACLE)) and not any(_ in field for _ in ("COUNT", "CASE")) and kb.errorChunkLength and not chunkTest:
120+
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL, DBMS.SYBASE, DBMS.ORACLE)) and not any(_ in field for _ in ("COUNT", "CASE")) and kb.errorChunkLength and not chunkTest:
121121
extendedField = re.search(r"[^ ,]*%s[^ ,]*" % re.escape(field), expression).group(0)
122122
if extendedField != field: # e.g. MIN(surname)
123123
nulledCastedField = extendedField.replace(field, nulledCastedField)
@@ -177,7 +177,7 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False):
177177
else:
178178
output = output.rstrip()
179179

180-
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL, DBMS.ORACLE)):
180+
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL, DBMS.SYBASE, DBMS.ORACLE)):
181181
if offset == 1:
182182
retVal = output
183183
else:
@@ -367,7 +367,7 @@ def errorUse(expression, dump=False):
367367
message = "due to huge table size do you want to remove "
368368
message += "ORDER BY clause gaining speed over consistency? [y/N] "
369369

370-
if readInput(message, default="N", boolean=True):
370+
if readInput(message, default='N', boolean=True):
371371
expression = expression[:expression.index(" ORDER BY ")]
372372

373373
numThreads = min(conf.threads, (stopLimit - startLimit))

lib/techniques/union/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _orderByTest(cols):
163163

164164
if retVal:
165165
infoMsg = "target URL appears to be UNION injectable with %d columns" % retVal
166-
singleTimeLogMessage(infoMsg, logging.INFO, re.sub(r"\d+", "N", infoMsg))
166+
singleTimeLogMessage(infoMsg, logging.INFO, re.sub(r"\d+", 'N', infoMsg))
167167

168168
return retVal
169169

@@ -290,7 +290,7 @@ def _unionTestByCharBruteforce(comment, place, parameter, value, prefix, suffix)
290290
if not conf.uChar and count > 1 and kb.uChar == NULL:
291291
message = "injection not exploitable with NULL values. Do you want to try with a random integer value for option '--union-char'? [Y/n] "
292292

293-
if not readInput(message, default="Y", boolean=True):
293+
if not readInput(message, default='Y', boolean=True):
294294
warnMsg += "usage of option '--union-char' "
295295
warnMsg += "(e.g. '--union-char=1') "
296296
else:

plugins/dbms/oracle/enumeration.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from lib.core.enums import EXPECTED
2222
from lib.core.enums import PAYLOAD
2323
from lib.core.exception import SqlmapNoneDataException
24+
from lib.core.settings import CURRENT_USER
2425
from lib.request import inject
2526
from plugins.generic.enumeration import Enumeration as GenericEnumeration
2627

@@ -30,7 +31,7 @@ def getRoles(self, query2=False):
3031

3132
rootQuery = queries[DBMS.ORACLE].roles
3233

33-
if conf.user == "CU":
34+
if conf.user == CURRENT_USER:
3435
infoMsg += " for current user"
3536
conf.user = self.getCurrentUser()
3637

@@ -55,7 +56,7 @@ def getRoles(self, query2=False):
5556
values = inject.getValue(query, blind=False, time=False)
5657

5758
if not values and not query2:
58-
infoMsg = "trying with table USER_ROLE_PRIVS"
59+
infoMsg = "trying with table 'USER_ROLE_PRIVS'"
5960
logger.info(infoMsg)
6061

6162
return self.getRoles(query2=True)
@@ -116,7 +117,7 @@ def getRoles(self, query2=False):
116117

117118
if not isNumPosStrValue(count):
118119
if count != 0 and not query2:
119-
infoMsg = "trying with table USER_SYS_PRIVS"
120+
infoMsg = "trying with table 'USER_SYS_PRIVS'"
120121
logger.info(infoMsg)
121122

122123
return self.getPrivileges(query2=True)

plugins/generic/users.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from lib.core.enums import PAYLOAD
4040
from lib.core.exception import SqlmapNoneDataException
4141
from lib.core.exception import SqlmapUserQuitException
42+
from lib.core.settings import CURRENT_USER
4243
from lib.core.threads import getCurrentThreadData
4344
from lib.request import inject
4445
from lib.utils.hash import attackCachedUsersPasswords
@@ -153,7 +154,7 @@ def getPasswordHashes(self):
153154

154155
rootQuery = queries[Backend.getIdentifiedDbms()].passwords
155156

156-
if conf.user == "CU":
157+
if conf.user == CURRENT_USER:
157158
infoMsg += " for current user"
158159
conf.user = self.getCurrentUser()
159160

@@ -362,7 +363,7 @@ def getPrivileges(self, query2=False):
362363

363364
rootQuery = queries[Backend.getIdentifiedDbms()].privileges
364365

365-
if conf.user == "CU":
366+
if conf.user == CURRENT_USER:
366367
infoMsg += " for current user"
367368
conf.user = self.getCurrentUser()
368369

@@ -410,7 +411,7 @@ def getPrivileges(self, query2=False):
410411
values = inject.getValue(query, blind=False, time=False)
411412

412413
if not values and Backend.isDbms(DBMS.ORACLE) and not query2:
413-
infoMsg = "trying with table USER_SYS_PRIVS"
414+
infoMsg = "trying with table 'USER_SYS_PRIVS'"
414415
logger.info(infoMsg)
415416

416417
return self.getPrivileges(query2=True)
@@ -446,7 +447,7 @@ def getPrivileges(self, query2=False):
446447
# In MySQL < 5.0 we get Y if the privilege is
447448
# True, N otherwise
448449
elif Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema:
449-
if privilege.upper() == "Y":
450+
if privilege.upper() == 'Y':
450451
privileges.add(MYSQL_PRIVS[count])
451452

452453
# In Firebird we get one letter for each privilege
@@ -465,7 +466,7 @@ def getPrivileges(self, query2=False):
465466
i = 1
466467

467468
for priv in privs:
468-
if priv.upper() in ("Y", "G"):
469+
if priv.upper() in ('Y', 'G'):
469470
for position, db2Priv in DB2_PRIVS.items():
470471
if position == i:
471472
privilege += ", " + db2Priv
@@ -525,7 +526,7 @@ def getPrivileges(self, query2=False):
525526

526527
if not isNumPosStrValue(count):
527528
if not retrievedUsers and Backend.isDbms(DBMS.ORACLE) and not query2:
528-
infoMsg = "trying with table USER_SYS_PRIVS"
529+
infoMsg = "trying with table 'USER_SYS_PRIVS'"
529530
logger.info(infoMsg)
530531

531532
return self.getPrivileges(query2=True)

thirdparty/identywaf/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright (c) 2019 Miroslav Stampar (@stamparm), MIT
4+
# See the file 'LICENSE' for copying permission
5+
6+
# The above copyright notice and this permission notice shall be included in
7+
# all copies or substantial portions of the Software.
8+
9+
pass

0 commit comments

Comments
 (0)