bypassing waf filters in sqli
what is waf or web application firewall>?
-a web application firewall (waf) is an appliance,server plugin, or filter that applies a set of rules to an http conversation. generally, these rules cover common attacks such as cross-site scripting (xss) and sql injection. by customizing the rules to your application, many attacks can be identified and blocked. the effort to perform this customization can be significant and needs to be maintained as the application is modified.

some website are using waf filter.
if u found a vuln sites that have waf and u try to inject a union based query and its show's not acceptable, 403 forbidden or web application firewall alert..that means the query or syntax that u inject is filter or blocked by waf.

ok now here's some method to bypass waf filters.


sql comments are a blessing to us sql injectors. they allow us to bypass a lot of the restrictions of web application firewalls and to kill certain sql statements to execute the attackers commands while commenting out the actual legitimate query. some comments in sql:

//, ? , /**/, #, ?+, ? -, ;

2)case changing:

some waf?s will filter only lowercase attacks as we can see we can easily evade this by case changing:
possible regex filter:

id=1+union/**/select, or with xss -> alert(1)

3)inline comments:

some waf?s filter key words like /union\sselect/ig we can bypass this filter by using inline comments most of the time, more complex examples will require more advanced approach like adding sql keywords that will further separate the two words:


take notice of the exclamation point /*!code*/ the exclamation point executes our sql statement.
inline comments can be used throughout the sql statement so if table_name or information_schema are filtered we can add more inline comments. for example, let?s pretend a site filters union,where, table_name, table_schema, =, and information_schema.. these are 3 statements we need to inject our target.
for this we would:

id=1/*!union*/+select+1,2,concat(/*!table_name*/)+from /*information_schema*/.tables /*!where */+/*!table_schema*/+like+database()? -

the above code would bypass the filter. notice we can use ?like? instead of ?=?
another way to use inline comemnts, when everything seems to fail you can try to through the application firewall off by crafting a sql statement using variables:

id=1+union/*&a=*/select/*&a=*/1,2,3,database()? -

the above code should bypass the union+select filters even where common inline comments didn?t work itself

4)buffer overflow:/unexpected input:

a lot of wafs are written in the c language making them prone to overflow or or act differently when loaded with a bunch of data. here is a waf that does it?s job correctly, but when given a large amount of data allows the malicious request and response.

id=1 and (select 1)=(select 0xaaaaaaaaaaaaaaaaaaaaa 1000 more a?s)+union+select+1,2,version(),4,5,database(),use r(),8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23, 24,25,26

this bypass above works. i myself just used this against a web site recently.

5)replaced keywords(preg_replace and/or waf?s with the same action

sometimes and application will remove all of a keyword. for instance, let?s say we have a filter that replaces union select with whitespace. we could bypass that filter like so:


as you can see once union+select has been removed our capital union+select takes its place successfully injecting our query:


6)character encoding:

most waf?s will decode and filter an applications input, but some wafs only decode the input once so double encoding can bypass certain filters as the waf will decode the input once then filter while the application will keep decoding the sql statement executing our code.
examples of double encoding:

id=1%252f%252a*/union%252f%252a /select%252f%252a*/1,2,password%252f%252a*/from%252f%252a*/users?+