XSS Filter Evasion
Bypass blacklisting Filters, sanitization and Browser Filters
Filter Evasion and WAF Bypassing
Common scenarios
The XSS vector is blocked by the application or something else
The XSS vector is sanitized
The XSS vector is filtered or blocked by the browser
Bypassing Blackliting Filters
Its the most common. Their goal is to detect specific patterns and prevent malicious behaviors.
Inject Script Code
Bypassing Weak script Tag Banning
ModSecurity > Script Tag Based XSS Vectors Rule
There are several alternatives in which its possible to run our code, such as different HTML tags and related event handlers.
Beyond script Tag… Using HTML Attributes
Beyond script Tag… Using HTML Events
Events are they way that HTML DOM adds interactivity between the website and its visitors; This happens simply by executing the client-side code (e.g, JavaScript)
Almost all event handler identifier start with on and are followerd by the name of the event. One of the most used is onerror:
Examples:
From a defensive point of view, the solution is to filter all the events that start with on in order to block this injection point.
This is a very common regex you might find used widely:
So, we have an Upgrade:
However, Some browsers convert the control character to a space, thus the \s meta-character is not enough to cover all possible chars.
We can bypass that too:
Browsers are in continuous evolution; Therefore, some of the chars allowed may not work anymore. So, Shazzer Fuzz DB has created two fuzzer tests:
→ http://shazzer.co.uk/vector/Characters-allowed-after-attribute-name
→ http://shazzer.co.uk/vector/Characters-allowed-before-attribute-name
To data, a valid regex rule should be the following:
Keyword Based Filters
There are filters focused on preventing scripting mode such as alert, javascript, eval
Char Escaping
Here we see Unicode Escaping without using native functions:
Unicode escaping using native functions. Eval is just one of many:
IF the filtered vector is within a string, in addition to Unicode, there are multiple escapses we may adopt:
Contructing String
Javascript jas several functions useful to create string:
Execution Sinks
Technically, functions that parse string as JavaScript code are called execution sinks, and JavaScript offers several alternatives.
Some Sinks:
Variation of the Function sink:
Pseudo-protocols
javascript: is an unofficional URI scheme, commonly referred as a pseudo-protocol.
javascript followerd by (:) is usually blocked
Example:
Bypass examples:
In addition to javascript:, there are also data: and the IE exclusive vbscript:
Data URI scheme:
If javascript: is blocked:
If data: is blocked:
The vbscript pseudo-protocol is not so common, because it can only be used with IE.
From IE11 in Edge, vbscript is no longer supported.
How to use vbscript:
Bypass vbscript:
Tool to obfuscate:
Bypassing Sanitization
The most common is to HTML-encode such as:
String Manipulations
Example:
Removing HTML tags
The check is not performed recursively:
If the filter performs recursive checks, we can still bypass. maybe changing the order of injected strings.
it all depends on the filter that we are facing
→ moreover: https://els-cdn.content-api.ine.com/eda3ac9d-554a-469a-98c6-639c90f0c7a5/index.html#
Escaping Quotes\
Filters place the backslash char ** before quotes to escape that kind of character
Example:
One of useful Javascript methods is:
It allows us to generate strings starting from a sequence of Unicode values:
Using unescape method:
Using decodeURI and decodeURIComponent:
These methods could be useful if you can inject into a script or event handler. nut you cannot use quotation marks because they are properly escaped.
Dont forget that each of them will return a string, so you need an execution sink to trigger the code (IE: eval)
Escaping Parentheses
The technique abuses the onerror handler, assigning a function to call once an error has been generated using throw followed by the arguments to the function assigned to the error handler.
→ moreover: http://www.thespanner.co.uk/2012/05/01/xss-technique-without-parentheses/
And since the arguments section is quoted, its possible to do some encoding like the following:
They dont cover all possible XSS attacl scenarios and they focus on Reflected type of XSS.
Injecting inside HTML Tag Attributes:
We can bypass WebKit with:
Injecting Inside SCRIPT Tag:
Injecting Inside Event Attributes:
DOM Based:
DOM Based, there are other scenarios that are not covered by browsers filters.
For example, fragmented vectors in multiple GET parameters or attacks that are not reflected in the same page, mXSS, etc.
Last updated