Tamper function(s) refactoring (really no need for returning headers as they are passed by reference)

This commit is contained in:
Miroslav Stampar 2012-10-25 10:10:23 +02:00
parent 54fbb22ab8
commit 12fc9442b9
36 changed files with 70 additions and 72 deletions

View File

@ -48,7 +48,7 @@ class Agent:
if kb.tamperFunctions:
for function in kb.tamperFunctions:
query, _ = function(payload=query, headers=None)
query = function(payload=query)
return query

View File

@ -587,7 +587,7 @@ class Connect:
if payload:
if kb.tamperFunctions:
for function in kb.tamperFunctions:
payload, auxHeaders = function(payload=payload, headers=auxHeaders)
payload = function(payload=payload, headers=auxHeaders)
value = agent.replacePayload(value, payload)

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.LOWEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces apostrophe character with its UTF-8 full width counterpart
@ -27,4 +27,4 @@ def tamper(payload, headers):
* http://lukasz.pilorz.net/testy/full_width_utf/index.phps
"""
return payload.replace('\'', "%EF%BC%87") if payload else payload, headers
return payload.replace('\'', "%EF%BC%87") if payload else payload

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.LOWEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces apostrophe character with its illegal double unicode counterpart
@ -21,4 +21,4 @@ def tamper(payload, headers):
* Output: AND %00%271%00%27=%00%271%00%27
"""
return payload.replace('\'', "%00%27") if payload else payload, headers
return payload.replace('\'', "%00%27") if payload else payload

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.LOWEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Appends encoded NULL byte character at the end of payload
@ -31,4 +31,4 @@ def tamper(payload, headers):
Reference: http://projects.webappsec.org/w/page/13246949/Null-Byte-Injection
"""
return "%s%%00" % payload if payload else payload, headers
return "%s%%00" % payload if payload else payload

View File

@ -14,7 +14,7 @@ __priority__ = PRIORITY.LOWEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Base64 all characters in a given payload
@ -23,4 +23,4 @@ def tamper(payload, headers):
* Output: MScgQU5EIFNMRUVQKDUpIw==
"""
return base64.b64encode(payload) if payload else payload, headers
return base64.b64encode(payload) if payload else payload

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.HIGHEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces greater than operator ('>') with 'NOT BETWEEN 0 AND #'
@ -61,4 +61,4 @@ def tamper(payload, headers):
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -14,7 +14,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Double url-encodes all characters in a given payload (not processing
already encoded)
@ -43,4 +43,4 @@ def tamper(payload, headers):
retVal += '%%25%.2X' % ord(payload[i])
i += 1
return retVal, headers
return retVal

View File

@ -14,7 +14,7 @@ __priority__ = PRIORITY.LOWEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Url-encodes all characters in a given payload (not processing already
encoded)
@ -50,4 +50,4 @@ def tamper(payload, headers):
retVal += '%%%.2X' % ord(payload[i])
i += 1
return retVal, headers
return retVal

View File

@ -16,7 +16,7 @@ __priority__ = PRIORITY.LOWEST
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against ASP or ASP.NET web applications" % os.path.basename(__file__).split(".")[0])
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Unicode-url-encodes non-encoded characters in a given payload (not
processing already encoded)
@ -55,4 +55,4 @@ def tamper(payload, headers):
retVal += '%%u%.4X' % ord(payload[i])
i += 1
return retVal, headers
return retVal

View File

