1 Project 2: Web App Security Collin Jackson CS 155 Spring 2006.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Nick Feamster CS 6262 Spring 2009
PHP I.
Hossain Shahriar Mohammad Zulkernine. One of the worst vulnerabilities in web applications It involves the generation of dynamic HTML contents with invalidated.
Web Security Never, ever, trust user inputs Supankar.
JavaScript and AJAX Jonathan Foss University of Warwick
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
0 The Past, Present and Future of XSS Defense Jim Manico 2011 OWASP Brussels.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
1 Project 2: Web App Security Collin Jackson CS 155 Spring 2007.
9/9/2005 Developing "Secure" Web Applications 1 Methods & Concepts for Developing “Secure” Web Applications Peter Y. Hammond, Developer Wasatch Front Regional.
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.
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.
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.
JavaScript & jQuery the missing manual Chapter 11
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
+ Websites Vulnerabilities. + Content Expand of The Internet Use of the Internet Examples Importance of the Internet How to find Security Vulnerabilities.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
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.
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.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
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.
1 Accelerated Web Development Course JavaScript and Client side programming Day 2 Rich Roth On The Net
Cross Site Scripting (XSS) Chaitanya Lakshmi
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript. Overview Introduction: JavaScript basics Expressions and types Expressions and types Arrays Arrays Objects and Associative Arrays Objects.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
Crash Course in Web Hacking
Introduction to JavaScript CS101 Introduction to Computing.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
1 Final Review. 2 Final Exam  30% of your grade for the course  December 9 at 7:00 p.m., the regular class time  No makeup exam or alternate times.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
Example – SQL Injection MySQL & PHP code: // The next instruction prompts the user is to supply an ID $personID = getIDstringFromUser(); $sqlQuery = "SELECT.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
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,
HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Formatting HTML Links HTML Head HTML CSS HTML.
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.
PHP (Session 2) INFO 257 Supplement.
Group 18: Chris Hood Brett Poche
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Introduction to Dynamic Web Programming
Example – SQL Injection
BASIC PHP and MYSQL Edward S. Flores.
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
Web Systems Development (CSC-215)
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Javascript and JQuery SRM DSC.
Lecture 27 Security I April 4, 2018 Open news web sites.
Presentation transcript:

1 Project 2: Web App Security Collin Jackson CS 155 Spring 2006

2 Deadlines

3 Part 1 Attacks

4 Overview Explore several attack types Requires both effectiveness and stealth Learn: How an attacker can evade sanitization Consequences of an exploit JavaScript Very basic CSS

5 Attack A: Cookie Theft Use URL encoding Could hijack session Attack C: Login Snooping Evade sanitization Handle DOM events Attacks Attack B: Silent Transfer Navigate browser Use iframes, forms Attack D: Profile Worm Confuse site scripts Replicate zoobar.org link zoobar.org form badguy.com stanford.edu redirect badguy.com zoobar.org form zoobar.org

6 JavaScript Browser scripting language with C-like syntax Sandboxed, garbage collected Closures var x = 3; var y = function() { alert(x); }; return y; Encapsulation/objects function X() { this.y = 3; } var z = new X(); alert(z.y); Can interpret data as code (eval) Browser-dependent

7 Invoking JavaScript Tags: alert( ‘Hello world!’ ) Links: javascript:alert( ‘Hello world!’ ) Wrap code in “void” if it has return value Event handlers: CSS (IE only) body { background: url(javascript:alert( ‘Hello world!’ )); }

8 DOM Manipulation Examples document.getElementByID(id) document.getElementsByTagName(tag) document.write(htmltext) document.createElement(tagname) document.body.appendChild(node) document.forms[index].fieldname.value = … document.formname.fieldname.value = … frame.contentDocument.getElementById(id)

9 Arrays and Loops Example: Change href of all links on a page var links = document.getElementsByTagName(‘a’); for(var i = 0; i < links.length; i++) { var link = links[i]; link.href = “javascript:alert(‘Sorry!’);”; }

10 Other Useful Functions Navigation document.location document.formname.submit() document.forms[0].submitfield.click() Delayed Events node.addEventListener(eventname, handler, useCapture) node.removeEventListener(eventname, handler, useCapture) window.setTimeout(handler, milliseconds)

