sqlmap/tamper/multiplespaces.py

50 lines
1.2 KiB
Python
Raw Normal View History

#!/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
def dependencies():
pass
2012-12-03 17:27:01 +04:00
def tamper(payload, **kwargs):
2011-06-09 16:14:14 +04:00
"""
Adds multiple spaces around SQL keywords
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
>>> random.seed(0)
>>> tamper('1 UNION SELECT foobar')
'1 UNION SELECT foobar'
2011-06-09 16:14:14 +04:00
"""
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
return retVal