sqlmap/tamper/versionedmorekeywords.py

43 lines
1.2 KiB
Python
Raw Normal View History

2011-06-30 10:34:24 +04:00
#!/usr/bin/env python
"""
2011-06-30 11:55:07 +04:00
$Id$
2011-06-30 10:34:24 +04:00
Copyright (c) 2006-2011 sqlmap developers (http://sqlmap.sourceforge.net/)
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
from lib.core.common import randomRange
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
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
def tamper(payload):
"""
2011-06-30 11:52:13 +04:00
Encloses each keyword with versioned MySQL comment (MySQL >= 5.1.13)
2011-06-30 10:34:24 +04:00
Example: 'INSERT' will become '/*!INSERT*/'
"""
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()
2011-06-30 12:02:52 +04:00
singleTimeWarnMessage("tamper script '%s' is only meant to be run against MySQL >= 5.1.13" % os.path.basename(__file__))
2011-06-30 11:52:13 +04:00
2011-06-30 10:34:24 +04:00
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("*/ ", "*/")
return retVal