@ -7,6 +7,7 @@ See the file 'LICENSE' for copying permission
import re
# 从sqlmap的库中导入随机范围函数、兼容模块中的xrange函数、知识库和优先级枚举
from lib . core . common import randomRange
from lib . core . compat import xrange
from lib . core . data import kb
@ -27,24 +28,28 @@ def tamper(payload, **kwargs):
retVal = payload
if payload :
# 使用正则表达式找到payload中的所有单词( 至少一个字母或下划线)
for match in re . finditer ( r " \ b[A-Za-z_]+ \ b " , payload ) :
word = match . group ( )
# 跳过长度小于2的单词
if len ( word ) < 2 :
continue
# 如果单词是SQL关键字
if word . upper ( ) in kb . keywords :
_ = word [ 0 ]
_ = word [ 0 ] # 从单词的第一个字符开始构造新的字符串
# 遍历单词的每个字符(除了第一个和最后一个)
for i in xrange ( 1 , len ( word ) - 1 ) :
# 随机决定是否插入注释
_ + = " %s %s " % ( " /**/ " if randomRange ( 0 , 1 ) else " " , word [ i ] )
# 添加单词的最后一个字符
_ + = word [ - 1 ]
# 如果没有插入任何注释,则随机选择一个位置插入注释
if " /**/ " not in _ :
index = randomRange ( 1 , len ( word ) - 1 )
_ = word [ : index ] + " /**/ " + word [ index : ]
# 将原始的单词替换为插入了注释的新字符串
retVal = retVal . replace ( word , _ )
return retVal