A Taxonomy of SQL Injection Attacks
A Taxonomy of SQL Injection Attacks
I.
Web
Application
INTRODUCTION
http://www.domain.com/news.php?nid=170
http://www.domain.com/news.php?nid=170OR1=
1
270
264
269
Result:
"Incorrect
syntax
near
'ABCD'.
Unclosed quotation mark after the character
string '' AND Password='TEST''."
A. Tautologies
This type of SQL injection attack works by making the
WHERE clause always true, And this will result in
bypassing the condition inside the SQL statement. Attackers
mostly use tautology SQL injection to bypass the
authentication. They also add inline comment signs to ignore
the remaining part of the statement to achieve to the highest
amount of the result in return with the lowest range of
conditions [3]. Mostly SQL tautologies are comes handy
when the attacker try to force a SQL statement to return all
records, by ignoring all WHERE conditions. The most
common tautology is or 1=1. It will put another condition
by concatenating the OR and the 1=1 criteria that always
is true so the result of the whole condition will be true [4].
Below is a SQL query for fetching all columns that their
username are equal to Administrator and their pass is equal
to root.
OR 1=1 --
Original URL:http://www.example.com/news.php?
newsid=340
398
102
270
271
265
E. Stored Procedures
Stored procedures are premade portion of SQL queries
that are designed to do a specific task. Some of the database
systems have their own pre-defined stored procedures for
working with operating system. Poor written store
procedures are also vulnerable to SQL injection attack and
attacker can execute them to achieve his malicious goals. If
the attacker can execute database predefined stored
procedures, he also will be able to run commands on
operating system of the server machine (Privilege
escalation).
Currently a lot of developers wrongly believe that using
of stored procedures is a good method to avoid SQL
injection but this is not true in general. Basically stored
procedures can be helpful in avoiding SQL injection by
limiting the types of statements that can be passed to SQL
parameters. This limitation cannot completely protect the
application against SQL injection because still there are
some ways to bypass these limitations.
In the following example there is a stored procedure that
receive category variable from the outside world.
URL:http://example.com/news.php?id=10
UNION
SELECT ALL 1,2-ERROR:All
queries
in
an
SQL
statement
containing a UNION operator must have an
equal number of expressions in their target
lists.
URL:http://example.com/news.php?id=10
UNION
SELECT ALL 1,2,3-ERROR:All
queries
in
an
SQL
statement
containing a UNION operator must have an
equal number of expressions in their target
lists.
URL:http://example.com/news.php?id=10
SELECT ALL 1,2,3,4NO ERROR
UNION
http://example.com/news.php?id=10
SELECT ALL 1,DB_NAME,3,4--
UNION
AND
ALTER
PROCEDURE
get_news
(@category
NVARCHAR(50))
AS
BEGIN
DECLARE @sqlcmd NVARCHAR(MAX);
SET @sqlcmd = N'SELECT * FROM news WHERE
news_cat = ''' + @category + '''';
EXECUTE(@sqlcmd)
END
D. Piggy-Backed Queries
In this type of attack, the attacker will inject an
independent query and in result of a successful attack the
second query will run after the first original query that
already ran. The different of this attack with UNION attack
is that the queries will not join each other but they are
completely independent. This attack named piggy back
because the secondary query will be sent to database under
the cover of the first query [6].
Implementing this attack is only possible if the database
configured in a way that give this permission to the user to
run multiple queries in the same line. This type of attack can
be very dangerous because it give the ability to the attacker
to add any kind of SQL command he want and run it in the
database, which can causes a high impact incident.
Semicolon ( ; ) is playing an important role in this type of
attack because attacker use it as a delimiter for the end of the
first query and the start of new query. But in some database
management systems, the existence of delimiter is not
necessary.
In the following example we can see a query which will
fetch news from the news table based on 3 conditions of
year, author and type.
sport'; SHUTDOWN; --
F. Inference
In this type of attack, attackers inject the SQL and
observe the differences in return from the web application.
Basically attack launched by asking questions. For example
if the answer is A do M or if the answer is B do
N[7]. Usually this attack take place when the web
application is harden in aspect of error handling and attacker
cannot use the error messages.
There are two main attack technique categorized as
Inference attacks, Timing Attacks and Blind Injections.
Timing Attacks:
In timing attack, SQL injection will let the
attacker to understand the answer to his question by
271
272
266
http://www.MyWebsite.com/news.php?id=12
0
AND
IF(version()
like
4%,
sleep(10), false))--
alert
tcp
any
any
->
$HTTP_SERVERS
$HTTP_PORTS (msg: SQL Injection attempt;
flow: to_server, established; content: ' or
1=1 --; nocase; sid: 1; rev:1;)
AND
http://example.com/news.php?id=132
(select 1 from users limit 0,1)=1
AND
%31%20%4F%52%20%31%3D%31
1 OR 1=&#x
31;
1 OR 1=1
DR/**/OP users
IV.
PROPOSED SOLUTION
G. Alternate Encodings
Alternate encoding is not an independent type of attack
but its a technique that mostly used next to other SQL
injection techniques to avoid security system of that web
application or network infrastructure from detecting of the
272
273
267
CONCLUSION
273
274
268