SlideShare a Scribd company logo
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
27
Comparison And Implementation Of Random4
Algorithm And Hirschberg Algorithm Using Open
Source Software For Prevention Of SQL Injection
Attack
1
Mohammed Ahmed, 2
Sayyed Saima, 3
Shaikh Shagufta, 4
Shaikh Tazreen
(Department of Computer Engineering)
M.H. Saboo Siddik College of Engineering, Clare Road, Byculla, Mumbai-400008, India.
ABSTRACT
SQL injection attacks are easy way to attack the web applications and gain access to the private data in a
database. Using different types of the SQL attacks one can easily gain access, modify the database or can
even remove it. Details such as fields and table names are required for a hacker to modify a database.
Hence, to provide the increased amount of security to users and their data, different types of techniques are
used such as Random4 algorithm, which is based on randomization and used to encrypt the user input,
Hirschberg algorithm which is a divide and conquer technique used to match the query pattern. In this
paper we are providing a comparative study and implementation of these prevention techniques using open
source software.
Keywords
SQL injection, Random4, Hirschberg.
1. INTRODUCTION
According to the White Hat report on the web security vulnerabilities in the year 2011 it is shown
that nearly 14-15 % of web application attacks account for SQL Injection [1].
SQL Injection Attack is a type of code-injection attack [2] which penetrates in the web
applications and gets illegal access to the databases, it is very easy for the attackers to inject the
code in the web page and gain access to all the databases, or to modify or even delete the
databases. This type of attack is mainly caused due to improper validation of user input. [3].
With the leading attacks on the web applications it is very important to prevent them. So,
different techniques are used for the prevention, named as Random4 Algorithm which is based on
randomization. It will take user input and encrypt it using Random4 Look up table, the encryption
of the current characters will be based on the next character. Second technique is Hirschberg
Algorithm which is a divide and conquer version of the Needleman-Wunsch algorithm [4] and is
based on pattern matching of the query. Any input given to the web application goes in the form
of query, so using Hirschberg one standard query format will be set and if the received pattern of
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
28
the query from web page is not matched with the set query pattern then no one can get access to
the web page or the databases.
The following prevention techniques are chosen for comparison and implementation named as
Random4 Algorithm and Hirschberg Algorithm.
IMPLEMENTED ALGORITHMS:
I– RANDOM4 ALGORITHM:
Input:
input String inp[]
Output: Encrypted String en[]
N: Length of inp[]
R[]: Random values of character
For i=1 to N
If(inp[i+1]==null || inp[i+1]=lowercase)
Then en[i]=R[lower]
End { if }
Else If( inp[i+1]=uppercase)
Then en[i]=R[upper]
End { Else if }
Else If( inp[i+1]=number)
Then en[i]=[number]
End { Else if }
Else If( inp[i+1]=special_character)
Then en[i]=[special]
End { Else if }
End { For }
Return en[]
Random4 is based on the randomization and is used to convert the input into the cipher text. Any
input in the web forms will be containing numbers, uppercase, lowercase or special characters.
Using the look up table, the user input will be converted into cipher text. Each character in the
input can have 72 combinations. Hence there will be 726 combinations possible for 6 character
inputs possible. To encrypt the input, each input character is given four random values. A sample
look up table is given below. The first column in the table is for lower case, second is for upper
case, third is for numbers and fourth is for special characters now based on the next input
character, one of these four values is substituted for a given character. For example, if the input is
provided in the form of username as xY@2 then the first character ‘x’ is given four Random
values in the look up table based on the next input character which is upper case here, the value
“R[Upper]” is chosen.
If the next character was lower case then the value “R[lower]” is chosen. If the next character
was number, the value “R[number]” is chosen. If the next character was special character then
value “R[Special]” is chosen.
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
29
Table 1: Look Up table
II- HIRSCHBERG ALGORITHM:
Hirschberg’s algorithm is a divide and conquer version of Needleman-Wunsch algorithm. In this
algorithm one standardized form of an SQL Query is set for the login.
This algorithm works on the logic 1 and 0. Each word in the login query is considered as a
column and row wise for checking. When the user enters the input in the web page, it goes into
the form of query. Each word of the query will be verified with the predefined set query and if the
query word is perfectly matched then it will be marked as 1 otherwise 0. If in the whole table a
single 0 is found then it will be considered as an attack and system will block the access.
For example if the username and password entered as ‘Soni’ and ‘1234’ respectively.
Then the query will be formed as
SELECT * FROM logintable WHERE username=’Soni’ AND password=’1234’;
In this query each format of the query will be matched and it will be considered as a correct user.
Now suppose the SQL injection query
Username: soni and password: ‘abcd’ OR ‘1’=’1
Here after ‘abcd’ it will be detected as SQL injection because after password’s quotes (‘‘) it will
not get AND statement instead it will get OR statement which is not in the predefined query. So
in this way the attack is prevented.
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
30
Table 2: Look Up table
3.IMPLEMENTATION:
I – RANDOM4 ALGORITHM:
package com.java.utility;
public class Random4 {
// a-z 26 A-Z 26 0-9 10 Special 25 Total 87
public char[] mainList=
{
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'0','1','2','3','4','5','6','7','8','9',
'!','@','#','$','%','^','&','*','(',')','-','',';','"',''',','
};
public char[] firstList=
{
',',''','"',';','','-',')','(','*','&','^','%','$','#','@','!',
'9','8','7','6','5','4','3','2','1','0',
'Z','Y','X','W','V','U','T','S','R','Q','P','O','N','M','L','K','J','I','H','G','F','E','D','C','B','A',
'z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'
};
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
31
public char[] secondList=
{
'0','1','2','3','4','5','6','7','8','9',
'!','@','#','$','%','^','&','*','(',')','-','',';','"',''',',',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
};
public char[] thirdList=
{
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m',
'z','y','x','w','v','u','t','s','r','q','p','o','n','A','B','C','D','E','F','G','H','I','J','K','L','M',
'9','8','7','6','5','4','3','2','1','0',
',',''','"',';','','-',')','(','*','&','^','%','$','#','@','!'
};
public char[] fourthList=
{
'5','6','7','8','9','0','1','2','3','4',
'n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M',
'!','@','#','$','%','^','&','*','(',')','-','',';','"',''',',',
'm','l','k','j','i','h','g','f','e','d','c','b','a','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
};
//Encryption module
public String encrypt(String data)
{
String encdata = "";
for(int i=0;i<data.length();i++)
{
char get = data.charAt(i);
String getcase = "lower";
if(i!=data.length()-1)
{
char findcase = data.charAt(i+1);
getcase = getCase(findcase);
}
int position = getPosition(get);
if(position == -1)
{
encdata = encdata + get;
}
else
{
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
32
if(getcase.equals("lower"))
{
encdata = encdata + firstList[position];
}
else if(getcase.equals("upper"))
{
encdata = encdata + secondList[position];
}
else if(getcase.equals("number"))
{
encdata = encdata + thirdList[position];
}
else if(getcase.equals("special"))
{
encdata = encdata + fourthList[position];
}
System.out.println("Case : "+getcase+" "+get+" a : "+encdata);
}
}
return encdata;
}
public String getCase(char ch)
{
String charcase = "";
int val = (int)ch;
if(val>64 && val<91)
{
charcase = "upper";
}
else if(val>96 && val<124)
{
charcase = "lower";
}
else if(val>47 && val<58)
{
charcase = "number";
}
else
{
charcase = "special";
}
return charcase;
}
public int getPosition(char ch)
{
int position = -1;
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
33
for(int i=0;i<mainList.length;i++)
{
if(ch == mainList[i])
{
position = i;
break;
}
}
return position;
}
II – HIRSCBERG ALGORITHM:
package com.java.utility;
import java.util.StringTokenizer;
import java.util.Vector;
public class Hirshberg {
boolean analysis = false;//not allowed
//true allowed
Vector<Object> xAxis;
Vector<Object> yAxis;
Vector<Object> result;
Vector<Object> output;
String applicationQuery;
// Setting the predefined Query pattern
public Hirshberg() {
xAxis = new Vector<Object>();
yAxis = new Vector<Object>();
keywords();
}
public void keywords() {
xAxis.add("SELECT");
xAxis.add("*");
xAxis.add("FROM");
xAxis.add("LoginTable");
xAxis.add("WHERE");
xAxis.add("username");
xAxis.add("=");
xAxis.add("'");
xAxis.add("");
xAxis.add("'");
xAxis.add("AND");
xAxis.add("password");
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
34
xAxis.add("=");
xAxis.add("'");
xAxis.add("");
xAxis.add("'");
xAxis.add(";");
}
//pattern matching module
public boolean Checker(String query) {
try {
result = new Vector<Object>();
applicationQuery = query.trim();
StringTokenizer st = new StringTokenizer(applicationQuery, " ");
while (st.hasMoreElements()) {
String e = st.nextToken();
if (!e.contains("'")) {
result.add(e);
} else {
String r = e;
StringTokenizer stk = new StringTokenizer(r, "'");
while (stk.hasMoreElements()) {
result.add("'");
result.add(stk.nextElement());
result.add("'");
}
}
}
System.err.println(result.size());
for (int z = 0; z < result.size(); z++) {
if (result.elementAt(z).toString().equals("'")) {
if (result.elementAt(z + 2).toString().equals("'")) {
result.setElementAt("", (z + 1));
z = z + 3;
}
}
}
System.out.println(xAxis);
System.err.println(result);
//Analysis Module
output = new Vector<Object>();
int count = 0;
for (int i = count; i < xAxis.size(); i++) {
for (int j = count; j < result.size(); j++) {
String x = xAxis.elementAt(i).toString();
String y = result.elementAt(j).toString();
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
35
System.out.println("x== " + x + " y== " + y);
if (x.equalsIgnoreCase(y)) {
output.add("1");
analysis = true;
count++;
break;
} else {
analysis = false;
count++;
break;
}
}
if (!analysis) {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return analysis;
}
}
4. RESULTS:
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
36
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
37
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
38
5. COMPARATIVE STUDY:
Parameters Hirschberg Random4
Proxy Overhead No No
Time Complexity Less More
Space Complexity Less Bit more
Encryption No encryption (query
pattern is matched only)
User Input
Computational Overhead Less Bit more
Table 3: Comparative Study
6. CONCLUSION:
This paper presents the methods for preventing the web applications from SQL injection attack.
And by the above comparative study, we have concluded that Hirschberg algorithm is easy to
implement, it has less time and space complexity and no proxy or computational overhead. On
the other side Random4 is also a powerful technique because of encryption but due to that time
Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015
39
and space complexity is more than Hirschberg Algorithm. It is easy to implement, and it has no
proxy or computational overhead.
REFERENCES:
[1] https://www.whitehatsec.com/resource/stats.html
[2] W.G halfond and A. orso AMNESIA: Analysis and monitoring for neutrilizing SQL injection
attacks.in proceedings of the IEEE and ACM International Conference on Automated Software
Engineering (ASE-2005), Long Beach, CA, USA, NOV 2005.
[3] Random4: An Application Specific Randomized Encryption Algorithm to prevent SQL Injection
Avireddy, S. Dept. of Inf. Technol., Anna Univ. Chennai, India Perumal, V. ; Gowraj, N. ; Kannan,
R.S. ; Thinakaran, P. ; Ganapthi, S..Gunasekaran, J.R. Prabhu,S. IEEE TRANSACTIONS ON
COMMUNICATIONS, VOL. 60, NO.5, MAY 2012
[4] 2009 IEEE International Advance Computing Conference (IACC 2009) Patiala, India, 6-7 March
2009 Combinatorial Approach for Preventing SQL Injection Attacks ,R. Ezumalai, G. Aghila
Department of Computer Science, Pondicherry University, Puducherry, India.
AUTHORS:
Mohd. Ahmed is currently Assistant professor at the M.H. Saboo Siddik College of
Engineering and has completed his M.E. from Vidyalankar Institute of Technology (VIT),
Mumbai and formerly trainee hardware & network engineer in DSS Mobile communication,
Mumbai. He is having 9 years teaching and 1 year industry experience.
Shaikh Tazreen is currently pursuing B.E. from M.H. Saboo Siddik College of
engineering, Mumbai.
Shaikh Shagufta is currently pursuing B.E. from M.H. Saboo Siddik College of
engineering, Mumbai.
Sayyed Saima is currently pursuing B.E. from M.H. Saboo Siddik College of engineering,
Mumbai.

More Related Content

Similar to Comparison And Implementation of Random4 Algorithm and Hirschberg Algorithm Using Open Source Software for Prevention of SQL Injection Attack

Searchable symmetric encryption security definitions
Searchable symmetric encryption security definitionsSearchable symmetric encryption security definitions
Searchable symmetric encryption security definitions
Conference Papers
 
SQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
SQL Injection Attack Detection and Prevention Techniques to Secure Web-SiteSQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
SQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
ijtsrd
 
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
ijcisjournal
 
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
ijcisjournal
 
DEFCON 23 - Lance buttars Nemus - sql injection on lamp
DEFCON 23 - Lance buttars Nemus - sql injection on lampDEFCON 23 - Lance buttars Nemus - sql injection on lamp
DEFCON 23 - Lance buttars Nemus - sql injection on lamp
Felipe Prado
 
Classification with R
Classification with RClassification with R
Classification with R
Najima Begum
 
A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...
A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...
A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...
IJMER
 
IRJET- Encrypted Negative Password using RSA Algorithm
IRJET- Encrypted Negative Password using RSA AlgorithmIRJET- Encrypted Negative Password using RSA Algorithm
IRJET- Encrypted Negative Password using RSA Algorithm
IRJET Journal
 
IRJET- Penetration Testing using Metasploit Framework: An Ethical Approach
IRJET- Penetration Testing using Metasploit Framework: An Ethical ApproachIRJET- Penetration Testing using Metasploit Framework: An Ethical Approach
IRJET- Penetration Testing using Metasploit Framework: An Ethical Approach
IRJET Journal
 
A New System for Clustering and Classification of Intrusion Detection System ...
A New System for Clustering and Classification of Intrusion Detection System ...A New System for Clustering and Classification of Intrusion Detection System ...
A New System for Clustering and Classification of Intrusion Detection System ...
CSCJournals
 
Advanced Sql Injection ENG
Advanced Sql Injection ENGAdvanced Sql Injection ENG
Advanced Sql Injection ENGDmitry Evteev
 
ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...
ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...
ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...
Ioannis Stais
 
Block cipher encryption for text to-image algorithm
Block cipher encryption for text to-image algorithmBlock cipher encryption for text to-image algorithm
Block cipher encryption for text to-image algorithmIAEME Publication
 
IRJET- Improving Cyber Security using Artificial Intelligence
IRJET- Improving Cyber Security using Artificial IntelligenceIRJET- Improving Cyber Security using Artificial Intelligence
IRJET- Improving Cyber Security using Artificial Intelligence
IRJET Journal
 
Detection of Structured Query Language Injection Attacks Using Machine Learni...
Detection of Structured Query Language Injection Attacks Using Machine Learni...Detection of Structured Query Language Injection Attacks Using Machine Learni...
Detection of Structured Query Language Injection Attacks Using Machine Learni...
AIRCC Publishing Corporation
 
A tool to evaluate symmetric key algorithms
A tool to evaluate symmetric key algorithmsA tool to evaluate symmetric key algorithms
A tool to evaluate symmetric key algorithms
Tharindu Weerasinghe
 
Defcon 17-joseph mccray-adv-sql_injection
Defcon 17-joseph mccray-adv-sql_injectionDefcon 17-joseph mccray-adv-sql_injection
Defcon 17-joseph mccray-adv-sql_injectionAhmed AbdelSatar
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacks
Respa Peter
 
Automating Analysis and Exploitation of Embedded Device Firmware
Automating Analysis and Exploitation of Embedded Device FirmwareAutomating Analysis and Exploitation of Embedded Device Firmware
Automating Analysis and Exploitation of Embedded Device Firmware
Malachi Jones
 
Prevention of SQL injection in E- Commerce
Prevention of SQL injection in E- CommercePrevention of SQL injection in E- Commerce
Prevention of SQL injection in E- Commerce
ijceronline
 

Similar to Comparison And Implementation of Random4 Algorithm and Hirschberg Algorithm Using Open Source Software for Prevention of SQL Injection Attack (20)

Searchable symmetric encryption security definitions
Searchable symmetric encryption security definitionsSearchable symmetric encryption security definitions
Searchable symmetric encryption security definitions
 
SQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
SQL Injection Attack Detection and Prevention Techniques to Secure Web-SiteSQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
SQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
 
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
 
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
Deployment of Reverse Proxy for the Mitigation of SQL Injection Attacks Using...
 
DEFCON 23 - Lance buttars Nemus - sql injection on lamp
DEFCON 23 - Lance buttars Nemus - sql injection on lampDEFCON 23 - Lance buttars Nemus - sql injection on lamp
DEFCON 23 - Lance buttars Nemus - sql injection on lamp
 
Classification with R
Classification with RClassification with R
Classification with R
 
A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...
A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...
A Technique by using Neuro-Fuzzy Inference System for Intrusion Detection and...
 
IRJET- Encrypted Negative Password using RSA Algorithm
IRJET- Encrypted Negative Password using RSA AlgorithmIRJET- Encrypted Negative Password using RSA Algorithm
IRJET- Encrypted Negative Password using RSA Algorithm
 
IRJET- Penetration Testing using Metasploit Framework: An Ethical Approach
IRJET- Penetration Testing using Metasploit Framework: An Ethical ApproachIRJET- Penetration Testing using Metasploit Framework: An Ethical Approach
IRJET- Penetration Testing using Metasploit Framework: An Ethical Approach
 
A New System for Clustering and Classification of Intrusion Detection System ...
A New System for Clustering and Classification of Intrusion Detection System ...A New System for Clustering and Classification of Intrusion Detection System ...
A New System for Clustering and Classification of Intrusion Detection System ...
 
Advanced Sql Injection ENG
Advanced Sql Injection ENGAdvanced Sql Injection ENG
Advanced Sql Injection ENG
 
ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...
ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...
ANOTHER BRICK OFF THE WALL: DECONSTRUCTING WEB APPLICATION FIREWALLS USING AU...
 
Block cipher encryption for text to-image algorithm
Block cipher encryption for text to-image algorithmBlock cipher encryption for text to-image algorithm
Block cipher encryption for text to-image algorithm
 
IRJET- Improving Cyber Security using Artificial Intelligence
IRJET- Improving Cyber Security using Artificial IntelligenceIRJET- Improving Cyber Security using Artificial Intelligence
IRJET- Improving Cyber Security using Artificial Intelligence
 
Detection of Structured Query Language Injection Attacks Using Machine Learni...
Detection of Structured Query Language Injection Attacks Using Machine Learni...Detection of Structured Query Language Injection Attacks Using Machine Learni...
Detection of Structured Query Language Injection Attacks Using Machine Learni...
 
A tool to evaluate symmetric key algorithms
A tool to evaluate symmetric key algorithmsA tool to evaluate symmetric key algorithms
A tool to evaluate symmetric key algorithms
 
Defcon 17-joseph mccray-adv-sql_injection
Defcon 17-joseph mccray-adv-sql_injectionDefcon 17-joseph mccray-adv-sql_injection
Defcon 17-joseph mccray-adv-sql_injection
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacks
 
Automating Analysis and Exploitation of Embedded Device Firmware
Automating Analysis and Exploitation of Embedded Device FirmwareAutomating Analysis and Exploitation of Embedded Device Firmware
Automating Analysis and Exploitation of Embedded Device Firmware
 
Prevention of SQL injection in E- Commerce
Prevention of SQL injection in E- CommercePrevention of SQL injection in E- Commerce
Prevention of SQL injection in E- Commerce
 

Recently uploaded

Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 

Recently uploaded (20)

Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 

Comparison And Implementation of Random4 Algorithm and Hirschberg Algorithm Using Open Source Software for Prevention of SQL Injection Attack

  • 1. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 27 Comparison And Implementation Of Random4 Algorithm And Hirschberg Algorithm Using Open Source Software For Prevention Of SQL Injection Attack 1 Mohammed Ahmed, 2 Sayyed Saima, 3 Shaikh Shagufta, 4 Shaikh Tazreen (Department of Computer Engineering) M.H. Saboo Siddik College of Engineering, Clare Road, Byculla, Mumbai-400008, India. ABSTRACT SQL injection attacks are easy way to attack the web applications and gain access to the private data in a database. Using different types of the SQL attacks one can easily gain access, modify the database or can even remove it. Details such as fields and table names are required for a hacker to modify a database. Hence, to provide the increased amount of security to users and their data, different types of techniques are used such as Random4 algorithm, which is based on randomization and used to encrypt the user input, Hirschberg algorithm which is a divide and conquer technique used to match the query pattern. In this paper we are providing a comparative study and implementation of these prevention techniques using open source software. Keywords SQL injection, Random4, Hirschberg. 1. INTRODUCTION According to the White Hat report on the web security vulnerabilities in the year 2011 it is shown that nearly 14-15 % of web application attacks account for SQL Injection [1]. SQL Injection Attack is a type of code-injection attack [2] which penetrates in the web applications and gets illegal access to the databases, it is very easy for the attackers to inject the code in the web page and gain access to all the databases, or to modify or even delete the databases. This type of attack is mainly caused due to improper validation of user input. [3]. With the leading attacks on the web applications it is very important to prevent them. So, different techniques are used for the prevention, named as Random4 Algorithm which is based on randomization. It will take user input and encrypt it using Random4 Look up table, the encryption of the current characters will be based on the next character. Second technique is Hirschberg Algorithm which is a divide and conquer version of the Needleman-Wunsch algorithm [4] and is based on pattern matching of the query. Any input given to the web application goes in the form of query, so using Hirschberg one standard query format will be set and if the received pattern of
  • 2. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 28 the query from web page is not matched with the set query pattern then no one can get access to the web page or the databases. The following prevention techniques are chosen for comparison and implementation named as Random4 Algorithm and Hirschberg Algorithm. IMPLEMENTED ALGORITHMS: I– RANDOM4 ALGORITHM: Input: input String inp[] Output: Encrypted String en[] N: Length of inp[] R[]: Random values of character For i=1 to N If(inp[i+1]==null || inp[i+1]=lowercase) Then en[i]=R[lower] End { if } Else If( inp[i+1]=uppercase) Then en[i]=R[upper] End { Else if } Else If( inp[i+1]=number) Then en[i]=[number] End { Else if } Else If( inp[i+1]=special_character) Then en[i]=[special] End { Else if } End { For } Return en[] Random4 is based on the randomization and is used to convert the input into the cipher text. Any input in the web forms will be containing numbers, uppercase, lowercase or special characters. Using the look up table, the user input will be converted into cipher text. Each character in the input can have 72 combinations. Hence there will be 726 combinations possible for 6 character inputs possible. To encrypt the input, each input character is given four random values. A sample look up table is given below. The first column in the table is for lower case, second is for upper case, third is for numbers and fourth is for special characters now based on the next input character, one of these four values is substituted for a given character. For example, if the input is provided in the form of username as xY@2 then the first character ‘x’ is given four Random values in the look up table based on the next input character which is upper case here, the value “R[Upper]” is chosen. If the next character was lower case then the value “R[lower]” is chosen. If the next character was number, the value “R[number]” is chosen. If the next character was special character then value “R[Special]” is chosen.
  • 3. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 29 Table 1: Look Up table II- HIRSCHBERG ALGORITHM: Hirschberg’s algorithm is a divide and conquer version of Needleman-Wunsch algorithm. In this algorithm one standardized form of an SQL Query is set for the login. This algorithm works on the logic 1 and 0. Each word in the login query is considered as a column and row wise for checking. When the user enters the input in the web page, it goes into the form of query. Each word of the query will be verified with the predefined set query and if the query word is perfectly matched then it will be marked as 1 otherwise 0. If in the whole table a single 0 is found then it will be considered as an attack and system will block the access. For example if the username and password entered as ‘Soni’ and ‘1234’ respectively. Then the query will be formed as SELECT * FROM logintable WHERE username=’Soni’ AND password=’1234’; In this query each format of the query will be matched and it will be considered as a correct user. Now suppose the SQL injection query Username: soni and password: ‘abcd’ OR ‘1’=’1 Here after ‘abcd’ it will be detected as SQL injection because after password’s quotes (‘‘) it will not get AND statement instead it will get OR statement which is not in the predefined query. So in this way the attack is prevented.
  • 4. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 30 Table 2: Look Up table 3.IMPLEMENTATION: I – RANDOM4 ALGORITHM: package com.java.utility; public class Random4 { // a-z 26 A-Z 26 0-9 10 Special 25 Total 87 public char[] mainList= { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', '0','1','2','3','4','5','6','7','8','9', '!','@','#','$','%','^','&','*','(',')','-','',';','"',''',',' }; public char[] firstList= { ',',''','"',';','','-',')','(','*','&','^','%','$','#','@','!', '9','8','7','6','5','4','3','2','1','0', 'Z','Y','X','W','V','U','T','S','R','Q','P','O','N','M','L','K','J','I','H','G','F','E','D','C','B','A', 'z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a' };
  • 5. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 31 public char[] secondList= { '0','1','2','3','4','5','6','7','8','9', '!','@','#','$','%','^','&','*','(',')','-','',';','"',''',',', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', }; public char[] thirdList= { 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m', 'z','y','x','w','v','u','t','s','r','q','p','o','n','A','B','C','D','E','F','G','H','I','J','K','L','M', '9','8','7','6','5','4','3','2','1','0', ',',''','"',';','','-',')','(','*','&','^','%','$','#','@','!' }; public char[] fourthList= { '5','6','7','8','9','0','1','2','3','4', 'n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M', '!','@','#','$','%','^','&','*','(',')','-','',';','"',''',',', 'm','l','k','j','i','h','g','f','e','d','c','b','a','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; //Encryption module public String encrypt(String data) { String encdata = ""; for(int i=0;i<data.length();i++) { char get = data.charAt(i); String getcase = "lower"; if(i!=data.length()-1) { char findcase = data.charAt(i+1); getcase = getCase(findcase); } int position = getPosition(get); if(position == -1) { encdata = encdata + get; } else {
  • 6. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 32 if(getcase.equals("lower")) { encdata = encdata + firstList[position]; } else if(getcase.equals("upper")) { encdata = encdata + secondList[position]; } else if(getcase.equals("number")) { encdata = encdata + thirdList[position]; } else if(getcase.equals("special")) { encdata = encdata + fourthList[position]; } System.out.println("Case : "+getcase+" "+get+" a : "+encdata); } } return encdata; } public String getCase(char ch) { String charcase = ""; int val = (int)ch; if(val>64 && val<91) { charcase = "upper"; } else if(val>96 && val<124) { charcase = "lower"; } else if(val>47 && val<58) { charcase = "number"; } else { charcase = "special"; } return charcase; } public int getPosition(char ch) { int position = -1;
  • 7. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 33 for(int i=0;i<mainList.length;i++) { if(ch == mainList[i]) { position = i; break; } } return position; } II – HIRSCBERG ALGORITHM: package com.java.utility; import java.util.StringTokenizer; import java.util.Vector; public class Hirshberg { boolean analysis = false;//not allowed //true allowed Vector<Object> xAxis; Vector<Object> yAxis; Vector<Object> result; Vector<Object> output; String applicationQuery; // Setting the predefined Query pattern public Hirshberg() { xAxis = new Vector<Object>(); yAxis = new Vector<Object>(); keywords(); } public void keywords() { xAxis.add("SELECT"); xAxis.add("*"); xAxis.add("FROM"); xAxis.add("LoginTable"); xAxis.add("WHERE"); xAxis.add("username"); xAxis.add("="); xAxis.add("'"); xAxis.add(""); xAxis.add("'"); xAxis.add("AND"); xAxis.add("password");
  • 8. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 34 xAxis.add("="); xAxis.add("'"); xAxis.add(""); xAxis.add("'"); xAxis.add(";"); } //pattern matching module public boolean Checker(String query) { try { result = new Vector<Object>(); applicationQuery = query.trim(); StringTokenizer st = new StringTokenizer(applicationQuery, " "); while (st.hasMoreElements()) { String e = st.nextToken(); if (!e.contains("'")) { result.add(e); } else { String r = e; StringTokenizer stk = new StringTokenizer(r, "'"); while (stk.hasMoreElements()) { result.add("'"); result.add(stk.nextElement()); result.add("'"); } } } System.err.println(result.size()); for (int z = 0; z < result.size(); z++) { if (result.elementAt(z).toString().equals("'")) { if (result.elementAt(z + 2).toString().equals("'")) { result.setElementAt("", (z + 1)); z = z + 3; } } } System.out.println(xAxis); System.err.println(result); //Analysis Module output = new Vector<Object>(); int count = 0; for (int i = count; i < xAxis.size(); i++) { for (int j = count; j < result.size(); j++) { String x = xAxis.elementAt(i).toString(); String y = result.elementAt(j).toString();
  • 9. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 35 System.out.println("x== " + x + " y== " + y); if (x.equalsIgnoreCase(y)) { output.add("1"); analysis = true; count++; break; } else { analysis = false; count++; break; } } if (!analysis) { break; } } } catch (Exception e) { e.printStackTrace(); } return analysis; } } 4. RESULTS:
  • 10. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 36
  • 11. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 37
  • 12. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 38 5. COMPARATIVE STUDY: Parameters Hirschberg Random4 Proxy Overhead No No Time Complexity Less More Space Complexity Less Bit more Encryption No encryption (query pattern is matched only) User Input Computational Overhead Less Bit more Table 3: Comparative Study 6. CONCLUSION: This paper presents the methods for preventing the web applications from SQL injection attack. And by the above comparative study, we have concluded that Hirschberg algorithm is easy to implement, it has less time and space complexity and no proxy or computational overhead. On the other side Random4 is also a powerful technique because of encryption but due to that time
  • 13. Advanced Computational Intelligence: An International Journal (ACII), Vol.2, No.2, April 2015 39 and space complexity is more than Hirschberg Algorithm. It is easy to implement, and it has no proxy or computational overhead. REFERENCES: [1] https://www.whitehatsec.com/resource/stats.html [2] W.G halfond and A. orso AMNESIA: Analysis and monitoring for neutrilizing SQL injection attacks.in proceedings of the IEEE and ACM International Conference on Automated Software Engineering (ASE-2005), Long Beach, CA, USA, NOV 2005. [3] Random4: An Application Specific Randomized Encryption Algorithm to prevent SQL Injection Avireddy, S. Dept. of Inf. Technol., Anna Univ. Chennai, India Perumal, V. ; Gowraj, N. ; Kannan, R.S. ; Thinakaran, P. ; Ganapthi, S..Gunasekaran, J.R. Prabhu,S. IEEE TRANSACTIONS ON COMMUNICATIONS, VOL. 60, NO.5, MAY 2012 [4] 2009 IEEE International Advance Computing Conference (IACC 2009) Patiala, India, 6-7 March 2009 Combinatorial Approach for Preventing SQL Injection Attacks ,R. Ezumalai, G. Aghila Department of Computer Science, Pondicherry University, Puducherry, India. AUTHORS: Mohd. Ahmed is currently Assistant professor at the M.H. Saboo Siddik College of Engineering and has completed his M.E. from Vidyalankar Institute of Technology (VIT), Mumbai and formerly trainee hardware & network engineer in DSS Mobile communication, Mumbai. He is having 9 years teaching and 1 year industry experience. Shaikh Tazreen is currently pursuing B.E. from M.H. Saboo Siddik College of engineering, Mumbai. Shaikh Shagufta is currently pursuing B.E. from M.H. Saboo Siddik College of engineering, Mumbai. Sayyed Saima is currently pursuing B.E. from M.H. Saboo Siddik College of engineering, Mumbai.