Robust Defence against XSS through Context Free Grammar



Similar documents
Cross Site Scripting Prevention

HOD of Dept. of CSE & IT. Asst. Prof., Dept. Of CSE AIET, Lko, India. AIET, Lko, India

Protection, Usability and Improvements in Reflected XSS Filters

A Tale of the Weaknesses of Current Client-Side XSS Filtering

XSS-GUARD : Precise Dynamic Prevention of Cross Site Scripting (XSS) Attacks

CS 558 Internet Systems and Technologies

Check list for web developers

Webapps Vulnerability Report

A Server and Browser-Transparent CSRF Defense for Web 2.0 Applications. Slides by Connor Schnaith

Web Application Security

Client vs. Server Implementations of Mitigating XSS Security Threats on Web Applications

Cross Site Scripting in Joomla Acajoom Component

Document Structure Integrity: A Robust Basis for Cross-Site Scripting Defense

Exploitation of Cross-Site Scripting (XSS) Vulnerability on Real World Web Applications and its Defense

Recommended Practice Case Study: Cross-Site Scripting. February 2007

What is Web Security? Motivation

Intrusion detection for web applications

Creating Stronger, Safer, Web Facing Code. JPL IT Security Mary Rivera June 17, 2011

Client Side Filter Enhancement using Web Proxy

Bug Report. Date: March 19, 2011 Reporter: Chris Jarabek

WHITE PAPER. FortiWeb and the OWASP Top 10 Mitigating the most dangerous application security threats

Analysis of Browser Defenses against XSS Attack Vectors

Phishing by data URI

Hack Proof Your Webapps

The Top Web Application Attacks: Are you vulnerable?

A Novel Frame Work to Detect Malicious Attacks in Web Applications

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

Toward A Taxonomy of Techniques to Detect Cross-site Scripting and SQL Injection Vulnerabilities

How To Fix A Web Application Security Vulnerability

Where every interaction matters.

Detect and Sanitise Encoded Cross-Site Scripting and SQL Injection Attack Strings Using a Hash Map

Recent Advances in Web Application Security

Web Forensic Evidence of SQL Injection Analysis

Acunetix Website Audit. 5 November, Developer Report. Generated by Acunetix WVS Reporter (v8.0 Build )

Detection and mitigation of Web Services Attacks using Markov Model

Web Application Security. Vulnerabilities, Weakness and Countermeasures. Massimo Cotelli CISSP. Secure

Project 2: Web Security Pitfalls

Detection of SQL Injection and XSS Vulnerability in Web Application

A Multi agent Scanner to Detect Stored XSS Vulnerabilities

Detection and Prevention of SQL Injection Attacks

WEB ATTACKS AND COUNTERMEASURES

Bank Hacking Live! Ofer Maor CTO, Hacktics Ltd. ATC-4, 12 Jun 2006, 4:30PM

INTRUSION PROTECTION AGAINST SQL INJECTION ATTACKS USING REVERSE PROXY

FINAL DoIT v.4 PAYMENT CARD INDUSTRY DATA SECURITY STANDARDS APPLICATION DEVELOPMENT AND MAINTENANCE PROCEDURES

HTTPParameter Pollution. ChrysostomosDaniel

Magento Security and Vulnerabilities. Roman Stepanov

A Survey on Security and Vulnerabilities of Web Application

Application security testing: Protecting your application and data

Detecting and Exploiting XSS with Xenotix XSS Exploit Framework

Security Research Advisory IBM inotes 9 Active Content Filtering Bypass

Web applications. Web security: web basics. HTTP requests. URLs. GET request. Myrto Arapinis School of Informatics University of Edinburgh

IJMIE Volume 2, Issue 9 ISSN:

A Tale of the Weaknesses of Current Client-side XSS Filtering

Web Application Security Considerations

Cross-Site Scripting

A DYNAMIC TOOL FOR DETECTION OF XSS ATTACKS IN A REAL-TIME ENVIRONMENT

FINAL DoIT v.8 APPLICATION SECURITY PROCEDURE

Protect Your IT Infrastructure from Zero-Day Attacks and New Vulnerabilities

How to break in. Tecniche avanzate di pen testing in ambito Web Application, Internal Network and Social Engineering

