Differential String Analysis Tevfik Bultan (Joint work with Muath Alkhalaf, Fang Yu and Abdulbaki Aydin) 1 Verification Lab Department.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

PHP I.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Differential String Analysis Tevfik Bultan (Joint work with Muath Alkhalaf, Fang Yu and Abdulbaki Aydin) 1 Verification Lab Department.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
CS 290C: Formal Models for Web Software Lecture 1: Introduction Instructor: Tevfik Bultan.
Eliminating Web Software Vulnerabilities with Automated Verification Tevfik Bultan Verification Lab Department of Computer Science University of California,
Leveraging User Interactions for In-Depth Testing of Web Applications Sean McAllister, Engin Kirda, and Christopher Kruegel RAID ’08 1 Seoyeon Kang November.
Sara SartoliAkbar Siami Namin NSF-SFS workshop July 14-18, 2014.
© 2003 School of Computing, University of Leeds SY32 Secure Computing, Lecture 14 Implementation Flaws Part 2: Malicious Input and Data Validation Issues.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Muath Alkhalaf 1 Shauvik Roy Choudhary 2 Mattia Fazzini 2 Tevfik Bultan 1 Alessandro Orso 2 Christopher Kruegel 1 1 UC Santa Barbara 2 Georgia Tech.
Injection Attacks by Example SQL Injection and XSS Adam Forsythe Thomas Hollingsworth.
Automatic Creation of SQL Injection and Cross-Site Scripting Attacks 2nd-order XSS attacks 1st-order XSS attacks SQLI attacks Adam Kiezun, Philip J. Guo,
Preventing SQL Injection ~example of SQL injection $user = $_POST[‘user’]; $pass = $_POST[‘pass’]; $query = DELETE FROM Users WHERE user = ‘$user’ AND.
Stupid Browser Tricks with PHP and JavaScript By Chris Winikka.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
CS 290C: Formal Models for Web Software Lectures 17: Analyzing Input Validation and Sanitization in Web Applications Instructor: Tevfik Bultan.
Prevent Cross-Site Scripting (XSS) attack
Prithvi Bisht, Timothy Hinrichs, Nazari Skrupsky, Radoslaw Bobrowicz, V.N. Venkatakrishnan University of Illinois at Chicago, USA ACM CCS (Oct,2010) Prithvi.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
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.
Automatically Hardening Web Applications Using Precise Tainting Anh Nguyen-Tuong Salvatore Guarnieri Doug Greene Jeff Shirley David Evans University of.
Eliminating Bugs In MVC-Style Web Applications Tevfik Bultan Verification Lab (Vlab),
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.
Preventing Web Application Injections with Complementary Character Coding Raymond Mui Phyllis Frankl Polytechnic Institute of NYU Presented at ESORICS.
Chapter 8 Cookies And Security JavaScript, Third Edition.
CSC-682 Cryptography & Computer Security Sound and Precise Analysis of Web Applications for Injection Vulnerabilities Pompi Rotaru Based on an article.
Web Application Security ECE ECE Internetwork Security What is a Web Application? An application generally comprised of a collection of scripts.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
School of Computing and Information Systems CS 371 Web Application Programming Security Avoiding and Preventing Attacks.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
OWASP Top Ten #1 Unvalidated Input. Agenda What is the OWASP Top 10? Where can I find it? What is Unvalidated Input? What environments are effected? How.
FSE 2014 Tutorial String Analysis Tevfik Bultan University of California, Santa Barbara, USA Fang Yu National Chengchi University, Taiwan.
COMPUTER SECURITY MIDTERM REVIEW CS161 University of California BerkeleyApril 4, 2012.
October 3, 2008IMI Security Symposium Application Security through a Hacker’s Eyes James Walden Northern Kentucky University
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
SQL INJECTIONS Presented By: Eloy Viteri. What is SQL Injection An SQL injection attack is executed when a web page allows users to enter text into a.
If statements and validation. If statement In programming the if statement allows one to test certain conditions and respond differently depending on.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
Detecting and Repairing Security Vulnerabilities in Web Applications Tevfik Bultan (Joint work with Muath Alkhalaf, Fang Yu and Abdulbaki Aydin) 1
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
EECS 354: Network Security Group Members: Patrick Wong Eric Chan Shira Schneidman Web Attacks Project: Detecting XSS and SQL Injection Vulnerabilities.
CS 267: Automated Verification Lectures 16: String Analysis Instructor: Tevfik Bultan.
Example – SQL Injection MySQL & PHP code: // The next instruction prompts the user is to supply an ID $personID = getIDstringFromUser(); $sqlQuery = "SELECT.
Automatic Repair for Input Validation and Sanitization Bugs 1.
Saner: Composing Static and Dynamic Analysis to Validate Sanitization in Web Applications Davide Balzarotti, Marco Cova, Vika Felmetsger, Nenad Jovanovic,
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,
IST 210: PHP Basics IST 210: Organization of Data IST2101.
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.
Group 18: Chris Hood Brett Poche
Module: Software Engineering of Web Applications
An Introduction to Web Application Security
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
SQL Injection.
Example – SQL Injection
String Analysis for Dependable Input Validation
Automata Based String Analysis for Vulnerability Detection
PHP: Security issues FdSc Module 109 Server side scripting and
Lecture 2 - SQL Injection
CS5123 Software Validation and Quality Assurance
Presentation transcript:

