• No results found

Detecting SQL Injection and Cross-Site Scripting Attacks in Web Applications

N/A
N/A
Protected

Academic year: 2021

Share "Detecting SQL Injection and Cross-Site Scripting Attacks in Web Applications"

Copied!
7
0
0

Loading.... (view fulltext now)

Full text

(1)

[email protected] all rights reserved www.ijcsee.org.uk

Detecting SQL Injection and Cross-Site Scripting

Attacks in Web Applications

K. Vijay Bhaskar1 Asst. Professor, CSE Dept

Geethanjali College of Engineering & Technology, Cheryal, Hyderabad. [email protected] K. Naresh Babu2 Asst. Prof. CSE Dept, Geethanjali College of Engineering & Technology, Cheryal, Hyderabad. [email protected] S. Ramanjaneyulu3 Asst. Prof. CSE Dept Geethanjali College of Engineering & Technology, Cheryal, Hyderabad. [email protected]

Abstract:

Web applications have become one of the most important ways to provide a broad range of services to users. Almost in all of them user is authenticated before providing access to backend database for storing all the information by the queries. As well as which contains client side scripting languages such as JavaScript but this growing of JavaScript is increasing serious security vulnerabilities in web application too, such as cross-site scripting (CSS).In this paper, a well-designed injection will provide access to malicious or unauthorized users and mostly achieved through SQL injection and Cross -site scripting (CSS). This paper which describes how threats are attacked to applications. These attacks are identified by different approaches using regular expressions.

Keywords - SQL injection, Cross -site scripting (CSS), JavaScript, Web application.

1.

Introduction

In recent years the development of internet had huge impact on commerce and culture. As each coin has two sides; The World Wide Web has both pros and cons. On one hand where the Web can dramatically lower costs to organizations for distributing information, products, and services on the other computers that make up the Web are vulnerable. Security was, still is, and always will be one of the major concerns that critical systems have, especially when deployed in the World Wide Web, accessible through a web browser. Most security concerns are now related with application level.

Today almost everyone in touch of computer is connected online and to serve millions of users huge amount of data is stored in databases connected to some web application all across the globe. These users keep on inserting, querying and updating data in these databases. For all these operations to occur successfully a well-designed user interface is very important. Furthermore, these applications play a vital role in maintaining security of data stored in these databases. Web applications which are not very secured allow well-designed injection to perform unwanted operations on backend database. In the last couple of years, attacks against the Web application layer have required increased attention from security

(2)

[email protected] all rights reserved www.ijcsee.org.uk

professionals. This is because no matter how strong your firewall rulesets are or how diligent your patching mechanism may be, if your Web application developers haven't followed secure coding practices, attackers will walk right into your systems through port 80.

The two main attack techniques that have been used widely are SQL Injection and Cross Site Scripting attacks. SQL Injection refers to the technique of inserting SQL meta-characters and commands into Web-based input fields in order to manipulate the execution of the back-end SQL queries. These are attacks directed primarily against another organization's Web server.

Cross Site Scripting attacks work by embedding script tags in URLs and enticing unsuspecting users to click on them, ensuring that the malicious Javascript gets executed on the victim’s web browser on the client-side where as SQL injection related web vulnerability is involved with server side. These attacks leverage the trust between the user and the server and the fact that there is no input/output validation on the server to reject Javascript characters. These vulnerabilities could be exploited by SQL injection or XSS to gain control over the online web application database or stealing users information.

2.

Related Work

This paper describes techniques used to detect SQL Injection and Cross Site Scripting (CSS) attacks against your networks. Based on these two categories of Web-based attacks we discuss how to carry them out, their impact, and how to prevent these attacks using better coding and design practices. We take the popular open-source IDS Snort, and compose regular-expression based rules for detecting these attacks. Incidentally, the default rulesets in Snort does contain signatures for detecting cross-site scripting, but these can be evaded easily. Most

of them can be evaded by using the hex-encoded values.

We have written multiple rules for detecting the same attack depending upon the organization's level of paranoia. If you wish to detect each and every possible SQL Injection attack, then you simply need to watch out for any occurrence of SQL meta-characters such as the single-quote, semi-colon or double-dash. Similarly, a paranoid way of checking for CSS attacks would be to simply watch out for the angled brackets that signify an HTML tag. But these signatures may result in a high number of false positives. To avoid this, the signatures can be modified to be made accurate. Each of these signatures can be used with or without other verbs in a Snort signature using the PCRE

keyword. These signatures can also be used with a utility like grep to go through the Web-server's logs. But the caveat is that the user input is available in the Web server's logs only if the application uses GET requests. Data about POST requests is not available in the Web server's logs.

3.

SQL Injection and CSS

3.1. Threats in SQL injection

