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/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2010-10-14 18:41:14 +04:00
|
|
|
"""
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 17:07:44 +04:00
|
|
|
from lib.core.convert import urldecode
|
|
|
|
from lib.core.convert import urlencode
|
|
|
|
|
2010-10-13 02:45:25 +04:00
|
|
|
def tamper(place, value):
|
2010-10-17 01:33:15 +04:00
|
|
|
"""
|
|
|
|
Replaces 'IFNULL(A, B)' with 'IF(ISNULL(A), B, A)'
|
|
|
|
Example: 'IFNULL(1, 2)' becomes 'IF(ISNULL(1), 2, 1)'
|
|
|
|
"""
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 17:07:44 +04:00
|
|
|
if value and value.find("IFNULL") > -1:
|
|
|
|
if place != "URI":
|
|
|
|
value = urldecode(value)
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 17:07:44 +04:00
|
|
|
while value.find("IFNULL(") > -1:
|
|
|
|
index = value.find("IFNULL(")
|
|
|
|
deepness = 1
|
|
|
|
comma, end = None, None
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 17:07:44 +04:00
|
|
|
for i in xrange(index + len("IFNULL("), len(value)):
|
|
|
|
if deepness == 1 and value[i] == ',':
|
|
|
|
comma = i
|
|
|
|
elif deepness == 1 and value[i] == ')':
|
|
|
|
end = i
|
|
|
|
break
|
|
|
|
elif value[i] == '(':
|
|
|
|
deepness += 1
|
|
|
|
elif value[i] == ')':
|
|
|
|
deepness -= 1
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 23:51:10 +04:00
|
|
|
if comma and end:
|
|
|
|
A = value[index + len("IFNULL("):comma]
|
|
|
|
B = value[comma + 1:end]
|
|
|
|
newVal = "IF(ISNULL(%s),%s,%s)" % (A, B, A)
|
|
|
|
value = value[:index] + newVal + value[end+1:]
|
|
|
|
else:
|
|
|
|
break
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 17:07:44 +04:00
|
|
|
if place != "URI":
|
|
|
|
value = urlencode(value)
|
2010-10-14 18:02:43 +04:00
|
|
|
|
2010-10-13 02:45:25 +04:00
|
|
|
return value
|