目录
PHP Code audit
http://xx.xxx.com/api/aaa/bbb?tableName=tb_users'
发现没有注入迹象!
代码审计后发现写过滤了特殊符号,因为输入的参数只能是数字和字母。
/**
* sql执行前 检测table是否规范 预判sql注入
* @param $tableName
*/
public function checkTable($tableName)
{
try {
if (!empty($tableName) && preg_replace( '/[^a-zA-Z0-9\_]/', '', $tableName)!=$tableName) {
Yii::log('检测表名不一致 '.$tableName , 'error');
return false;
}
} catch (Exception $e) {
Yii::log('检测表名异常', 'error');
}
}
思考有什么绕过的方式?
Think about bypass filtering
假设要绕过的字符是'
;
那么可以尝试如下转码方式,能避开匹配的规则,且对方转码之后也还能解析,那就完美绕过。
String to URL Code
'
String to Base64 Code
Jw==
String to JavaScript Escape Code
%27
String to ASCII Code
39
String to Binary Code
00100111
String to Octonary Code
\47
String to Octonary Code
\x27
String to HTML特殊字符编码
' = '
" = "
参考:https://www.jb51.net/onlineread/htmlchar.htm
常见绕过waf的操作
大小写绕过
and
改成如下形式:
And
aNd
ANd
...
双写绕过
and
改成如下形式:
anandd
andandandand
aaandnnddd
...
编码绕过
1' and 1=1
#转成URL-encode格式
%31%27%20%61%6E%64%20%31%3D%31
感谢大佬浮萍(https://fuping.site/)给我提供的工具。
或者御剑也能做转换:
全编码两次的作用:
如果上面的操作无效,是因为服务器会自动对URL进行一次URL编码,所以需要把关键字编码两次。
and
%61%6e%64
%25%36%31%25%36%65%25%36%34
步骤如下:
第一次编码:
第二次编码: