2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2011-06-09 16:14:14 +04:00
|
|
|
|
|
|
|
"""
|
2013-01-18 18:07:51 +04:00
|
|
|
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
|
2011-06-09 16:14:14 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
|
|
|
import random
|
|
|
|
import re
|
|
|
|
|
|
|
|
from lib.core.data import kb
|
|
|
|
from lib.core.enums import PRIORITY
|
|
|
|
|
|
|
|
__priority__ = PRIORITY.NORMAL
|
|
|
|
|
2011-07-07 01:04:45 +04:00
|
|
|
def dependencies():
|
|
|
|
pass
|
|
|
|
|
2012-12-03 17:27:01 +04:00
|
|
|
def tamper(payload, **kwargs):
|
2011-06-09 16:14:14 +04:00
|
|
|
"""
|
2011-07-07 01:04:45 +04:00
|
|
|
Adds multiple spaces around SQL keywords
|
|
|
|
|
|
|
|
Example:
|
|
|
|
* Input: UNION SELECT
|
2013-01-04 02:57:07 +04:00
|
|
|
* Output: UNION SELECT
|
2011-07-07 01:04:45 +04:00
|
|
|
|
|
|
|
Notes:
|
|
|
|
* Useful to bypass very weak and bespoke web application firewalls
|
|
|
|
that has poorly written permissive regular expressions
|
|
|
|
|
2011-06-09 16:14:14 +04:00
|
|
|
Reference: https://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt
|
|
|
|
"""
|
|
|
|
|
|
|
|
retVal = payload
|
|
|
|
|
|
|
|
if payload:
|
|
|
|
words = set()
|
|
|
|
|
|
|
|
for match in re.finditer(r"[A-Za-z_]+", payload):
|
|
|
|
word = match.group()
|
|
|
|
|
|
|
|
if word.upper() in kb.keywords:
|
|
|
|
words.add(word)
|
|
|
|
|
|
|
|
for word in words:
|
2013-01-10 16:18:44 +04:00
|
|
|
retVal = re.sub("(?<=\W)%s(?=[^A-Za-z_(]|\Z)" % word, "%s%s%s" % (' ' * random.randrange(1, 4), word, ' ' * random.randrange(1, 4)), retVal)
|
|
|
|
retVal = re.sub("(?<=\W)%s(?=[(])" % word, "%s%s" % (' ' * random.randrange(1, 4), word), retVal)
|
2011-06-09 16:14:14 +04:00
|
|
|
|
2012-10-25 12:10:23 +04:00
|
|
|
return retVal
|