sqlmap/tamper/space2comment.py

52 lines
1.2 KiB
Python
Raw Normal View History

2010-10-14 18:05:05 +04:00
#!/usr/bin/env python
"""
$Id$
Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
2010-10-15 03:18:29 +04:00
See the file 'doc/COPYING' for copying permission
"""
2010-10-13 18:27:35 +04:00
from lib.core.convert import urldecode
from lib.core.convert import urlencode
def tamper(place, value):
"""
Replaces ' ' with '/**/'
Example: 'SELECT id FROM users' becomes 'SELECT/**/id/**/FROM users'
"""
retVal = value
2010-10-13 18:27:35 +04:00
if value:
if place != "URI":
value = urldecode(value)
retVal = ""
quote, doublequote, firstspace = False, False, False
for i in xrange(len(value)):
if not firstspace:
2010-10-14 15:12:03 +04:00
if value[i].isspace():
firstspace = True
retVal += "/**/"
continue
elif value[i] == '\'':
quote = not quote
elif value[i] == '"':
doublequote = not doublequote
elif value[i]==" " and not doublequote and not quote:
retVal += "/**/"
continue
retVal += value[i]
2010-10-13 18:27:35 +04:00
if place != "URI":
retVal = urlencode(retVal)
return retVal