(WAPT) Web Application Penetration Testing

Introduction: 1. Daily 360 Website Scanning for Malware

Defending against XSS,CSRF, and Clickjacking David Bishop

Ruby on Rails Secure Coding Recommendations

WEB SECURITY CONCERNS THAT WEB VULNERABILITY SCANNING CAN IDENTIFY

EVALUATING COMMERCIAL WEB APPLICATION SECURITY. By Aaron Parke

CSE598i - Web 2.0 Security OWASP Top 10: The Ten Most Critical Web Application Security Vulnerabilities

Double guard: Detecting Interruptions in N- Tier Web Applications

Hunting Cross-Site Scripting Attacks in the Network

SECURE APPLICATION DEVELOPMENT CODING POLICY OCIO TABLE OF CONTENTS

LASTLINE WHITEPAPER. Using Passive DNS Analysis to Automatically Detect Malicious Domains

Web Application Guidelines

Adobe Systems Incorporated

Advanced Web Security, Lab

SQL INJECTION ATTACKS By Zelinski Radu, Technical University of Moldova

ArcGIS Server Security Threats & Best Practices David Cordes Michael Young

LASTLINE WHITEPAPER. Large-Scale Detection of Malicious Web Pages

Application Security Testing. Erez Metula (CISSP), Founder Application Security Expert

Rational AppScan & Ounce Products

Enhanced Model of SQL Injection Detecting and Prevention

Network Monitoring using MMT:

Still Aren't Doing. Frank Kim

Spam Detection Using Customized SimHash Function

Advancements in Botnet Attacks and Malware Distribution

Detecting Web Application Vulnerabilities Using Open Source Means. OWASP 3rd Free / Libre / Open Source Software (FLOSS) Conference 27/5/2008

EECS 398 Project 2: Classic Web Vulnerabilities

Threat Modeling/ Security Testing. Tarun Banga, Adobe 1. Agenda

Development and Industrial Application of Multi-Domain Security Testing Technologies. Innovation Sheet Model Inference Assisted Evolutionary Fuzzing

Enterprise Application Security Workshop Series

OWASP Top Ten Tools and Tactics

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

Cross-site site Scripting Attacks on Android WebView

Preparing for the Cross Site Request Forgery Defense

Study of Cross-Site Scripting Attacks and Their Countermeasures

Cyber Security Workshop Ethical Web Hacking

Transcription:

Robust Defence against XSS through Context Free Grammar 1 Divya Rishi Sahu, 2 Deepak Singh Tomar 1,2 Dept. of CSE, MANIT, Bhopal, MP, India Abstract JavaScript is one of the world s most widely adopted scripting languages among web developers. It is intended to provide enhanced user interface. On the other hand, researchers acquired that commonly used browser such as Chrome, Firefox, IE, etc. suffers from JavaScript bugs. Snippets written in JavaScript may also suffer from Cross Site Scripting potential security threat due to the security unconsciousness of developers. Cross Site Scripting occurs due to the injection of snippets such as JavaScript through the input field of web applications. In this paper firstly the way of exploiting Cross Site Scripting (XSS) has been acquainted. Mainly focuses on the XSS attacks, in which malicious snippets is injected through the address bar of browser. Secondly a context free grammar (CFG) has been developed for detecting XSS vulnerable snippets written in JavaScript. Finally, developed grammar for XSS detection has been embedded through developed Google Chrome Extension. The developed mechanism successfully detects the XSS vulnerabilities attempted through malicious URL string. It also blocks the infected request before executing them. Keywords XSS, Context Free Grammar, Extension I. Introduction With the proliferation of the internet, there has been a surge in the web services being offered by many organizations like e-banking, e-shopping etc. Most of these applications do not develop with defensive programming principles, which increase the number of attack vectors. Attacker may acquire material gains or steal the credentials of the novice users through attack like XSS. It is pointed in OWASP - Top 10 most critical web application security vulnerability list [1]. HTTP is a stateless protocol which maintains the session through cookies [2]. As per the report- Application Vulnerability trend report 2014 [3], XSS vulnerability has ranked as a serious threat and appears in 60% of web applications. It is a web application vulnerability that targets client side scripting language embedded in a web page such as JavaScript. XSS may launched by attacker to hijack the session, steal the cookies, compromise sensitive information, execute malicious scripts to redirect the session end so on. This paper focuses on prevention of XSS attack, which may cause any kind of harm to legitimate users due to the insertion of malicious JavaScript into Web Application through URL. Prevention mechanism focuses on developing a client side grammar based detection engine for Cross Site Scripting that differentiates XSS attack from simple script. The main goal of this work is to provide a XSS solution to novice end user to safe guard their systems from attackers. It results in enhanced and secured browsing experience without any surge in functionality. The developed plug-in chrome browser would fetch the generated Universal Resource Locator (URL) and detect it for any kind of malicious input. Such a plug-in would protect from cookie theft, key logging, phishing etc. II. Cross Side Scripting Exploitation Cross Site Scripting [4] is a type of injection attack that injects malicious script into the authentic websites. Malicious scripts may reside on the web server or be explicitly inserted when the user surf to particular website. It relies upon the resources of targeted web server such as third party cookies. Typical scenario of XSS is depicted in fig. 1. Hacker lures the victim to click on the URL containing malicious JavaScript code. Whenever victim clicks into the URL, request reach the trusted web server and it reply with error message. Reply contains the name of resource (i.e. malicious JavaScript). Hacker Lure to victim Victim Clicks on URL Fig. 1: Scenario for XSS Attack Browser Sends request to trusted server Server returns page containing malicious JavaScript code Browser Execute it Return values Attackers Server Trusted Server JavaScript code is executed and does malfunctioning as defined in code. Characteristics of web applications, relevant to the XSS through URL, are as follows: 1. Web applications take input from users (through address bar of browser). 2. It separates filtered input into two strings (i.e. path of web page and search part). 3. Subsequently, it dynamically includes the search part (if present) in Web pages fetched from specified path. 4. This search part sent with the command of Hyper Text Transfer Protocol (HTTP) and considered as the section of path. 5. HTTP URL does not pass the host details to client. According to these characteristics web application may be defined as follows: Definition (Web Application) Here Web Application P:(Σ* Σ*) Σ^* is defined as a mapping from user inputs (over an alphabet Σ) to URL (over Σ) and search part (if exist). In particular, P is given by {(p 1...p n ), (s 1...s m )} www.ijcst.com International Journal of Computer Science And Technology 113