Differential String Analysis Tevfik Bultan (Joint work with Muath Alkhalaf, Fang Yu and Abdulbaki Aydin) 1 Verification Lab Department of Computer Science University of California, Santa Barbara

Anatomy of a Web Application Submit unsupscribe.php DB php 2

Web Application Inputs are Strings 3 Submit DB unsupscribe.php php

Input Needs to be Validated and/or Sanitized 4 Submit DB unsupscribe.php php

Web Applications are Full of Bugs XSS 2.Injection Flaws 3.Malicious File Exec Injection Flaws 2.XSS 3.Broken Auth. Session M Injection Flaws 2.Broken Auth. Session M. 3.XSS ● OWASP Top 10 Web Application Vulnerabilities Source: IBM X-Force report

Vulnerabilities in Web Applications There are many well-known security vulnerabilities that exist in many web applications. Here are some examples: –Malicious file execution: where a malicious user causes the server to execute malicious code –SQL injection: where a malicious user executes SQL commands on the back-end database by providing specially formatted input –Cross site scripting (XSS): causes the attacker to execute a malicious script at a user’s browser These vulnerabilities are typically due to –errors in user input validation and sanitization or –lack of user input validation and sanitization 6

Why Is Input Validation & Sanitization Error-prone? Extensive string manipulation: –Web applications use extensive string manipulation To construct html pages, to construct database queries in SQL, etc. –The user input comes in string form and must be validated and sanitized before it can be used This requires the use of complex string manipulation functions such as string-replace –String manipulation is error prone 7

String Related Vulnerabilities String related web application vulnerabilities occur when: a sensitive function is passed a malicious string input from the user This input contains an attack It is not properly sanitized before it reaches the sensitive function String analysis: Discover these vulnerabilities automatically 8

String Manipulation Operations Concatenation – “ 1 ” + “ 2 ”  “ 12 ” – “Foo” + “bAaR”  “FoobAaR” Replacement – replace(“a”, “A”) – replace (“2”,””) (delete) – toUpperCase (multiple replace) bAAR bAaR ABC abC 9

String Filtering Operations Branch conditions length < 4 ? “Foo” “bAaR” match(/^[0-9]+$/) ? “234” “a3v%6” substring(2, 4) == “aR” ? ”bAaR” “Foo” 10

function validate (inputField, helpText){ if (!/.+/.test(inputField.value)) { if (helpText != null) helpText.innerHTML = "Please enter a value."; return false; } else { if (helpText != null) helpText.innerHTML = ""; if( A-Z0-9]{2,3})+$/.test(inputField.value)) { if (helpText != null) helpText.innerHTML = “enter a valid ”; return false; } else { if (helpText != null) helpText.innerHTML = ""; return true; }}} Javascript Input Validation 11

