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
"""
2019-01-05 23:38:52 +03:00
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
2017-10-11 15:50:46 +03:00
See the file 'LICENSE' for copying permission
2011-06-09 16:14:14 +04:00
"""
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
"""
2018-07-31 02:17:11 +03: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()
2018-02-08 18:49:16 +03:00
for match in re.finditer(r"\b[A-Za-z_]+\b", payload):
2011-06-09 16:14:14 +04:00
word = match.group()
if word.upper() in kb.keywords:
words.add(word)
for word in words:
2018-06-10 00:38:00 +03:00
retVal = re.sub(r"(?<=\W)%s(?=[^A-Za-z_(]|\Z)" % word, "%s%s%s" % (' ' * random.randrange(1, 4), word, ' ' * random.randrange(1, 4)), retVal)
retVal = re.sub(r"(?<=\W)%s(?=[(])" % word, "%s%s" % (' ' * random.randrange(1, 4), word), retVal)
2011-06-09 16:14:14 +04:00
return retVal