Case Study On SQL Injection
Case Study On SQL Injection
Page | 915
Shelly et al., International Journal of Advanced Research in Computer Science and Software Engineering 3(11),
November - 2013, pp. 915-919
5) Adding or Modifying Data: The aim of these attacks is to add or change information in a database.
6) Performing Denial of Service: These attacks are performed to shut down the database of a Web application, thus
denying service to other users even to legitimate ones.
7) Evading Detection: This type of attacks refers to certain those which are employed to avoid auditing and
detection by system protection mechanisms.
8) Bypassing Authentication: The goal of these types of attacks is to allow the attacker to bypass authentication
mechanisms of application and database. Bypassing such mechanisms could allow the attacker to assume the
rights and privileges associated with another application user.
9) Executing Remote Commands: These types of attacks attempt to execute arbitrary commands on the database.
These commands can be stored procedures or functions available to database users.
10) Performing Privilege Escalation: These attacks take advantage of implementation errors or logical flaws in the
database in order to escalate the privileges of the attacker [1].
II.
RELATED WORKS
Over years, many tools for detection and prevention of SQL Injection attacks have been developed. AMNESIA
developed by Halfond and Orso in [4] is a detection and prevention tool for SQL injection attack. It uses static analysis
and runtime monitoring for the purpose. The tool builds a model of the legitimate queries at each hotspot i.e. where SQL
queries are issued to database engine and monitors the application at runtime to ensure that all generated queries match
the statically-generated model. In [5], a tool named CANDID is proposed for detecting SQL injection. The tool
dynamically infers the programmer-intended query structure on any input, and detects attacks by comparing them against
the intended query structure. In [6], SQLRand uses instruction set randomization to detect and abort queries with injected
code and every SQL keyword is joined with a random integer to mislead the attacker. The proposed technique in [7]
prevents SQLIA in stored procedures by combining static application code analysis with runtime validation. In the static
part, a stored procedure parser is designed and it instruments the necessary statements in order to compare the original
SQL statement structure to that including user inputs for every SQL statement which depends on user inputs. The
technique abstracts the intended SQL query behavior in an application in the form of an SQL-graph and this graph is then
validated against all the different user inputs at runtime to capture all malicious SQL queries, before they are sent for
execution. An efficient technique is presented in [2] for detecting and preventing SQL Injection attack using pattern
matching algorithm. Pattern matching identifies or detects any anomaly packet from a sequential action, as the malicious
code includes many anomaly packets or strings. The technique proposed in [3] uses a new middle-ware-based prevention
mechanism: SQLIMW. The SQLIMW avoids SQL-Injection attack from the programmer to the server. Hash function is
used to replace encryption for better security. Furthermore, by combining the hash with XOR, it protects username,
password and private key of SQLIMW. The proposal provides better security and efficiency. This kind of middleware is
transparent to the programmer is not limited to sign-on authentication mechanism or single sign-on system, it can exist in
any layer of Web application system exchanging information with the database.
Almost every solution given to detect or prevent SQL Injection attacks is either for application layer or for database
layer. But none of them provide security at both application and database layers. Also very little emphasis is laid on
preventing SQL Injection attacks in stored procedures. [7] Although the mechanism of SQLIA is the same for both stored
procedure and application layer program, the same detection technique could not be applied to stored procedures,
because of limited programmability of stored procedures and the techniques usability and deployability. Many existing
techniques, such as filtering, information-flow analysis, penetration testing, and defensive coding, can detect and prevent
a subset not all of the vulnerabilities that lead to SQLIAs.
III. PROPOSED WORK
Here an efficient scheme for detecting and preventing SQL Injection attacks has been introduced. This scheme provides
security from both the frontend as well as the backend of the application so that, if security is compromised at one end,
the second end can still prevent SQL injection attacks. It consists of two modules:
Frontend phase
Backend phase
In the frontend phase, user input validation takes place. A list of several malicious known symbols or say anomaly tokens
has been maintained. When a user provides an input in the input field, the validation process checks that input and
matches it with the anomaly token list and if a match exists then it restricts further access by the attacker as shown in fig.
1.
Page | 916
Shelly et al., International Journal of Advanced Research in Computer Science and Software Engineering 3(11),
November - 2013, pp. 915-919
At every illegal attempt a log entry will be saved in the database in which the date, time, page of the application on which
illegal attempt was made and the IP address of the attacker got saved as shown in fig. 2. The IP address can help us track
the attacker in future if we want to.
Input text
No
Verified
Restrict procedure
Yes
Execute procedure
Page | 917
Shelly et al., International Journal of Advanced Research in Computer Science and Software Engineering 3(11),
November - 2013, pp. 915-919
At this point, this attack works like a piggy-back attack. A malicious query gets executed, which results in a database
shut down. This example shows that stored procedures can be vulnerable in the same way as traditional application code
[1]. But in Transact-SQL any malicious string or query cannot get merged with the parameters because there are no
concatenation symbols as mentioned above. For example:
Create procedure dbo.get_user
@username varchar(45),
@password varchar(45)
As
select username, password from users where username= @username and password = @password
This type of code can prevent other types of SQLIA as well. The architecture for proposed backend phase is shown in
fig. 4.
Analyze stored
procedure oneYES
by one
NO
If vulnerable
yes
yes
Union Queries
yes
Piggy-Backed Queries
yes
Stored Procedures
yes
Inference
yes
Altenate Encodings
yes
Page | 918
Shelly et al., International Journal of Advanced Research in Computer Science and Software Engineering 3(11),
November - 2013, pp. 915-919
V. CONCLUSION AND FUTURE WORK
SQL Injection attacks are one of the most dangerous types of threats to web applications. Many solutions to these attacks
have been proposed over years. But almost none of them provide security to the full extent of this attack. Also very little
emphasis is laid on preventing SQLIA in stored procedures. The proposed solutions for preventing or detecting SQLIA
provide security to either application layer or database layer but not to both. We have proposed a technique that provides
security to both application layer as well as database layer via frontend phase and backend phase. Researchers have
provided this two phase security because if security is compromised at one phase, the second phase can still provide
security from attacks. The technique currently works with Microsoft SQL server but in future it can be modified to work
with other servers as well.
REFERENCES
[1]. William G.J. Halfond, T. Viegas and A. Orso, A Classification of SQL Injection Attacks and Countermeasures,
in Proc. of ISSSE06, 2006.
[2]. Dr. M. Amutha Prabakar, M.KarthiKeyan, Prof.K. Marimuthu, An Efficient Technique for Preventing SQL
Injection Attack Using Pattern Matching Algorithm, in Proc. of ICECCN, 2013.
[3]. Gao Jiao, Chang-Ming XU and Jing Maohua, SQLIMW: a new mechanism against SQL-Injection, in Proc. of
CSSS, 2012.
[4]. William G.J. Halfond and Alessandro Orso, AMNESIA: Analysis and Monitoring for Neutralizing SQLInjection Attacks, in Proc. of ASE, 2005, p. 174183.
[5]. Sruthi Bandhakavi, Bisht, P. Madhusudan, V.N. Venkatakrishnan, CANDID: Preventing SQL Injection Attacks
using Dynamic Candidate Evaluations, in Proc. of CCS07, 2007.
[6]. S. W. Boyd and A. D. Keromytis, SQLRand: Preventing SQL injection attacks, in Proc. of ACNS, 2004.
[7]. Ke Wei, M. Muthuprasanna and Suraj Kothari, Preventing SQL Injection attacks in stored procedures, in
proceedings of ASWEC, 2006.
[8]. Amit Kukreti. (2005) SQL Injection Attacks homepage on codeproject. [Online]. Available:
http://www.codeproject.com/Articles/11020/SQL-injection-attacks/
[9]. (2013) Malicious SQL Injection: an introduction homepage on hackmac. [Online]. Available:
http://www.hackmac.org/tutorials/malicious-sql-injection-an-introduction/
Page | 919