ISSN : 0976-8491 (Online) ISSN : 2229-4333 (Print) {Where- P : is a path string i S : Σ* Σ* is a search filter } i The argument to P is an n-tupple of input string (i1...im), and P returns a command c = c 1 +...+ c t where, for 1 j t That is, each C j is either a path of web page or a filtered search part. Attacker may tamper C j part to exploit XSS vulnerability when: 1. Script injects into web application through a distrusted source, most frequently a web request. 2. Data incorporated with dynamic content is replied to the end user and sent without validation of malware snippets. Address bar in web browser is the globally available source to inject script into web application. This paper structured the three cases to exploit vulnerable JavaScript code through URL. A. Inline Inclusion of JavaScript- Inline JavaScript code may be appended to URL by defining the malicious behavior into <script>... </script> tag. URL may contains script definition, for instancehttp://localhost/?message=<script>alert( xss ); </script> B. Through Local File: URLs also may contain the link of a local resource file (i.e. JavaScript file- xss.js). These local file defines the malicious nature of JavaScript code and stored into client machine. Client may execute locally stored JavaScript file (xss.js) through injecting the URLhttp://localhost/?message= <script src= xss.js > </script> C. Remotely script inclusion: URL may contain path of remote file for execution. These remote files define the malicious nature of JavaScript code. Remote files are fetched through anchor tag attribute value (like href). E.g. URL given below fetches the JavaScript file (xss.js) from the server ha.ckers.org (ha.ckers.org/xss.js). http://localhost/?message= <script href = http://ha.ckers.org/ xss.js> </script> III. Literature Review of XSS Detection Techniques To mitigate such serious impact, Web applications should use an effective solution for Cross-Site Scripting vulnerability. Snippet containing script injected through the URL is frequently misunderstood as XSS attack. By default, Web browsers are able to interpret snippets having the script that is replied by the Web server. Such scripts are usually written in different scripting languages such as JavaScript and VBScript. These are introduced by the HTML scripting tag <SCRIPT>. NoScript is the extension of Firefox browser for blocking the execution of all JavaScript codes. In this solution, all scripts are considered as malicious in nature. Blocking all JavaScript code execution is not fruitful solution because scripting functionality provides better experience. For example, string alert( XSS ) does not considered as malicious due to the harmless nature. In contrast, string alert(document.cookie) is considered as malicious due to accessing the DOM object of browser. A. Static Detection Approaches- Static detection approaches are based on previous knowledge of XSS vulnerabilities, execution patterns and syntactic structure of 114 International Journal of Computer Science And Technology vulnerable snippets. These approaches are based on two detection models: the negative and the positive model. Positive model allowed only well known benevolent JavaScript and denied everything else. It creates white-list of trusted and benign traffic. Negative model defines denied traffic and allow everything else. It creates blacklist of malicious traffic. Static detection approaches are as follows: 1. XSS Detection through String Analysis This method involves checking for particular occurrence of string. It can be implemented as finite state machine or as a context free grammar. This technique first detects the presence of <script> tags (both opening and closing) thoroughly in whole code. However, it is not practical for finding XSS vulnerabilities through script tags due to the other ways of invoking the JavaScript. Other ways like including their own scripts into web page and existence of different interpreters. (i). Rule-Based Detection Approach This approach defines static rules which have to be defined before the analysis process. Rules may be uncomplicated like detection of particular language keyword or more complex like detection of chain of characteristics. Rule based validation is appropriate for both reflected and stored XSS. While, Special set of rules are required to address DOM Based XSS. Enormous types of attack vector and unique contexts within HTML, requires number of rules to address the XSS attack. Hence, lacking the single rules from the particular list turns out to be a complicated issue. B. Dynamic Detection Approaches- Dynamic detection approaches are based on changes occurred at run time because of vulnerability execution. 1. Syntactical Structure Analysis Analysing the difference in syntactical structure of output string is an approch to detect the malicious snippets. Mostly attacks modify the syntactic structure of the exploited system. However, only analysis of syntactic structure is not adequate to detect vulnerabilities occurred due to the interaction of multiple modules. Nadji et al. [6] analyze the difference of document structure integrity to detect XSS attacks. This approach is constructive for detecting injected snippets that does not alters the parse tree of DOM. 2. Anomaly-based Detection Anomaly rules consist of dynamic rules. As the name implies, those rules are neither static nor are they manually defined. Instead, the rules are defined through a learning phase. Learning phase defines the alteration in among behavior of trusted traffic and anomalous traffic. Here, anomalous traffic is the traffic that does not look like normal traffic. Deviations from this rule-set are flagged as anomalous traffic. 3. Taint Propagation Analysis Taint propagation analysis is used to detect flow of data to track the information flow from source to sink. This technique assumes that if sanitizing operation on all paths from source to sinks has been accomplished successfully then the application has secure. A number of XSS vectors may bypass strong filters easily. Hence, trust on end user filtering and improper sanitization function is not proficient for security. Thus, it does not provide strong security mechanism. www.ijcst.com

