2010-10-14 18:05:05 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2010-10-14 18:41:14 +04:00
|
|
|
"""
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
|
|
|
|
See the file doc/COPYING for copying permission.
|
|
|
|
"""
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 18:27:35 +04:00
|
|
|
import re
|
|
|
|
|
|
|
|
from lib.core.convert import urldecode
|
|
|
|
from lib.core.convert import urlencode
|
|
|
|
|
|
|
|
"""
|
2010-10-14 10:20:32 +04:00
|
|
|
' ' -> /**/ (e.g., SELECT id FROM users->SELECT/**/id/**/FROM users)
|
2010-10-13 18:27:35 +04:00
|
|
|
"""
|
|
|
|
def tamper(place, value):
|
2010-10-14 15:06:28 +04:00
|
|
|
retVal = value
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 18:27:35 +04:00
|
|
|
if value:
|
|
|
|
if place != "URI":
|
|
|
|
value = urldecode(value)
|
2010-10-14 15:06:28 +04:00
|
|
|
|
|
|
|
retVal = ""
|
|
|
|
qoute, 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
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-14 15:06:28 +04:00
|
|
|
elif value[i] == '\'':
|
|
|
|
qoute = not qoute
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-14 15:06:28 +04:00
|
|
|
elif value[i] == '"':
|
|
|
|
doublequote = not doublequote
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-14 15:06:28 +04:00
|
|
|
elif value[i]==" " and not doublequote and not qoute:
|
|
|
|
retVal += "/**/"
|
|
|
|
continue
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-14 15:06:28 +04:00
|
|
|
retVal += value[i]
|
|
|
|
|
2010-10-13 18:27:35 +04:00
|
|
|
if place != "URI":
|
2010-10-14 15:06:28 +04:00
|
|
|
retVal = urlencode(retVal)
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-14 15:06:28 +04:00
|
|
|
return retVal
|
|
|
|
|