Evading All Web-Application Firewalls Xss Filters: September 2015
Evading All Web-Application Firewalls Xss Filters: September 2015
Evading All Web-Application Firewalls Xss Filters: September 2015
SEPTEMBER 2015
MAZIN AHMED | MAZIN@MAZINAHMED.NET | @MAZEN160
Table of Contents
Topic
Page Number
Abstract
Introduction
Testing Environment
Products
Results
Vendor Responses
Conclusion
Acknowledgements
References
Page | 2
3
3
4
5
8
17
18
19
19
Mazin Ahmed
1. Abstract
Due to the increasing use of Web-Application Firewalls, I conducted a research on all wellknown Web-Application Firewalls to check their efficiency in protecting against cross-site scripting
attacks. The motive behind this research was to confirm that there is no effective way to protect
against a vulnerability other than fixing its root cause.
The tests were conducted against popular Web-Application Firewalls, such as F5 Big IP, Imperva
Incapsula, AQTRONIX WebKnight, PHP-IDS, Mod-Security, Sucuri, QuickDefense, Barracuda WAF, and
they were all evaded within the research.
2. Introduction
A web application firewall (WAF) is an appliance, server plugin, or filter that applies a set of
rules to an HTTP conversation. Usually, those rules protect against common threats, such as cross-site
scripting (XSS), SQL injection (SQLI), and other common web-application related vulnerabilities. In my
tests, I focused on finding methods to bypass WAFs protection against cross-site scripting
vulnerabilities.
"Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected
into otherwise benign and trusted web sites. XSS attacks occur when an attacker uses a web
application to send malicious code, generally in the form of a browser side script, to a different end
user. Flaws that allow these attacks to succeed are quite widespread and occur anywhere a web
application uses input from a user within the output it generates without validating or encoding it. An
attacker can use XSS to send a malicious script to an unsuspecting user. The end users browser has no
way to know that the script should not be trusted, and will execute the script. Because it thinks the
script came from a trusted source, the malicious script can access any cookies, session tokens, or
other sensitive information retained by the browser and used with that site"[1].
Page | 3
Mazin Ahmed
3. Testing Environment
The environment used in this research was based on several virtual machines that runs different
modern browsers. Due to the research motivation and goals I focused on the following web browsers:
Google Chrome
Opera Browser
Mozilla Firefox
Internet Explorer
Page | 4
Mazin Ahmed
4. Products
The research focused on the following Web-Application Firewalls.
4.2 Sucuri
"Sucuri is a company which offers a security service that detects unauthorized changes to
network (cloud) assets, including web sites, DNS, Whois records, SSL certificates and others. It is also
heavily used as an early warning system to detect malware, spam and other security issues on web
sites and DNS hijacking"[4]. It also protects against most common web-application vulnerabilities, such
as SQL injection, cross-site scripting, file inclusion attacks, and many other vulnerabilities.
4.3 ModSecurity
"ModSecurity is an open source, cross-platform web application firewall (WAF) module. Known as the
Swiss Army Knife of WAFs, it enables web application defenders to gain visibility into HTTP(S) traffic
and provides a power rules language and API to implement advanced protections"[5].
Page | 5
Mazin Ahmed
4.5 PHP-IDS
"PHPIDS (PHP Intrusion Detection System) is an open source PHP Web Application Intrusion
Detection System. It was written by Mario Heiderich, Christian Matthies, Lars H. Strojny and several
others in March 2007"[8].
"PHPIDS detects Cross-site scripting (XSS), SQL injection, header injection, and Directory
traversal, Remote File Execution, Local File Inclusion, and Denial of Service (DoS). It is simple to use
and well structured. It provides impact of every attack by analyzing any chosen input variables as
POST, GET, SESSION, COOKIE" [8].
PHP-IDS has a large rules set to prevent XSS attacks, and can be downloaded through the
project website, php-ids.org.
4.6 QuickDefense
"QuickDefense is an Nginx and Lua based easy to setup and configure web application firewall. It
allows users to write own rules in very simple language" [9].
Page | 6
Mazin Ahmed
Page | 7
Mazin Ahmed
5. Results
5.1 Imperva Incapsula
During tests, I noticed that Imperva Incapsula XSS filter protects against common XSS payloads. For
instance, the following payload is blacklisted. When an attacker inputs a common payload, such as
<script>alert(1)</script>, the request will be blocked.
<img/src="x"/onerror="alert(1)"> is also blocked. Meanwhile, <img src=x
onerror="input"> is not detected. The only obstacle to bypass the filter is to find action upon the
error. alert(), prompt(), confirm(), and eval() were all blocked, so an attacker would have to look for
other alternatives to create a proof of concept to show the existence of cross-site scripting
vulnerabilities.
The payload is unlimited to actions, but the only obstacle is its length. Most servers restrict the GET
request URL length. Therefore, the payload would work better if it worked on POST requests. Other
than that, the payload seems to be a perfect solution for evading Impervas Incapsula WAF.
Page | 8
Mazin Ahmed
5.2 WebKnight
WebKnight testing was quite different, as the rule set of WebKnight are updated frequently by the
information security community. The research identified two different bypasses that affects
WebKnight v4.1, and were patched on the release of WebKnight v4.2.
Page | 9
Mazin Ahmed
5.3 F5 Big IP
F5 Big IP known to be one of the most advanced enterprise-level web-application firewalls. The
discovered cross-site scripting evading techniques are not limited in actions. One of the discovered
bypasses works on all modern browsers, while the second one works on Firefox only.
Page | 10
Mazin Ahmed
Page | 11
Mazin Ahmed
Page | 12
Mazin Ahmed
5.5 PHP-IDS
PHP-IDS testing difficulties in the testing were different than most web-application firewalls. By
reviewing the filter's rule sets, it appeared that the rule sets does not blacklist JS events. Instead, PHPIDS main protection were on the actions of the JS event. For instance, alert() is instantly detected by
PHP-IDS. Also, all currently known encoding techniques are blocked too. Therefore, I had to take to
different path in the testing. Furthermore, it had certain protection against payload structure, that had
me to exploit few browser-behavior issues to bypass its protection protection.
The above payload is not being detected in PHP-IDS v0.7. Cross-site scripting attacks can be executed
using the same technique for different purposes.
Page | 13
Mazin Ahmed
5.6 Mod-Security
My research showed that Mod-Security is very sensitive to any malicious requests. For example,
hello%20onsomething=dosomething is marked as a potential cross-site scripting attack because
of the "onsomething" looks similar to JS events. Therefore, the tests focused on finding internal bugs
that can be used to evade Mod-Security XSS filter.
Page | 14
Mazin Ahmed
Page | 15
Mazin Ahmed
5.8.1 Bypass:
US-Encoding Bypass (Internet Explorer 6 & Internet Explorer 7)
The following payload is executed as a valid XSS payload against Internet Explorer 6 and Internet
Explorer 7 due to a bug in rendering US-encoding.
scriptalert(xss)/script
Page | 16
Mazin Ahmed
6. Vendor Responses:
6.1 F5
The findings has been reported to F5 security team, they have acknowledged the findings, and stated
that an update will be released on September 2015 to patch the issues.
6.2 WebKnight
AQTRONIX WebKnight team acknowledged the bypasses, and stated the issues will be patched in the
next release, v4.2.
6.3 PHP-IDS
All PHP-IDS developers has been contacted, but no response was heard from them.
6.5 Sucuri
Sucuri team has been contacted regarding the bypass, and they have patched the finding in less than
24 hours.
Page | 17
Mazin Ahmed
7. Conclusion
Based on the research I have done, it appears that every WAF can be bypassed by putting a
time and effort into finding its weaknesses. Every WAF has its own weaknesses that can be combined
to create an attack vector that has not been detected by the WAF.
Also, the best way of patching a security vulnerability is not by using a firewall, its by
investigating the root cause of the vulnerability and fixing it. Using web-application firewalls will not
protect from attacks and breaches, but it may force attackers to spend additional time in the
exploitation process.
The research tends to demonstrate that bypassing web-application firewalls is possible. While
trying to summarize the findings, not all discovered findings are included in this paper.
It appears that the difficulties in evading web-application firewalls slightly differs from a
product to another. For instance, some products took me five minutes to bypass them, while other
products took over forty-five minutes from me to bypass. In some occasions, bypasses didnt work on
every client-side environment for their products.
Page | 18
Mazin Ahmed
8. Acknowledgements:
I would like to thank the following individuals for their support:
Ahmed Abbas
Ayman Idris
John Stauffacher
Marcus Royce-Angel Peterson
Mario Heiderich
9. References:
1. https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
2. https://en.wikipedia.org/wiki/F5_Networks
3. https://www.f5.com/glossary/web-application-firewall/
4. https://en.wikipedia.org/wiki/Sucuri
5. https://www.modsecurity.org/about.html
6. https://en.wikipedia.org/wiki/Imperva
7. https://en.wikipedia.org/wiki/Incapsula
8. https://en.wikipedia.org/wiki/PHPIDS
9. http://sourceforge.net/projects/quickdefencewaf/
10. https://www.aqtronix.com/?PageID=99
11. https://en.wikipedia.org/wiki/Barracuda_Networks
12. https://www.barracuda.com/products/webapplicationfirewall/features
13. https://techlib.barracuda.com/waf/crosssitescriptingattack
Page | 19
Mazin Ahmed