C. XSS Prevention Approaches: Selecting a XSS prevention mechanism to go with server side solution or client side solution is also a great dispute. A client side solution can help the security unconscious end users. Server side solution helps web administrator and security experts. 1. Proxy Based Solution Noxes is a web proxy used by end user to protect against XSS attack. It is a client side and rule based solution to protect end users. If any connection is mismatched with its rules then end user may allow or deny the connection. Blacklisting the link is not sufficient technique to prevent cross-site Scripting attacks. It does not have any procedure of examining the errors that increases the false positive rate. 2. Browser Enforced Embedded Policies Web applications are often their own scripts. These all benign scripts are used to create white list for particular web application. This productive idea for protecting XSS, just allows execution of white listed script. Jim et al. [7] proposed hash based whitlist to protect from injection vulnerabilities. Firstly, generates the all hash value of whitelisted JavaScript and sends them to client side agent. Client side agent validate injected scripts through hash matching. Enforcing the policy to browser requires a modification in that. Accordingly, it suffers from scalability issue in respect with web application. Every client need to have this modified version of the browser. IV. Grammar Construction for XSS Attack The proposed architecture to detect vulnerable queries is based on context-free grammar. This grammar is constructed on the basis of various patterns exhibited through most available malicious URLs available in XSS Cheat Sheet [8]. Proposed architecture catches the malicious URLs and blocks these URLs before the execution. If there is no such malicious script found in URL, it may safely be termed harmless and may be allowed to execute. Architecture of the proposed work is depicted in the Fig. 2. A. URL Extraction- URL syntax and semantics are defined into RFC-1738, where URL has two parts <scheme> and <scheme-specific-part>. First part <scheme> is the name of the protocol used (such as http). It followed by a colon. Second part <scheme-specific-part> is a string whereof interpretation is based on the first part. In this paper, mostly URL s based on HTTP URL Scheme has been adopted to test the XSS attack. Syntax of HTTP URL is as follows: http://<host>:<port>/<path>?<searchpart> Developed extension extract the URL from address bar of the Google Chrome browser and pass it to preprocessing module. B. Syntactic Validation- Firstly, verify the query string for appropriate syntactic structure according to the scheme and features of web application. The intuition behind this syntactic validation is that the attacker tries; the script has run beyond the borders of the developers. forms with respect to U. It defines subset U which may be assigned such that L includes only syntactic forms that the application programmer wants to allow to the end user. According to valid syntactic forms, XSS has defined as: Definition (XSS): To a given Web Application P and an input vector (i 1.i m ), the following XSS command script c = P(i 1.i m ), constructed by P will be a XSS attack string if it holds the following conditions: Command script c has a valid parse tree T c ; There exist k such that 1 k n and s k (i k ) is a substring in the c and is not a valid semantic form in parse tree T c ; Fig. 2: Proposed Architecture C. URL Pre-processing- In this module, URL is decomposed into three major parts: the Website Name, Separator and the Query String. Website Name contains protocol, host, port and path of webpage. Website Name does not contain any error hence it s error-free, and ignored. Second is the Separator which is used to discrete the Website Name from <search part>. And remaining part (<search part>) is treated as Query String. This part may be augmented query upended into URL for XSS so it will be processed further. D. Tokenization- Proposed framework is suitable for JavaScript in hierarchical format. Hierarchical approach comprises two parsing top-down and bottom-up and one adaptive split-and-merge approach. Adaptive split-and-merge approaches firstly separate the heterogeneous regions, and then merge homogeneous regions. Split the query string into various tokens by means of JavaScript keywords. Subsequently, parse tree has been generated in hierarchical form that is labeled by symbols of a CFG. Root node has been labeled as Query String. Second-level nodes have all the remaining test tokens as its sub-tree. Here, all these tokens will be arranged in a multi level format with a variable number of levels as and when required. It is depends on the type of query string. The tree structure has been implemented with the help of JavaScript functions and cascading style sheets (CSS). For instances if URL is http://wahh-attaker.com/?+document.cookie than the query string will be +document.cookie. Generated parse tree has been depicted in fig. 3. Definition (Valid Syntactic Form): Let G = (V, Ʃ, S, P) be a CFG where V is non-terminals, Ʃ terminals, S a start symbol, P productions. Let U V Ʃ. Strings in the sub-language L generated by U are called valid syntactic www.ijcst.com International Journal of Computer Science And Technology 115