11 Stealthy Styles var node = document.getElementByID(“mynodeid”); node.style.display = ‘none’; // may not load at all node.style.visibility = ‘hidden’; // still takes up space node.style.position = ‘absolute’; // not included in flow document.write( // can also write CSS rules to page “ #mynodeid { visibility:hidden; } ”);

12 Example: Profile Deleter Malicious hyperlink deletes profile of user who clicks it Only works when user logged in User might have multiple tabs open Might have chosen/forgotten not to log out Might appear in another user’s profile Uses vulnerability in users.php from Attack A Constructs profile deletion form and submits it ???

13 Find vulnerability Site reflects query parameter in input field Link can include anything we want here

14 Copy form data View source to find form fields Create copycat form with our modifications

15 Close previous, Button click triggers form submit URL encode

16 Debugging Check error It didn’t work. Open JavaScript console Undefined  No properties! Two forms with same name

17 Now with correct form Fixed version

18 Profile deleted Final Test users.php replaced with index.php %0D%20%20action%3D%22%2Findex%2Ephp%22%3E%0D%3Ctextarea%20name%3D%22profile%5Fupdate%22%3E%3C% 2Ftextarea%3E%3Cbr%2F%3E%0D%3Cinput%20type%3Dsubmit%20name%3D%22profile%5Fsubmit%22%20value%3D%22 Save%20Profile%22%3E%3C%2Fform%3E%0D%3Cscript%3Edocument%2Eforms%5B1%5D%2Eprofile%5Fsubmit%2Eclick%28 %29%3C%2Fscript%3E

19 Post form into hidden iframe … Open page with form in hidden iframe … document.myframe.contentDocument.forms[0].profile_update.value =“”; Stealthier approaches

20 Part 2 Defenses

21 Goals Learn: How easy it is to make mistakes That even simple code can be hard to secure Techniques for appropriate input validation PHP Very basic SQL Little programming knowledge can be a dangerous thing

22 PHP: Hypertext Preprocessor Server scripting language with C-like syntax Can intermingle static HTML and code > Encapsulation/objects class X { var $y = 3; } $z = new X(); echo $z->y; Can embed variables in double-quote strings $user = “world”; echo “Hello $user!”; or$user = “world”; echo “Hello”. $user. “!”; Form data in global arrays $_GET, $_POST, …

23 SQL Widely used database query language Fetch a set of records SELECT * FROM Person WHERE Username=‘grader’ Add data to the table INSERT INTO Person (Username, Zoobars) VALUES (‘grader’, 10) Modify data UPDATE Person SET Zoobars=42 WHERE PersonID=5 Query syntax (mostly) independent of vendor

24 File structure index.php users.php transfer.php login.php includes/ auth.php (cookie authentication) common.php (includes everything else) navigation.php (site template) db/ zoobar/  Person.txt (must be writable by web server) Includes /usr/class/cs155/projects/pp2/txt-db-api/… Only edit these files

25 txt-db-api Third-party text file database library Data can be int, string, and autoincrement Need to escape strings: \’ \” \\ Actually magic_quotes_gpc does this for us $recipient = $_POST[‘recipient’]; // already escaped $sql = "SELECT PersonID FROM Person WHERE Username='$recipient'"; $rs = $db->executeQuery($sql); if( $rs->next() ) $id = $rs->getCurrentValueByName(‘PersonID’);

26 Attack A: Cookie Theft Attack C: Login Snooping Defenses to Part 1 Attack B: Silent Transfer Attack D: Profile Worm

27 Sanitization Techniques addslashes(string) Already done by magic_quotes_gpc Inverse: stripslashes(string) htmlspecialchars(string [, quote_style]) Converts & ” to HTML entities Use ENT_QUOTES to change ’ to ' strip_tags(string, [, allowable_tags]) Max tag length 1024 Does not sanitize tag properties preg_replace(pattern, replacement, subject) More info:

28 More XSS hunting Look for untrusted input used as output Note sanitization already applied to each variable Form data has magic_quotes_gpc, db data does not Determine browser context for output Inside a quoted string within a tag – worry about ’ ” Outside a tag – worry about Input to eval – very dangerous Sanitize the output if necessary No penalty for erring on the side of caution But sanitizing multiple times may lead to problems No credit for solving non-goals: SQL injection, etc.

29 Good luck! Start early Ask questions Be creative