Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dc2975

Browse files
committed
implemented first usable tamper module
1 parent 562df9c commit 2dc2975

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

tamper/ifnull2ifisnull.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
import re
22

3-
#not finished (watch for number of parenthesis)
4-
#IFNULL(A,B) -> IF(ISNULL(A),B,A)
3+
from lib.core.convert import urldecode
4+
from lib.core.convert import urlencode
5+
6+
"""
7+
Tampering IFNULL(A,B) -> IF(ISNULL(A),B,A)
8+
"""
59
def tamper(place, value):
6-
if value:
7-
if value.find("IFNULL") > -1:
8-
import pdb
9-
pdb.set_trace()
10-
value = re.sub(r"IFNULL(\(|%28)(?P<A>.+?)(,|%2C)(?P<B>.+?)(\)|%29)", lambda match: "IF%%28ISNULL%%28%s%%29%%2C%s%%2C%s%%29" % ("A="+match.group("A"), "B="+match.group("B"), "A="+match.group("A")), value)
10+
if value and value.find("IFNULL") > -1:
11+
if place != "URI":
12+
value = urldecode(value)
13+
#value = re.sub(r"IFNULL\(\({%d}(?P<A>.+?)\){%d},(?P<B>.+?)\)" % (num, num), lambda match: "IF(ISNULL(%s),%s,%s)" % (match.group("A"), match.group("B"), match.group("A")), value)
14+
while value.find("IFNULL(") > -1:
15+
index = value.find("IFNULL(")
16+
deepness = 1
17+
comma, end = None, None
18+
for i in xrange(index + len("IFNULL("), len(value)):
19+
if deepness == 1 and value[i] == ',':
20+
comma = i
21+
elif deepness == 1 and value[i] == ')':
22+
end = i
23+
break
24+
elif value[i] == '(':
25+
deepness += 1
26+
elif value[i] == ')':
27+
deepness -= 1
28+
A = value[index + len("IFNULL("):comma]
29+
B = value[comma + 1:end]
30+
newVal = "IF(ISNULL(%s),%s,%s)" % (A, B, A)
31+
value = value[:index] + newVal + value[end+1:]
32+
if place != "URI":
33+
value = urlencode(value)
1134
return value

0 commit comments

Comments
 (0)