ISSN : 0976-8491 (Online) ISSN : 2229-4333 (Print) Query String approach can be extended to all the other server side scripting languages (like asp, jsp, etc.), so that all classes of web developers can make use of the solution. ID ARG + DOM PATH document. cookie Fig. 3: Parse Tree for Example Usage E. Context Free Grammer This module checks the parse tree with the help of passing it as input to the implemented code of developed context free grammar. This code has been designed for detecting malevolent strings based on developed CFG. Developed CFG for XSS attack has been depicted in Figure 4. Subsequently it checks the grammar for instances of keywords like script, JavaScript, location, cookie, etc. For example, if keyword like eval and alert appears with script or VBScript, then it might be a suspicious situation. If the query string is completely parsed through the grammar, it can be inferred that the string does not contain any malicious script, and so it is harmless. If the query string is not parsed completely through the grammar, it may be inferred that the string contains suspicious script therefore, it is harmful. As the final output, a popup message is displayed regarding the nature of the URL and notifies whether it must be blocked or allowed to execute. F. Performance Evaluation Traditionally, evaluation of a system measures has been done in terms of accuracy and completeness. Measuring the accuracy of an error-prone system is often done in terms of True Positive Rate (TPR), False Positive Rate (FPR). Completeness of the system may be measure though measuring result in all possible cases. To evaluate the performance, a labeled dataset of 151 URLs has been created and injected into developed environment. VI. Conclusion and Future Work In this paper a browser based XSS filtering tool has been developed to differentiate simple bona fide scripts from malevolent XSS queries. Consequently, the grammar is capable enough to detect and point out a wide array of malevolent URLs in real-time with much better precision and accuracy. The percentage and contribution of false positives and false negatives has been efficiently evaluated, which has boosted the real-time performance of the entire detection mechanism. Developing such an extension increase the security of novice end user at client side to safe guard their systems from malignant XSS attack. Thus, novice end users may enjoy the safe and better experience of browsing. This work has an immense future scope as far as implementation and improvements are concerned. The developed extension works accurately to stripping out the XSS queries however it is restricted to Google Chrome browser and JavaScript. The same logic and 116 International Journal of Computer Science And Technology Fig. 4: Developed CFG for XSS This dataset contains URLs with their respective previously identified malevolent or benevolent behavior. TPR and FPR depends on the dataset used and may vary. This experimental evaluation results that the system is 85.457% accurate as per the developed dataset. VII. Acknowledgment The work presented in this paper is not possible without the network and security laboratory of Department of Computer Science and Engineering, MA National Institute of Technology (MANIT), Bhopal, India. We would like to gratefully and sincerely thank to all of my former undergraduate lab mates for laboratory support. References [1] OWASP OWASP top 10-2013, the ten most critical web application security risks, June 2013 [Online]. Available: www.ijcst.com

https://www.owasp.org/index.php/top_10_2013-top_10 [Accessed: 1-July-2013]. [2] Divya Rishi Sahu, Deepak Singh Tomar, End user identification through proactive techniques, In Int. Conf. on Information Science 2014 (ICIS-2014), Ernakulam, Kerala, July-2014. [3] Cenzic Inc., Application vulnerability trend report:2014, [Online]. Available: http://www.cenzic.com/downloads/ Cenzic_Vulnerability_Report_2014.pdf [Accessed: 12- August-2014]. [4] Dr. E. Benoist, Cross Site Scripting, 2012 [Online]. Available: http://benoist.ch/websecurity/slides/crosssitescripting/ slidesxss.pdf [Accessed: June 2013]. [5] G. A. Di Luccaet Al., Identifying cross site scripting vulnerabilities in web application, In Proc. of the Web Site Evolution (WSE), Sixth IEEE Int. Workshop, Chicago, IL, September-2004, pp. 71-80. [6] Y. Nadji, P. Saxena, D. Song, Document Structure Integrity: A Robust Basis for Cross-Site Scripting Defence, In 16th Annual Network & Distributed System Security Symposium (NDSS), San Diego, California, USA, February-2009. [7] T. Jim, N. Swamy, H. Hicks, Defeating script injection attacks with browser-enforced embedded policies, In Proc. of the 16th Int. Conf. on World Wide Web, Banff, Alberta, Canada, May -2007, pp. 601-610. [8] R Snake, XSS (Cross Site Scripting) Cheat Sheet ESP: for filter evasion, [Online] Available:http://sage.math. washington.edu/home/wstein/www/home/agc/lit/javascript/ xss.html [Accessed: August 2013]. [9] Zhendong Su, Gary Wassermann, The essence of command injection attacks in web application, Conf. record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, USA, Jauary-2006, pp. 372-382. Divya Rish Sahu completed M.Tech in Information Security and BE in Information Technology branch. He is currently pursuing his PhD in CSE department from Maulana Azad National Institute of Technology (MANIT), Bhopal, India. Dr. Deepak Singh Tomar obtained his BE, M Tech and PhD in CSE. He is currently Assistant Professor of CSE department at NIT Bhopal, India. His research interests are in Web Mining and Cyber Security. He has published more than 45 papers and guided 27 M Tech thesis. He is having more than 20 year experience. www.ijcst.com International Journal of Computer Science And Technology 117