sqlmap/tamper/chardoubleencode.py

47 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python2
"""
2013-01-18 18:07:51 +04:00
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
import string
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW
def dependencies():
pass
2012-12-03 17:27:01 +04:00
def tamper(payload, **kwargs):
"""
Double url-encodes all characters in a given payload (not processing
already encoded)
Example:
* Input: SELECT FIELD FROM%20TABLE
* Output: %2553%2545%254c%2545%2543%2554%2520%2546%2549%2545%254c%2544%2520%2546%2552%254f%254d%2520%2554%2541%2542%254c%2545
Notes:
* Useful to bypass some weak web application firewalls that do not
double url-decode the request before processing it through their
ruleset
"""
retVal = payload
if payload:
retVal = ""
i = 0
while i < len(payload):
2013-01-10 16:18:44 +04:00
if payload[i] == '%' and (i < len(payload) - 2) and payload[i + 1:i + 2] in string.hexdigits and payload[i + 2:i + 3] in string.hexdigits:
retVal += payload[i:i + 3]
i += 3
else:
2012-07-24 03:21:32 +04:00
retVal += '%%25%.2X' % ord(payload[i])
i += 1
return retVal