function validate (inputField, helpText){ if (!/.+/.test(inputField.value)) { if (helpText != null) helpText.innerHTML = "Please enter a value."; return false; } else { if (helpText != null) helpText.innerHTML = ""; if( A-Z0-9]{2,3})+$/.test(inputField.value)) { if (helpText != null) helpText.innerHTML = “enter a valid "; return false; } else { if (helpText != null) helpText.innerHTML = ""; return true; }}}  [a-zA-Z0-9\.-_\+].-_ means all characters from. to _  This includes ; and =  [a-zA-Z0-9\.-_\+].-_ means all characters from. to _  This includes ; and = Input Validation Error 12

GOAL Automatically Find and Repair Bugs CAUSED BY String filtering and manipulation operations IN Input validation and sanitization code IN Web applications 13

Differential Analysis: Verification without Specification 14 Client-side Server-side

Sanitization Code is Complex function validate() {... switch(type) { case "time": var highlight = true; var default_msg = "Please enter a valid time."; time_pattern = /^[1-9]\:[0-5][0-9]\s*(\AM|PM|am|pm?)\s*$/; time_pattern2 = /^[1-1][0-2]\:[0-5][0-9]\s*(\AM|PM|am|pm?)\s*$/; time_pattern3 = /^[1-1][0-2]\:[0-5][0-9]\:[0-5][0-9]\s*(\AM|PM| am|pm?)\s*$/; time_pattern4 = /^[1-9]\:[0-5][0-9]\:[0-5][0-9]\s*(\AM|PM| am|pm?)\s*$/; if (field.value != "") { if (!time_pattern.test(field.value) && !time_pattern2.test(field.value) && !time_pattern3.test(field.value) && !time_pattern4.test(field.value)) { error = true; } break; case " ": error = is Invalid(field); var highlight = true; var default_msg = "Please enter a valid address."; break; case "date": var highlight = true; var default_msg = "Please enter a valid date."; date_pattern = /^(\d{1}|\d{2})\/(\d{1}|\d{2})\/(\d{2}|\d{4})\s*$/; if (field.value != "") if (!date_pattern.test(field.value)||!isDateValid(field.value)) error = true; break;... if (alert_msg == "" || alert_msg == null) alert_msg = default_msg; if (error) { any_error = true; total_msg = total_msg + alert_msg + "|"; } if (error && highlight) { field.setAttribute("class","error"); field.setAttribute("className","error"); // For IE }... } 1)Mixed input validation and sanitization for multiple HTML input fields 2) Lots of event handling and error reporting code 15

Modular Verification Process Extraction String Analysis Bug Detection and Repair 16 Web App Sanitizer Functions Symbolic representation of attack strings and vulnerability signatures

Classification of Input Validation and Sanitization Functions 17 PureValidatorPureValidator Input Yes (valid) No (invalid) PureSanitizerPureSanitizer Input Output ValidatingSanitizerValidatingSanitizer Input Output No (invalid)

Static Extraction for PHP 18 Sink mysql_query(……) Sources printf …… $_POST[“ ”] $_POST[“username”] ValidatingSanitizerValidatingSanitizer Input Output No (invalid) Static extraction using Pixy -Augmented to handle path conditions Static dependency analysis Output is a dependency graph -Contains all validation and sanitization operations between sources and sink

Dynamic Extraction for Javascript 19 ValidatingSanitizerValidatingSanitizer Input Output No (invalid) Sink submit xmlhttp.send() Source Enter Run application on a number of inputs –Inputs are selected heuristically Instrument execution –HtmlUnit: browser simulator –Rhino: JS interpreter –Convert all accesses on objects and arrays to accesses on memory locations Dynamic dependency tracking Source: IBM X-Force report

String Analysis & Repair 20 Yes No Target Sanitizer Generate Patch Automata-based String Analysis Reference Sanitizer Length Patch Validation Patch Sanitization Patch

Automata-Based String Analysis Sanitizer Function Symbolic Forward Fix-Point Computation Symbolic Backward Fix-Point Computation String Analysis Post-Image (Post-Condition) Pre-Image (Pre-Condition) Negative Pre-Image (Pre-Condition for reject) 21

sanitizer(x){ if (x != “aa” && x != “bb” && x != “ab”) reject; x = replace(/^ab$/, “ba”,x); return x; } 22 Sanitizers aa bb ab aab bbb aa bb T ba Σ* Σ* ∪ T rejecting invalid inputs Σ = {a, b}

aa bb ab aab bbb aa bb T ba Σ* ∪ (Non) Preferred Output Pre-image Negative Pre-Image Reject Possible output (Post Image) Σ* Post-Image, Pre-Image and Negative Pre-Image 23 b a, T sanitizer(x){ if (x != “aa” && x != “bb” && x != “ab”) reject; x = replace(/^ab$/, “ba”,x); return x; }

Symbolic Automata Explicit DFA representation Symbolic DFA representation

1 st Step: Find Inconsistency 25 Σ* T Σ* ∪ T Σ* T Σ* ∪ T Target Reference Output difference: Strings returned by target but not by reference ?⊆?⊆

2 nd Step: Differential Repair 26 Σ* T Σ* ∪ T Σ* T Σ* ∪ T Target Reference Σ* T Σ* ∪ T Repaired Function ⊈

Composing Sanitizers? Can we run the two sanitizers one after the other? Does not work due to lack of Idempotency – Both sanitizers escape ’ with \ – Input ab’c – 1 st sanitizer  ab\’c – 2 nd sanitizer  ab\\’c Security problem (double escaping) We need to find the difference 27

28 function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } Σ* T Σ* ∪ T Σ* T Σ* ∪ T X Output difference: Strings returned by target but not by reference reject sanitize

29 function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } InputTargetReferenceDiff Type “<““<““<““<““”Sanitization “ ’’ ”“ \’\’ ”“ ’’ ”Sanitization + Length “ abcd ” Validation Set of input strings that resulted in the difference: input difference automaton ‘ ‘ ‘ T

How to Generate a Sanitization Patch? Basic Idea: Modify the input strings so that they do not cause a difference How? Make sure that the modified input strings do not go from the start state to an accept state in the input difference automaton How? 1) Find a min-cut that separates the start state from all the accepting states in the input difference automaton, and 2) Delete all the characters in the cut 30

For the example above: Min-Cut results in deleting everything “foo”  “” Min-Cut is too conservative! Why? You can not remove a validation difference using a sanitization patch 31 function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } Input difference automaton ‘ ‘ ‘ Min-Cut = Σ

