REPORT ON TECHNICAL SEMINAR
SQL Injection Attacks
‘echniques and Protection Mechanisms
(UCSE) International Journal on Computer Science and Engineering Vol. 02, No. 07, 2010,
Susanta Nanda, Lap Chung Lam, Fourth Intenational Conference IEEE 2008
SQL Injection Prevention Accessed Nov.10, 2010,
Submitted by
B.SIVA KUMAR (07BE1A0540)
Under The Guidance of
NMS DESAI
Department of Compute Science & Engineering
Krishna Murthy Institute of Technology & EngineeringCollege Code : BE EAMCET CODE : KITE
Oy KRISHNA MURTHY
INSTITUTE OF TECHNOLOGY & ENGINEERING
Sy. No. 23 & 39, Edulabad Village, Ghatkesar Mandal, Ranga Reddy Dist, - 501 301, Ph : 08415-20303
Certificate
This is to certify that the
Mechanisms” being submitted by B.SIVA KUMAR (07BE1A0540) in partial fulfillment of the
award of Bachelor of Technology in Computer Science & Engineering, to Krishna Murthy
issertation “SQL Injection Attacks: Techniques and Protection
Institute of Technology & Engineering is a record of bonafide work carried out by them under
my guidance and supervision.
The results presented in this dissertation have been verified and are found to be
satisfactory. They have not been submitted to any other University for the award of any degree
or diploma to the best of my knowledge.
Fenn
Internal guide &Head of the Department
N.M.S, DESAI
City Office : # 1-7-9/3, Hari Hara Estate Oop ISI Street No@, Habsiguda. Hvderabad 07 Tel -040-27170462, 32470044ACKNOWLEDGEMENT
Self Confidence, hard work, commitment and planning are essential to carry out any task.
Possessing these qualities is sheer waste, if an opportunity does not exist, Whose constant
guidance and encouragement crown all efforts with Success.
express my sincere gratitude to, Mr.NMS DESAI, Head of The Dept, for his precious
suggestions, motivation and co-operation for the successful completion of this work.
| extend my sincere thanks to Dr.S.F.KODAD, Principal and Mr.D.KrishnaMurthy, secretary of
Krishnamurthy institute of Technology and Engineering.
We would also like to express our sincere thanks to all the staff of CSE, KITE for their
kind cooperation and timely help during the course of our project, Finally, we would like to
thank our parents and friends who have always stood by us whenever we were in need of
them.
With Gratitude,
8.SIVA KUMAR (07BE1A0540)CONTENT
. INTRODUCTION
. CODE INJECTION ATTACKS,
CATEGORIES OF SQL INJECTION ATTACKS
SQL INJECTION METHODS
METHODS FOR PROTECTION AGAINST SQL INJECTION ATTACKS
A) BIND VARIABLE MECHANISM
B) PARAMETERIZED STATEMENTS.
C) INPUT VALIDATION
CONCLUSION
. ACKNOWLEDGMENT
. REFERENCES
10
12Abstract
‘When an internet user interacts in web environment by surfing the Net, sending electronic
Mail messages and participating in online forums lot of data is generated which may have user’s
private information. If this information is captured by third party tools and techniques; it may
cause a breach intend user privacy. In the Web environment, end user privacy is one of the most
controversial legal issues. In this paper issues related to information leakage through SQL
injection attacks are presented and protection mechanisms are also discussed1, INTRODUCTION
As the Internet is growing day by day, most of the people are not aware of security and privacy.
Internet is @ widespread information infrastructure; it is basically an insecure channel for
exchanging information, Web security is the set of rules and measures taken against web security
threats. Web privacy is the ability of hiding end user’s information. Nowadays most of the
applications have the vulnerability (weakness) that makes a threat possible. An attack may be
possible due to poor design, configuration mistakes, or poor written code of the web Application,
A threat can be harmful for database, control of web application, and other components of web
application, that are needed to be protected from all types of threat. All types of code injection or
SQL injection are very dangerous for these components of the web application. To build secure
applications, security and privacy must be considered, and developer must be aware about it.
‘They are Confidentiality, Integrity and availability. Confidentiality means the information
available on a system should be safe from unauthorized people; Integrity means the information
available in an organization should be complete and whole. It shouldn't be altered by any
‘unauthorized person. Availability is as important as Confidentiality and Integrity. It means the
information requested or required by the
Authorized users should always be available
ty2. CODE INJECTION ATTACKS
Code Injection is a term used when malicious code/script is injected into a program/web
application from an outside source, for example input ficld which is provided by the web
application to take input from the end-user. This attack makes use of lack of accurate
input/output data validation. The injected malicious code executes as a part of the application.
The consequences of a successful code injection attack may result in either damage to an asset,
or an undesirable operation. Attack can be performed within software, web application etc in
which the weakness is present, Weakness contribute to the introduction of vulnerabilities within
that software or web applications, vulnerability can be used by the attacker to exploit the web
applications to gain unintended access to data, denial of services, or perform incorrect
operations. HTML Injection Attack, Cross Site Scripting Attack,SQL Injection Attack, Shell
Attack, Content Spoofing, HTTP Response Splitting, HTTP Request Splitting andXML
Poisoning Attack are some examples of the code injection attack. SQL Injection: - SQL injection
is an attack technique which can be used by the attacker to exploit the web application; as @
result the attacker may gain unauthorized access to a database or to retrieve information directly
from the database. Attacker can exploit SQL injection vulnerabilities remotely without any
database or application authentication. SQL injection attacks are straightforward in nature — an
attacker just passes malicious string as an input to an application for stealing confidential
information.
2I. SOL Injection using Dynamic Strings
Most of the web based application takes input from the end user for constructing dynamic SQL
statement [2],
Query = “SELECT * FROM student WHERE sname = ‘student name’ “;
1 Example 1 - Dynamically built SQL command string
Consider a web application that takes input from the stucents and displays the result
of the student, with the logic of the above SQL query, the result of the above query is as follows
Suppose an attacker submits a student name that looks like the following:
Student Name: nikita’ OR ‘1'="1
‘The SQL command string built from this input would be as follows:
SELECT * FROM student WHERE sname = ‘nikita’ OR ‘17="1
‘This query will retum all rows from the student's database, regardless of whether "nikita" is a
real user name. This is due to the OR statement appended to the WHERE clause. The
comparison '1'='1' will always return a "true” result, making the overall WHERE clause evaluate
to true for all rows in the table. If this is used for authentication purposes, the attacker will often
be logged in as the first or last user in the table.hentication purposes, the attacker will often be
logged in as the first or last user in the table
8)3. CATEGORIES OF SQL INJECTION ATTACKS
‘There are four main kinds of SQL Injection attacks
1. SQL Manipulation
2. Code Injection
3. Funetion Call Injection
4, Buffer Overflows
SQL manipulation usually involves modifying the SQL query through altering the WHERE
clause. In this class of attack, amend the WHERE clause of the statement so the WHERE clause
constantly results in TRUE[2]www-integrigy.conv..Integrigy Oracle SQL. Injection_Attacks].
In the case of Code injection an attacker introduces new SQL statements into the input field
instead of valid input. The classic code or statement appends a SQL Server command to make
SQL statement vulnerable. Code injection only works when multiple SQL statements per
database request are supported or keywords like AND,OR are supported by the database.
Function call injection is the addition of database functions or user defined functions into a
vulnerable SQL queries. These function calls can be used to make intemal calls or modify data in
the database that can be harmful to the users.SQL injection of buffer overflows is a subset of
function call injection, In several commercial and open-source databases, vulnerabilities exist in
a few database functions that may result in a buffer overflow.
(4)4. SQL INJECTION METHODS,
SQL Injection method is as follows:
SOL Manipulation
The most common type of SQL Injection attack is SQL manipulation, The attacker attempts to
modify the present SQL statement by adding elements to the WHERE clause. An cxample of
‘SQL manipulation can be given by a simple search application. This application takes student
roll number as input and displays its result. The web application may run the following query.
SELECT * FROM student WHERE rollnum = ''
This query will return the result of the student, but if the attacker attempts to manipulate the SQL
statement to execute as ~
Student Result Page
"ORE
Figure I Taking Input from UserSELECT * FROM student WHERE rollnun = ‘+ or ‘1! = ‘2
The Result of Student is as follows
Paceed query fe Owe Server! SELECT * FROM stulent where rolbuum=" OR '1'="1"
Figure 2 Result of the Malicious Code
‘The WHERE clause becomes true for every row and as a result it fetches all entries of the
database, in this waythe attacker gains access to the application,
(6)5. METHODS FOR PROTECTION AGAINST SQL INJECTION ATTACKS
‘SQL Injection attacks can be protected with simple changes in server site programming as well
as client side programming. Developers must be aware of all types of attacks and take care for all
possible attacks. Each and Every dynamic SQL statement must be sanitized. A single
unprotected query can be harmful for the application, data, or database server.B. Taking User
Input From Predefined Choices In this way the web application can be secured from malicious
attacks, The attacker cannot insert custom queries or any type of harmful script which can disturb
the integrity of the database. This is a simple yet effective way to curb web application attacks.
This can be established by making simple changes into the server site code.
Student Result Page
(0 f= =I [0]
Figure 3 Taking Input from Predetined Choices
0A, Bind Variables Mechanism
Bind variable is another technique to control SQL. injection attacks. Using bind variables helps in
improving web application performance. The web application developer should use bind
variables in all SQL statements. In java language there is a mechanism called prepared statement,
this implements the concept of bind variables mechanism.
Prepared Statement pstate;
Pstate=con.prepareStatement ("select * from student where
xvollnum =2");
pstate.setString (1, "sroll");
B. Parameterized Statements
To defend SQL injection attacks, user input must not be directly passed in SQL queries. Instead,
parameterized statements must be preferred, ot else user input should be sanitized or filtered
carefully (17]-To sanitize the given user input it must be assigned (bound) to a parameter and
passed through a filtering sanitizing function like one present in PHP (mysql_real_eseape_string
(Suser input)), The use of this function adds a back slash (}) against all of the escape characters
ssuch that the malicious seript present is not executed. The
Result of that function can be viewed in figure 4.
The Result of Student is ay follows ao
Entered Roll Number is: OR '1"
Passed query: SELECT * FROM student where rolmm="' OR “1''="1!
Figure 4 Result of Using Predefined Function
8]C. Input Validation
This is the simplest method for defense against SQL injection attacks, Every passed string
parameter ought to be validated. Many web applications use hidden fields and other techniques,
which also must be validated. If a bind variable is not being used, special database characters
must be removed or escaped.
‘Student Result Page 2
eh
Enter Roll Number
‘Your string has specs cheracters
hace are nn allel
Figure 5 Input Validation Using Client Site Seript
In most databases the single quote character and other special characters are a big issue, the
simplest method to avoid them is to escape all single quotes. This can be established by using
client side scripting language
(]VI. CONCLUSION
Code injection attacks, especially SQL injection attack is one of the infamous issues. Controlling
the maliciousSQL code/script on the web application and maintaining the end privacy is still a
key challenge for the web developer. These issues must be considered seriously by the web
developers involved in developing websites using databases. This paper describes how an
attacker can exploit the web application by using SQL injection attack to get confidential
information from a database. Different protection mechanisms against SQL. injection attack are
also proposed.Nikita Patel et al. / International Journal on Computer Science and Engineering
(CSE)
110)VILLACKNOWLEDGMENT
The research presented in this paper would not have been possible without our college, PCST,
Bhopal. We wish to express our appreciation to all the people who helped turn the World-Wide
Web into the useful and popular distributed hypertext and providing information as it is
anywhere. We also wish to thank the anonymous reviewers for their valuable suggestions, who
helped in improving our paper content.
(a1)VIILREFERENCES
[1] “An Introduction to SQL Injection Attacks for Oracle Developers,” [Online]. Available:
www.integrigy.com/Integrigy_Oracle_SQL_Injection_Attacks [Accessed: Oct.02, 2010].
[2] *SQL Injection” [Online] Available: http://projects. webappsee.org/w/page! 13246963/SQL-
Injection [Accessed: Oct 12, 2010]
[3] “Wikipedia,” [Online]. Available: http://en.wikipedia.org/wiki [Accessed: Oct.5,2010].
[4] “SQL Injection Prevention,” [Online] Available:
hitp://www.owasp.org/index.php/SQL_ Injection Prevention (Accessed: Nov.10,
2010),
[5] ‘Prepared Statements” [Online] Available:
http://www .owasp.org/index php/SQL_Injection_Prevention [Accesse
[6] “Blind SQL Injection” Kavin Spet White Paper. [Online] Available:
[7] “Second Order Code Injection Attack” Gunter Ollmann [Online] Available:
[8] “Web Application Attack Prevention for Tiered Internet Service” Susanta Nanda, Lap Chung
Lam, Fourth Intenational ConferencelEEE 2008.
Nikita Patel et al. / International Journal on Computer Science and Engineering (IJCSE)
ISSN
lov 12, 2010}.
(221