developing secure web application - cross-site scripting (xss)

22
Developing Secure Web Application Cross-Site Scripting (XSS) Cezar Coca Endava 10th of November 2012

Upload: codecampiasi

Post on 12-Jun-2015

490 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Developing Secure Web Application - Cross-Site Scripting (XSS)

Developing Secure Web ApplicationCross-Site Scripting (XSS)Cezar CocaEndava

10th of November 2012

Page 2: Developing Secure Web Application - Cross-Site Scripting (XSS)

Agenda

• Why?

• Formal description

• Same Origin Policy

• How to perform an XSS attack

• Demo

• Prevention of XSS attacks

Page 3: Developing Secure Web Application - Cross-Site Scripting (XSS)

OWASP Top Ten (2010 Edition)

http://www.owasp.org/index.php/Top_10

Page 4: Developing Secure Web Application - Cross-Site Scripting (XSS)

At first sight

=

Page 5: Developing Secure Web Application - Cross-Site Scripting (XSS)

Second sight

Page 6: Developing Secure Web Application - Cross-Site Scripting (XSS)

XSS formal description

Types – at least two primary flavors • Non-persistent (or reflected)

• Persistent (or stored)

Typical impact

• Steal user’s session (hijack session)

• Rewrite web page

• Redirect user to phishing or malware site

• Most Severe: Install XSS proxy

Page 7: Developing Secure Web Application - Cross-Site Scripting (XSS)

Same Origin Policy – Security Domain

Page 8: Developing Secure Web Application - Cross-Site Scripting (XSS)

Same Origin Policy - DOM

Page 9: Developing Secure Web Application - Cross-Site Scripting (XSS)

Same Origin Policy - DOM

Page 10: Developing Secure Web Application - Cross-Site Scripting (XSS)

Same Origin Policy - DOM

Page 11: Developing Secure Web Application - Cross-Site Scripting (XSS)

Reflected XSS Illustrated

Attacker send the victim a misleading email with a link containing malicious JavaScript

1

Page 12: Developing Secure Web Application - Cross-Site Scripting (XSS)

Reflected XSS Illustrated

Attacker send the victim a misleading email with a link containing malicious JavaScript

1

2

When the victim clicks on the link, the HTTP request is initiated from the victim's browser and sent to the vulnerable Web application.

Page 13: Developing Secure Web Application - Cross-Site Scripting (XSS)

Reflected XSS Illustrated

Attacker send the victim a misleading email with a link containing malicious JavaScript

1

2

When the victim clicks on the link, the HTTP request is initiated from the victim's browser and sent to the vulnerable Web application.

3

The malicious JavaScript is then reflected back to the victim's browser, where it is executed in the context of the victim user's session

Page 14: Developing Secure Web Application - Cross-Site Scripting (XSS)

DEMO – deployment diagram

Page 15: Developing Secure Web Application - Cross-Site Scripting (XSS)

LET’S HACK

Page 16: Developing Secure Web Application - Cross-Site Scripting (XSS)

Second sight

Page 17: Developing Secure Web Application - Cross-Site Scripting (XSS)

Prevention of XSS Attack – part 1

• Input Validation

• Canonicalize data first

• Prevent encoded attacks

• Black list testing is no solution

• Black lists are never complete!

• White list testing is better

• Only what you expect will pass

• Regular expressions

• HTML Encoding

• HTML encoding of all input when put into output pages

Page 18: Developing Secure Web Application - Cross-Site Scripting (XSS)

Prevention of XSS Attack – Multiple contexts

Browser have multiple contexts that must be considered!

HTML Body

HTML Attributes

<STYLE> Context

<SCRIPT> Context

URL Context

Page 19: Developing Secure Web Application - Cross-Site Scripting (XSS)

Prevention of XSS Attack – Session Hijacking

• Session hijacking

• “HttpOnly" Cookies

• "secure" Cookies. Cookies are only sent over SSL

• Disable TRACE

• References:

• http://www.owasp.org/index.php/XSS_(Cross Site Scripting) Prevention Che

at Sheet

• http://ha.ckers.org/xss.html

• http://www.owasp.org/index.php/ESAPI

Page 20: Developing Secure Web Application - Cross-Site Scripting (XSS)
Page 21: Developing Secure Web Application - Cross-Site Scripting (XSS)
Page 22: Developing Secure Web Application - Cross-Site Scripting (XSS)

Diamond Sponsors

Platinum Sponsors Gold Sponsors

Training Partners Media Partners Other Partners