SQL injection attacks allow attackers to spoof identity, tamper with existing data, cause repudiation issues such as voiding transactions or changing balances, allow the complete disclosure of all data on the system, destroy the data or make it otherwise unavailable, and become administrators of the database server. SQL Injection is very common with PHP and ASP applications due to the prevalence of older functional interfaces. Due to the nature of programmatic interfaces available, J2EE and ASP.NET applications are less likely to have easily exploited SQL injections. The severity of SQL Injection attacks is limited by the attacker’s

(3)

[email protected] all rights reserved www.ijcsee.org.uk

skill and imagination, and to a lesser extent, defense in depth countermeasures, such as low privilege connections to the database server and so on.

3.2.

Regular Expressions for

SQL Injection

An important point to keep in mind while choosing your regular expression(s) for detecting SQL Injection attacks is that an attacker can inject SQL into input taken from a form, as well as through the fields of a cookie. The input validation logic must consider every type of input that originates from the user, either from form fields or cookie information, as suspect. Also if you discover too many alerts coming in from a signature that looks out for a single-quote or a semi-colon, it just might be that one or more of these characters are valid inputs in cookies created by your Web application. Therefore, it needs to evaluate each of these signatures for Web application.

A Trivial regular expression is also used to detect SQL injection attacks to watch out for SQL specific meta-characters such as the single-quote (') or the double-dash (--). In order to detect these characters and their hex equivalents, the following regular expression may be used:

3.2.1.Detecting SQL Injection by

Meta-Characters

Explanation:

We first detect either the hex equivalent of the single-quote, the single-quote itself or the presence of the double-dash. These are SQL characters for MS SQL Server and Oracle, which denote the beginning of a comment, and everything that follows is ignored. Additionally, if you're using MySQL, you need to check for presence of the '#' or its hex-equivalent. We do

not need to check for the hex-equivalent of the double-dash, because it is not an HTML meta-character and will not be encoded by the browser. Also, if an attacker tries to manually modify the double-dash to its hex value of %2D (using a proxy like Achilles), the SQL Injection attack fails.

The above regular expression would be added into a new Snort rule as follows:

alert tcp EXTERNAL_NET any ->

$HTTP_SERVERS

$HTTP_PORTS

(msg:"NII

SQL Injection-Paranoid";

flow:to_server,established;uricontent:"

In this case, the uricontent keyword has the value ".pl", because in our test environment, the CGI scripts are written in Perl. Depending upon your particular application, this value may be either ".php", or ".asp", or ".jsp", etc.

In the previous regular expression, we detect the double-dash because there may be situations where SQL injection is possible even without the single-quote. Take, for instance, an SQL query which has the where clause containing only numeric values. Something like:

Select value1 ,value2 , num_value3 from database where num_value3=

some_user_supplied_number

In this case, the attacker may execute an additional SQL query, by supplying an input like:

3; insert values into some_other_table

Finally, pcre modifiers 'i' and 'x' are used in order to match without case sensitivity and to ignore whitespaces, respectively.The above signature could be additionally expanded to detect the occurrence of the semi-colon as well. However, the semi-colon has a tendency to occur as part of normal HTTP traffic. In order to

(4)

[email protected] all rights reserved www.ijcsee.org.uk

reduce the false positives from this, and also from any normal occurrence of the single-quote and double-dash, the above signature could be modified to first detect the occurrence of the = sign. User input will usually occur as a GET or a POST request, where the input fields will be reflected as:

username=some_user_supplied_value & password=some_user_supplied_value

Therefore, the SQL injection attempt would result in user input being preceded by a = sign or its hex equivalent.

3.2.2.Detecting SQL Injection with

the UNION keyword

- the single-quote and its hex-equivalent

union - the keyword union

Similar expressions can be written for other SQL queries such as select, insert, update, delete, drop, and so on.

In this stage, the attacker has discovered that the Web application is vulnerable to SQL injection, he will try to exploit it. If he realizes that the back-end database is on an MS SQL server, he will typically try to execute one of the many dangerous stored and extended stored procedures. These procedures start with the letters 'sp' or 'xp' respectively. Typically, he would try to execute the 'xp_cmdshell' extended procedure, which allows the execution of Windows shell commands through the SQL Server. The access rights with which these commands will be executed are those of the account with which SQL Server is running -- usually Local System. Alternatively, he may also try and modify the registry using procedures such as xp_regread, xp_regwrite, etc.

3.2.3.Detecting

SQL

Injection

attacks on a MS SQL Server

Explanation:

exec - the keyword required to run the stored or

extended procedure.

(\s|\+)+ - one or more whitespaces or their HTTP

encoded equivalents.

(s|x)p - the letters 'sp' or 'xp' to identify stored or extended procedures respectively.

\w+ - one or more alphanumeric or underscore characters to complete the name of the procedure.

3.3.

Threats in CSS:

Cross- Site Scripting (CSS) are the kinds of attacks on the web applications where an attacker is able to get control of user’s browser for executing a malicious script which is mainly in the form of HTML/JavaScript code. The attackers will inject JavaScript, VBScript, ActiveX, HTML, or Flash into a vulnerable application to fool a user in order to gather data from them. It mainly lies in the context of trust of the web application’s site. In result to it an attacker may be able to reach any sensitive browser resource related to the web application (passively or actively) if in case the embedded code gets executed successfully. Everything from account hijacking, changing of user settings, cookie theft/poisoning, or false advertising is possible. New malicious users are being found every day for CSS attacks. Examples -cookies, session IDs, etc. This problem has been figured out in two fold. Firstly, by design the browsers are not secure. They have been created with the motive of producing outputs with respect to a request and it is not considered the main duty of a browser to figure out whether a piece of code is doing something malicious. Secondly, because of lack in programming knacks and timeline constraint

(5)

[email protected] all rights reserved www.ijcsee.org.uk

web application developers are unable to create secure sites.

3.4.Regular Expressions for

Cross Site Scripting (CSS)

When launching a cross-site scripting attack, or testing a Website's vulnerability to it, the attacker may first issue a simple HTML formatting tag such as <b> for bold, <i> for italic or <u> for underline. Alternatively, he may try a trivial script tag such as

<script>alert("OK")</script>. This is likely because most of the printed and online literature on CSS use this script as an example for determining if a site is vulnerable to CSS. These attempts can be trivially detected. However, the advanced attacker may attempt to camouflage the entire string by entering its Hex equivalents. So the <script> tag would appear as

%3C%73%63%72%69%70%74%3E. On the other hand, the attacker may actually use a Web Application Proxy like Achilles and reverse the browser's automatic conversion of special characters such as < to %3C and > to %3E. So the attack URL will contain the angled brackets instead of their hex equivalents as would otherwise normally occur.

The following regular expression checks for attacks that may contain HTML opening tags and closing tags <> with any text inside. It will catch attempts to use <b> or <u> or <script>. The regexp is case-insensitive. We also need to check for the presence of angled brackets, as well as their hex equivalents, or (%3C|<). To detect the hex conversion of the entire string, we must check for the presence of numbers as well as the % sign in the user input, in other words, the use of [a-z0-9%]. This may sometimes result in false-positives, but most of the time will detect the actual attack.

3.4.1.Simple CSS attack

Explanation:

((\%3C)|<) - check for opening angle bracket or

hex equivalent

((\%2F)|\/)* - the forward slash for a closing tag or its hex equivalent

[a-z0-9\%]+ - check for alphanumeric string inside the tag, or hex representation of these

((\%3E)|>) - check for closing angle bracket or hex equivalent

Snort signature:

alert tcp $EXTERNAL_NET any ->

$HTTP_SERVERS

$HTTP_PORTS

(msg:"NII Cross-site scripting attempt";

flow:to_server,established;

Cross-site scripting can also be accomplished by using the <img src=> technique. The existing default snort signature can be easily evaded. The one supplied in section 3.2 will be much tougher to evade.

3.4.2. CSS attack by "img src"

Explanation:

(\%3C)) opening angled bracket or hex equivalent

(\%69)|i|(\%49))((\%6D)|m|(\%4D))((\%67)|g| (\%47) the letters 'img' in varying combinations of ASCII, or upper or lower case hex equivalents

[^\n]+ any character other than a new line following the <img

(\%3E)|>) closing angled bracket or hex equivalent

3.4.3. Paranoid regex for CSS attacks

Explanation:

This signature simply looks for the opening HTML tag, and its hex equivalent, followed by one or more characters other than the newline, and then followed by the closing tag or its hex

(6)

[email protected] all rights reserved www.ijcsee.org.uk

equivalent. This may end up giving a few false positives depending upon how your Web application and Web server are structured, but it is guaranteed to catch anything that even remotely resembles a cross-site scripting attack.

4. Conclusion

In this paper, we've presented different types of regular expression signatures that can be used to detect SQL Injection and Cross Site Scripting attacks. Some of the signatures are paranoid, in that they will raise an alert even if there is a hint of an attack. We recommend that these signatures be taken as a starting point for tuning your IDS or log analysis methods, in the detection of these Web application layer attacks. After a few modifications, and after taking into account the non-malicious traffic that occurs as part of your normal Web transactions, you should be able to accurately detect these attacks. This is my analysis report on most well-known injection problem, cross-site scripting. I didn’t implement or run any tools to experiment. I use their algorithms and procedures to understand, how they work and I summarize their successes as well as limitations. I didn’t find any method that is 100% perfect. Even I am not presenting any tool that can detect XSS. I keep this task for my future movement. Web Application performs many critical tasks and deals with sensitive information. In our daily life, we pass our so many confidential data through this media. So this platform must be secure and stable. Nowadays, web application facing security problem for these injection problem and XSS is one of them. Researchers are doing hard work to make our web application platform more reliable. This survey report will help them fortheir further research on this issue. I believe that this report provides summary of all the methodologies, used for detecting XSS and their limitations and success as well.

References:

[1] S. M. Metev, and V. P. Veiko, “Laser Assisted Microtechnology,” 2nd ed., R. M. Osgood, Jr., Ed. Berlin, Germany: Springer-Verlag, 1998.

[2] Z. Su and G. Wassermann, “The essence of command Injection Attacks in Web Applications,” In Proceeding of the 33rdAnnual Symposium on Principles of Programming Languages, USA: ACM, January 2006, pp. 372-382.

[3] C. Yue and H. Wang, “Charactering Insecure JavaScript Practice on the Web,” In Proceedings of the 18th International Conference on the World Wide Web, Madrid, Spain: ACM, April 20-24, 2005. [4] Sruthi Bandhakavi, Prithvi Bisht, P. Madhusudan, CANDID: Preventing SQL Injection Attacks using Dynamic Candidate Evaluations, 2007, Alexandria, Virginia, USA, ACM.

[5] A Tajpour, A., Masrom, M., Heydari, M.Z., and Ibrahim, S., SQL injection detection and prevention tools assessment. Proc. 3rd IEEE International Conference on Computer Science and Information

Technology (ICCSIT’10) 9-11 July (2010), 518-522

[6] L Halfond W. G., Viegas, J., and Orso, A., A Classification of SQL-Injection Attacks and

Countermeasures. In Proc. of the Intl. Symposium on Secure Software Engineering, Mar. (2006).

[7]http://www.owasp.org/index.php/Top_10_2010-A1-Injection, retrieved on 13/01/2010

[8] Fu, X., Lu, X., Peltsverger, B., Chen, S., Qian, K., and Tao, L., A Static Analysis Framework for Detecting SQL Injection Vulnerabilities. Proc. 31st Annual International Computer Software and

Applications Conference 2007 (COMPSAC 2007),

24-27 July (2007), 87-96.

[9] Ruse, M., Sarkar, T., and Basu. S., Analysis & Detection of SQL Injection Vulnerabilities via Automatic Test Case Generation of Programs. Proc.

(7)

[email protected] all rights reserved www.ijcsee.org.uk 10th Annual International Symposium on

Applications and the Internet (2010), 31-37 [10] Thomas, S., Williams, L., and Xie, T., On automated prepared statement generation to remove SQL injection vulnerabilities. Information and

Software Technology, Volume 51 Issue 3, March

(2009), 589–5981

[11] Roichman, A., Gudes, E., Fine-grained Access Control to Web Databases. Proceedings of 12th

SACMAT Symposium, France (2007).

[12] Kemalis, K. and T. Tzouramanis. SQL-IDS: A Specification-based Approach for SQLinjection Detection. SAC’08. Fortaleza, Ceará, Brazil, ACM

(2008), 2153 2158.

[13] Junjin, M., An Approach for SQL Injection Vulnerability Detection. Proc. of the 6th International Conference on Information

Technology: New Generations, Las Vegas, Nevada,

April (2009), 1411-1414.

[14] TBoyd S.W. and Keromytis, A.D., SQLrand: Preventing SQL Injection Attacks. Proceedings of the 2nd Applied Cryptography and Network Security

(ACNS’04) Conference, June (2004), 292–302.

[15] McClure, R.A. and Kruger, I.H., SQL DOM: compile time checking of dynamic SQL statements.

27th International Conference on Software

References

Related documents

x An automated detection system is proposed with the aim to discover injection points in a web application and possible malicious JavaScript injection vulnerabilities..

• The Attack Generator / Checker takes a list of taint sets (one for each sensitive sink), creates candidate at- tacks by modifying the inputs in the taint sets using a library of

Our attack-creation technique generates a set of concrete inputs, executes the program under test with each input, and dynamically observes whether data flows from an input to

Because of various Web server vulnerabilities and procedure of not strict, the cause for Web server script attacks was increasing, its are mostly through the ASP or PHP

Cross-Site Scripting attacks (XSS attacks for short) are those attacks against web applications in which an attacker gets control of a user’s browser in or- der to execute a

 Browser exploitation: Malicious script can redirect client browsers to an attacker’s site, so that the attacker is able to take advantage of specific security hole in web browsers

In conclusion, this paper describes the implementation of a program that generates XSS and SQL INJECTION mitigation aspects that can be applied to mitigate

Nowadays Cross-Site Scripting (XSS) attacks are the common vulnerable attack in web application through the injection of malicious code in advanced HTML tags and