在进行指纹识别之前,了解Web应用程序防火墙 (WAF) 通常在网络中的部署位置,对于攻击者来说至关重要。
渗透测试人员在开始对Web应用进行测试前,务必了解WAF的存在,因为这可能会直接影响他们的攻击成果。
但在此之前…
什么是WAF?
WAF(Web应用程序防火墙)在网站安全领域扮演着至关重要的角色。它们的主要功能是对网络流量进行过滤和监控。Web应用程序防火墙能够有效地防御各种常见的安全漏洞。 许多组织都在积极更新其基础架构,将Web应用程序防火墙纳入其中。不过,根据网络安全专家的观点,Web应用程序防火墙本身并不能完全解决安全问题,还需要进行细致的配置,才能准确地识别并阻止外部威胁。
WAF与传统防火墙的区别在于,WAF能够针对特定的在线应用程序内容进行过滤,而传统防火墙主要作为服务器之间的安全屏障。
HTTP交互行为受到一系列规则的约束。 这些规则旨在解决跨站脚本和SQL注入等常见的安全漏洞。
互联网上存在众多免费和开源工具,可以帮助我们识别Web应用程序背后的防火墙。
本文将深入探讨用于检测WAF的方法和工具。
请注意:在本教程中,我使用了我自己的网站作为示例进行说明。在未经所有者明确许可的情况下,请勿在任何网站上进行扫描或其他黑客活动。
手动发现
使用TELNET检测
Telnet 远程登录主要由网络管理员和渗透测试人员使用。Telnet 允许通过任意端口连接到远程主机。
- Web应用程序防火墙通常会将HTTP参数保留或插入在响应头中。
- Telnet 可用于获取基本信息,例如服务器和cookie,这些信息可用于指纹识别。
- 输入命令:
telnet Targetwebsite.com 80
[email protected]: # telnet Targetwebsite.com 80 Trying 18.166.248.208... Connected to Targetwebsite.com. Escape character is '^]'.
执行上述命令后,输入HEAD / HTTP / 1.1
并按下回车键。
[email protected]: # telnet 18.166.248.208 80 Trying 18.166.248.208... Connected to 18.166.248.208. Escape character is '^]'. HEAD / HTTP/1.1 Host: 18.166.248.208 HTTP/1.1 200 OK Date: SUN, 10 Oct 2021 05:08:03 IST Server: Apache X-Powered-By: PHP/5.3.5 ZendServer/5.0 Set-Cookie: SESSIONID VULN SITE=t25put8gliicvqf62u3ctgjm21; path=/ Expires: Thu, 19 Nov 1981 08:52:00 IST Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Varnish: 4723782781 Age: 0 Via: 1.1 varnish Connection: close Content-Type: text/html Connection closed by foreign host.
这表明了网站所在的服务器,以及使用telnet连接到目标端口80后,网站后端所采用的编程语言。
一些WAF系统允许修改标头,并且它们可能导致Web服务器发送与标准不同的HTTP响应。
正如上面的结果所示,Web服务器响应了我们的请求,并显示防火墙/边缘网关是Varnish。
自动发现
#1. 使用NMAP检测
Nmap提供了一个脚本,可以用来识别Web应用程序防火墙,并能用于此目的。
- Nmap是众多渗透测试人员和网络管理员常用的安全评估工具。
- Nmap常被用于收集关于目标的信息。
- 该脚本针对之前相同的网页运行。
- 输入命令:
nmap --script=http-waf-fingerprint targetweb.com
[email protected]:# nmap --script=http-waf-fingerprint targetwebsite.com Starting Nmap 7.90 ( https://nmap.org ) at 2021-10-10 07:58 IST Nmap scan report for targetsite.com (18.166.248.208) Host is up (0.24s latency). Not shown: 982filtered ports PORT STATE SERVICE 53/tcp open domain 80/tcp open http | http-waf-fingerprint: | Detected WAF | Citrix Netscaler 443/tcp open https 5432/tcp closed postgresql 8080/tcp closed http-proxy Nmap done: 1 IP address (1 host up) scanned in 25.46 seconds
执行上述Nmap命令后,检测到了Citrix Netscaler防火墙。
#2. 使用WhatWaf进行检测
WhatWaf 是一种安全工具,主要用于对Web应用程序进行指纹识别,并检测任何WAF的存在。此工具可以帮助我们在安全评估过程中确定Web应用程序是否受到了WAF的保护。
如果确定有WAF保护,绕过和规避策略可能有助于进一步测试或利用在线应用程序的漏洞。
防火墙绕过、应用程序检测、应用程序指纹识别和软件识别都是WhatWaf的常见用途。网络渗透测试人员和安全专业人员是该程序的目标用户。
如何安装WhatWaf?
在Kali-Linux上安装:
sudo apt install python3-pip git clone https://github.com/ekultek/whatwaf cd whatwaf sudo pip3 install -r requirements.txt
在启动时,如果我们没有配置Python版本,可以指定一个可执行文件:
./whatwaf --help
但是,由于我们可能没有安装Python 2的依赖项,建议明确指定Python版本:
python3 ./whatwaf --help
工具使用
WhatWaf防火墙检测工具非常易于使用!我们只需要执行以下命令:
./whatwaf -u https://www.targetsite.com
如下所示,该工具检测到了指定网站URL的防火墙。
提醒! – 我使用自己的网站进行扫描。
┌──(root💀kali)-[/home/writer/WhatWaf] └─# ./whatwaf -u https://www.renjith.org ,------. ' .--. ' ,--. .--. ,--. .--.| | | | | | | | | | | |'--' | | | | | | | | | | __. | | |.'.| | | |.'.| | | .' | | | | |___| | ,'. |hat| ,'. |af .---. '--' '--' '--' '--' '---' /><script>alert("WhatWaf?<|>v2.0.3($dev)");</script>%00 [11:12:34][ERROR] you must install psutil first `pip install psutil` to start mining XMR [11:12:34][INFO] checking for updates [11:12:34][WARN] it is highly advised to use a proxy when using WhatWaf. do so by passing the proxy flag (IE `--proxy http://127.0.0.1:9050`) or by passing the Tor flag (IE `--tor`) [11:12:34][INFO] using User-Agent 'whatwaf/2.0.3 (Language=2.7.18; Platform=Linux)' [11:12:34][INFO] using default payloads [11:12:34][INFO] testing connection to target URL before starting attack [11:12:35][SUCCESS] connection succeeded, continuing [11:12:35][INFO] running single web application 'https://www.renjith.org' [11:12:35][WARN] URL does not appear to have a query (parameter), this may interfere with the detection results [11:12:35][INFO] request type: GET [11:12:35][INFO] gathering HTTP responses [11:12:42][INFO] gathering normal response to compare against [11:12:42][INFO] loading firewall detection scripts [11:12:42][INFO] running firewall detection checks [11:12:44][FIREWALL] detected website protection identified as 'Apache Generic' [11:12:44][INFO] starting bypass analysis [11:12:44][INFO] loading payload tampering scripts [11:12:45][INFO] running tampering bypass checks [11:19:09][SUCCESS] apparent working tampers for target: ------------------------------ (#1) description: tamper payload by changing characters into a wildcard example: '/bin/cat /et?/?asswd' load path: content.tampers.randomwildcard ------------------------------
正如上述结果所示,Web服务器响应了我们的请求,并显示该网站的防火墙是Apache。我们也可以使用tor服务来扫描WAF,但这可能会增加延迟。
./whatwaf -u https://www.targetsite.com --tor
WhatWaf工具的主要优点是,它会自动尝试让有效负载绕过暴露的防火墙。
#3. 使用Wafw00f检测
用于检测Web应用程序防火墙的最著名工具之一是Wafw00f。 Wafw00f通过向Web应用程序防火墙发送HTTP请求来识别它。 当发送HTTP请求失败时,wafw00f会发出恶意HTTP请求。 如果发出恶意HTTP请求失败,wafw00f会检查之前的HTTP请求,并使用简单的算法来确定Web应用程序防火墙是否对我们的攻击做出了反应。
Kali Linux发行版中默认没有预装Wafw00f。
如何安装Wafw00f?
可以从官方GitHub源下载zip包。
下载Wafwoof工具。您还可以使用git客户端克隆存储库。要获取包,请运行以下命令:
$ git clone https://github.com/EnableSecurity/wafw00f.git
要在系统中下载wafw00f工具,请导航到wafw00f文件夹或目录,并执行以下命令。
$ python setup.py install
这将处理设置文件,并将wafw00f安装到系统中。
工具使用
要使用此工具,请运行以下命令:
$ wafw00f <url>
提醒 – 仅扫描您被允许测试的网站。
┌──(root💀kali)-[/home/writer/wafw00f] └─# wafw00f https://webhashes.com ______ / ( Woof! ) ____/ ) ,, ) (_ .-. - _______ ( |__| ()``; |==|_______) .)|__| / (' /| ( |__| ( / ) / | . |__| (_)_)) / | |__| ~ WAFW00F : v2.1.0 ~ The Web Application Firewall Fingerprinting Toolkit [*] Checking https://whatismyip.com [+] The site https://whatismyip.com is behind Cloudflare (Cloudflare Inc.) WAF. [~] Number of requests : 2
糟了,防火墙被检测到了!
我们将尝试不同的目标网站进行讨论。
┌──(root💀kali)-[/home/writer/wafw00f] └─# wafw00f https://renjith.org ______ / ( Woof! ) ____/ ) ,, ) (_ .-. - _______ ( |__| ()``; |==|_______) .)|__| / (' /| ( |__| ( / ) / | . |__| (_)_)) / | |__| ~ WAFW00F : v2.1.0 ~ The Web Application Firewall Fingerprinting Toolkit [*] Checking https://renjith.org [+] Generic Detection results: [-] No WAF detected by the generic detection [~] Number of requests: 7
这一次没有检测到防火墙。
要在详细模式下使用它,请运行以下命令:
wafw00f <url> -v
您可以通过执行以下命令查看此实用程序的一些附加功能:
wafw00f <url> --help
总结👨💻
本文探讨了用于检测Web应用程序防火墙的不同策略和工具。这是在每次Web应用程序渗透测试的信息收集阶段都必须执行的一项重要操作。
此外,了解WAF的存在后,渗透测试人员可以尝试各种方法来绕过防御,并利用在线应用程序中的任何漏洞。
根据网络安全专家的说法,Web应用程序防火墙(WAF)的需求日益增长。始终要分析Web应用程序日志,以便检测后端Web应用程序服务器上的新型攻击,这一点至关重要。这使您可以在Web应用程序防火墙中自定义规则,以提供最高级别的保护。
您可能还会对以下内容感兴趣:使用Nikto扫描器进行漏洞扫描。