sqlmap/tamper/versionedkeywords.py

38 lines
910 B
Python
Raw Normal View History

2011-05-28 19:42:47 +04:00
#!/usr/bin/env python
"""
$Id$
Copyright (c) 2006-2011 sqlmap developers (http://sqlmap.sourceforge.net/)
See the file 'doc/COPYING' for copying permission
"""
import re
from lib.core.common import randomRange
from lib.core.data import kb
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 tamper(payload):
"""
2011-06-30 11:52:13 +04:00
Encloses each non-function keyword with versioned MySQL comment
2011-05-28 19:42:47 +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:
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