@ -17,7 +17,7 @@ __priority__ = PRIORITY.HIGHEST
def dependencies():
singleTimeWarnMessage("tamper script '%s' is unlikely to work against %s" % (os.path.basename(__file__).split(".")[0], DBMS.PGSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces all occurances of operator equal ('=') with operator 'LIKE'
@ -47,4 +47,4 @@ def tamper(payload, headers):
if payload:
retVal = re.sub(r"\s*=\s*", lambda match: process(match), retVal)
return retVal, headers
return retVal

View File

@ -1,8 +1,6 @@
#!/usr/bin/env python
"""
$Id$
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
@ -21,7 +19,7 @@ __priority__ = PRIORITY.HIGHER
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s < 5.1" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Adds versioned MySQL comment before each keyword
@ -55,4 +53,4 @@ def tamper(payload, headers):
retVal = re.sub(r"(?<=\W)(?P<word>[A-Za-z_]+)(?=\W|\Z)", lambda match: process(match), retVal)
retVal = retVal.replace(" /*!0", "/*!0")
return retVal, headers
return retVal

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.HIGHEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces instances like 'IFNULL(A, B)' with 'IF(ISNULL(A), B, A)'
@ -61,4 +61,4 @@ def tamper(payload, headers):
else:
break
return payload, headers
return payload

View File

@ -13,7 +13,7 @@ __priority__ = PRIORITY.HIGHER
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Embraces complete query with versioned comment
@ -43,4 +43,4 @@ def tamper(payload, headers):
if ' ' in payload:
retVal = "%s /*!30%s%s*/%s" % (payload[:payload.find(' ')], randomInt(3), payload[payload.find(' ') + 1:], postfix)
return retVal, headers
return retVal

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.HIGHER
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Embraces complete query with zero-versioned comment
@ -42,4 +42,4 @@ def tamper(payload, headers):
if ' ' in payload:
retVal = "%s /*!00000%s*/%s" % (payload[:payload.find(' ')], payload[payload.find(' ') + 1:], postfix)
return retVal, headers
return retVal

View File

@ -16,7 +16,7 @@ __priority__ = PRIORITY.NORMAL
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Adds multiple spaces around SQL keywords
@ -46,4 +46,4 @@ def tamper(payload, headers):
retVal = re.sub("(?<=\W)%s(?=[^A-Za-z_(]|\Z)" % word, "%s%s%s" % (' '*random.randrange(1,4), word, ' '*random.randrange(1,4)), retVal)
retVal = re.sub("(?<=\W)%s(?=[(])" % word, "%s%s" % (' '*random.randrange(1,4), word), retVal)
return retVal, headers
return retVal

View File

@ -13,7 +13,7 @@ from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces predefined SQL keywords with representations
suitable for replacement (e.g. .replace("SELECT", "")) filters
@ -38,4 +38,4 @@ def tamper(payload, headers):
_ = random.randint(1, len(keyword) - 1)
retVal = re.sub(r"(?i)\b%s\b" % keyword, "%s%s%s" % (keyword[:_], keyword, keyword[_:]), retVal)
return retVal, headers
return retVal

View File

@ -16,7 +16,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against ASP web applications" % os.path.basename(__file__).split(".")[0])
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Adds a percentage sign ('%') infront of each character
@ -51,4 +51,4 @@ def tamper(payload, headers):
retVal += payload[i]
i += 1
return retVal, headers
return retVal

View File

@ -16,7 +16,7 @@ __priority__ = PRIORITY.NORMAL
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces each keyword character with random case value
@ -50,4 +50,4 @@ def tamper(payload, headers):
retVal = retVal.replace(word, _)
return retVal, headers
return retVal

View File

@ -13,7 +13,7 @@ from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Add random comments to SQL keywords
Example: 'INSERT' becomes 'IN/**/S/**/ERT'
@ -37,4 +37,4 @@ def tamper(payload, headers):
_ += word[-1]
retVal = retVal.replace(word, _)
return retVal, headers
return retVal

View File

@ -14,7 +14,7 @@ __priority__ = PRIORITY.NORMAL
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Appends special crafted string
@ -27,4 +27,4 @@ def tamper(payload, headers):
* Reference: http://seclists.org/fulldisclosure/2011/May/163
"""
return payload + " and '0having'='0having'" if payload else payload, headers
return payload + " and '0having'='0having'" if payload else payload

View File

@ -9,7 +9,7 @@ from lib.core.enums import PRIORITY
__priority__ = PRIORITY.HIGH
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Appends 'sp_password' to the end of the payload for automatic obfuscation from DBMS logs
@ -30,4 +30,4 @@ def tamper(payload, headers):
if payload:
retVal = "%s%ssp_password" % (payload, "-- " if not any(_ if _ in payload else None for _ in ('#', "-- ")) else "")
return retVal, headers
return retVal

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with comments '/**/'
@ -55,4 +55,4 @@ def tamper(payload, headers):
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -12,7 +12,7 @@ from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a dash comment ('--') followed by
a random string and a new line ('\n')
@ -46,4 +46,4 @@ def tamper(payload, headers):
else:
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -18,7 +18,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a pound character ('#') followed by
a random string and a new line ('\n')
@ -52,4 +52,4 @@ def tamper(payload, headers):
else:
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -21,7 +21,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s > 5.1.13" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a pound character ('#') followed by
a random string and a new line ('\n')
@ -66,4 +66,4 @@ def tamper(payload, headers):
else:
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -17,7 +17,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MSSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a random blank character from a
valid set of alternate characters
@ -86,4 +86,4 @@ def tamper(payload, headers):
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -9,7 +9,7 @@ from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a pound character ('#') followed by
a new line ('\n')
@ -38,4 +38,4 @@ def tamper(payload, headers):
else:
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -17,7 +17,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a random blank character from a
valid set of alternate characters
@ -69,4 +69,4 @@ def tamper(payload, headers):
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -16,7 +16,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a dash comment ('--') followed by
a new line ('\n')
@ -47,4 +47,4 @@ def tamper(payload, headers):
else:
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -12,7 +12,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with plus ('+')
@ -51,4 +51,4 @@ def tamper(payload, headers):
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -14,7 +14,7 @@ __priority__ = PRIORITY.LOW
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces space character (' ') with a random blank character from a
valid set of alternate characters
@ -64,4 +64,4 @@ def tamper(payload, headers):
retVal += payload[i]
return retVal, headers
return retVal

View File

@ -14,7 +14,7 @@ __priority__ = PRIORITY.HIGHEST
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces UNION ALL SELECT with UNION SELECT
@ -23,4 +23,4 @@ def tamper(payload, headers):
* Output: -1 UNION SELECT
"""
return payload.replace("UNION ALL SELECT", "UNION SELECT") if payload else payload, headers
return payload.replace("UNION ALL SELECT", "UNION SELECT") if payload else payload

View File

@ -14,7 +14,7 @@ __priority__ = PRIORITY.NORMAL
def dependencies():
pass
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Replaces quote character (') with a multi-byte combo %bf%27 together with
generic comment at the end (to make it work)
@ -48,4 +48,4 @@ def tamper(payload, headers):
retVal = re.sub("\s*(AND|OR)[\s(]+'[^']+'\s*(=|LIKE)\s*'.*", "", retVal)
retVal += "-- "
return retVal, headers
return retVal

View File

@ -18,7 +18,7 @@ __priority__ = PRIORITY.HIGHER
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Encloses each non-function keyword with versioned MySQL comment
@ -50,4 +50,4 @@ def tamper(payload, headers):
retVal = re.sub(r"(?<=\W)(?P<word>[A-Za-z_]+)(?=[^\w(]|\Z)", lambda match: process(match), retVal)
retVal = retVal.replace(" /*!", "/*!").replace("*/ ", "*/")
return retVal, headers
return retVal

View File

@ -19,7 +19,7 @@ __priority__ = PRIORITY.HIGHER
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s >= 5.1.13" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, headers):
def tamper(payload, headers=None):
"""
Encloses each keyword with versioned MySQL comment
@ -51,4 +51,4 @@ def tamper(payload, headers):
retVal = re.sub(r"(?<=\W)(?P<word>[A-Za-z_]+)(?=\W|\Z)", lambda match: process(match), retVal)
retVal = retVal.replace(" /*!", "/*!").replace("*/ ", "*/")
return retVal, headers
return retVal