(1) Validation Patch 32 function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } Σ* T Σ* ∪ T Σ* T Σ* ∪ T function valid_patch($x){ if (semrep_match1($x)) die(“error”); } Validation patch DFA

function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } function valid_patch($x){ if (semrep_match1($x)) die(“error”); } Σ* T Σ* ∪ T Σ* T Σ* ∪ T X Min-Cut = { ‘, <} “fo ’ ”  “fo\ ’ ” function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } 33

function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } Σ* T Σ* ∪ T Σ* T Σ* ∪ T function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } function valid_patch($x){ if (semrep_match1($x)) die(“error”); } function length_patch($x){ if (semrep_match2($x)) die(“error”); } function valid_patch($x){ if (semrep_match1($x)) die(“error”); } Length DFA Unwanted length in target caused by escape (2) Length Patch 34

function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } Σ* T Σ* ∪ T Σ* T Σ* ∪ T function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } function valid_patch($x){ if (semrep_match1($x)) die(“error”); } function length_patch($x){ if (semrep_match2($x)) die(“error”); } Length DFA Unwanted length in target caused by escape Length Restricted Post-image Length Restricted Post-image Reference Post-image (3) Sanitization Patch 35 Sanitization difference X

function reference($x){ $x = preg_replace(“<“, “”, $x); if (strlen($x) < 4) return $x; else die(“error”); } function target($x){ $x = preg_replace(‘”’, ‘\”’, $x);return $x; } function valid_patch($x){ if (semrep_match1($x)) die(“error”); } function length_patch($x){ if (semrep_match2($x)) die(“error”); } Min-Cut = {<} function target($x){ $x = preg_replace(“’”, “\’”, $x);return $x; } function sanit_patch($x){ $x = semrep_sanit(“<“, $x); return $x; } (3) Sanitization Patch 36

Min-Cut Heuristics We use two heuristics for mincut Trim: – Only if min-cut contain space character – Test if reference Post-Image is does not have space at the beginning and end – Assume it is trim () Escape: – Test if reference Post-Image escapes the mincut characters 37

Experimental Results 38

Differential Repair Evaluation We ran the differential patching algorithm on 5 PHP web applications 39 NameDescription PHPNews v1.3.0 News publishing software UseBB v Forum software Snipe Gallery v3.1.5 Image management system MyBloggie v2.1.6 Weblog system Schoolmate v1.5.4 School administration software

Number of Patches Generated 40

Sanitization Patch Results 41

Time and Memory Performance of Differential Repair Algorithm 42

SemRep: Differential Repair Tool

Publications on Differential String Analysis Muath Alkhalaf, Abdulbaki Aydin, and Tevfik Bultan. "Semantic Differential Repair for Input Validation and Sanitization." Proceedings of the 2014 International Symposium on Software Testing and Analysis (ISSTA 2014), pages , San Jose, California, USA, July 21-25, Muath Alkhalaf, Shauvik Roy Choudhary, Mattia Fazzini, Tevfik Bultan, Alessandro Orso and Christopher Kruegel. "ViewPoints: Differential String Analysis for Discovering Client and Server-Side Input Validation Inconsistencies." Proceedings of the 2012 International Symposium on Software Testing and Analysis (ISSTA 2012), pages 56-66, Minneapolis, USA, July ,