University of Illinois at Chicago

Slides:



Advertisements
Similar presentations
How Did I Steal Your Database Mostafa
Advertisements

Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Injection Yuji Kosuga, Kenji Kono, Miyuki Hanaoka Keio University Miho Hishiyama,
The Essence of Command Injection Attacks in Web Applications Zhendong Su and Gary Wassermann Present by Alon Kremer April 2011.
Introduction The concept of “SQL Injection”
NAVY Research Group Department of Computer Science Faculty of Electrical Engineering and Computer Science VŠB-TUO 17. listopadu Ostrava-Poruba.
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
ReferencesReferences DiscussionDiscussion Vulnerability Example: SQL injection Auditing Tool for Eclipse LAPSE: a Security Auditing Tool for Eclipse IntroductionIntroductionResultsResults.
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.
Check That Input Preventing SQL Injection Attacks By Andrew Morton For CS 410.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
SQL INJECTION COUNTERMEASURES &
CSCI 6962: Server-side Design and Programming Secure Web Programming.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
AMNESIA: Analysis and Monitoring for NEutralizing SQL- Injection Attacks Published by Wiliam Halfond and Alessandro Orso Presented by El Shibani Omar CS691.
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 5 “Database and Cloud Security”.
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.
XSS-GUARD : Precise Dynamic Prevention of Cross Site Scripting (XSS) Attacks Prithvi Bisht ( Joint work with : V.N. Venkatakrishnan.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
CSC-682 Cryptography & Computer Security Sound and Precise Analysis of Web Applications for Injection Vulnerabilities Pompi Rotaru Based on an article.
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
CANDID : Preventing SQL Injection Attacks Using Dynamic Candidate Evaluations V. N. Venkatakrishnan Assistant Professor, Computer Science University of.
Attacking Data Stores Brad Stancel CSCE 813 Presentation 11/12/2012.
Analysis of SQL injection prevention using a filtering proxy server By: David Rowe Supervisor: Barry Irwin.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
M1G Introduction to Database Development 5. Doing more with queries.
C ANDID : P REVENTING SQL I NJECTION A TTACKS U SING D YNAMIC C ANDIDATE E VALUATIONS Presented by Jeong-hoon, Park 1.
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.
Aniket Joshi Justin Thomas. Agenda Introduction to SQL Injection SQL Injection Attack SQL Injection Prevention Summary.
WEB SECURITY WEEK 2 Computer Security Group University of Texas at Dallas.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
Form Handling IDIA 618 Fall 2014 Bridget M. Blodgett.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
SQL Injection Anthony Brown March 4, 2008 IntroductionQuestionsBackgroundTechniquesPreventionDemoConclusions.
Secure Authentication. SQL Injection Many web developers are unaware of how SQL queries can be tampered with SQL queries are able to circumvent access.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
SQL Injection By Wenonah Abadilla. Topics What is SQL What is SQL Injection Damn Vulnerable Web App SQLI Demo Prepared Statements.
SQL Injection Attacks S Vinay Kumar, 07012D0506. Outline SQL Injection ? Classification of Attacks Attack Techniques Prevention Techniques Conclusion.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
M M Waseem Iqbal.  Cause: Unverified/unsanitized user input  Effect: the application runs unintended SQL code.  Attack is particularly effective if.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
COMP 430 Intro. to Database Systems SQL from application code.
SQL Injection By Wenonah Abadilla.
Database and Cloud Security
Database System Implementation CSE 507
Module: Software Engineering of Web Applications
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Introduction to Dynamic Web Programming
SQL Injection.
Context-Sensitive Analysis
CS320 Web and Internet Programming Database Access with JDBC
Introduction to Computer Science / Procedural – 67130
SQL INJECTION ATTACKS.
SQL Injection Attacks Many web servers have backing databases
Un</br>able’s MySecretSecrets
PHP: Security issues FdSc Module 109 Server side scripting and
Teaching slides Chapter 8.
University of Illinois at Chicago
University of Illinois at Chicago
Chapter 13 Security Methods Part 3.
Lecture 2 - SQL Injection
Web Hacking: Beginners
Language-based Security
SQL Injection Attack.
Presentation transcript:

University of Illinois at Chicago CANDID : Preventing SQL Injection Attacks Using Dynamic Candidate Evaluations V. N. Venkatakrishnan Assistant Professor, Computer Science University of Illinois at Chicago Joint work with: Sruthi Bandhakavi (UIUC) Prithvi Bisht (UIC) and P. Madhusudan (UIUC)

SQL Injection : Typical Query SELECT * FROM phonebook WHERE username = ‘John’ AND password = ‘open_sesame’ Phonebook Record Manager John open_sesame Username Password Submit Delete Display John’s phonebook entries are displayed Application Server SQL injection are attacks on web applications launched through specifically crafted user inputs. Lets first see how an SQL injection attack looks like. The user types in his input in a form in a web browser, which sends it over to an application server. The application server inserts the user data into a query and sends it over to a database. The database returns the results for the query, which in turn are displayed to the user in a web page. This slide shows an example of a simple phone book manager, where the application returns the phonebook entries of a particular user, given the username and the appropriate password. Web browser User Input Query Database Web Page Result Set

SQL Injection : Typical Query SELECT * FROM phonebook WHERE username = ‘John’ OR 1=1 --AND password = ‘not needed’ Phonebook Record Manager John’ OR 1=1 -- not needed Username Password Submit Delete Display All phonebook entries are displayed Application Server SQL injection are attacks on web applications launched through specifically crafted user inputs. Lets first see how an SQL injection attack looks like. The user types in his input in a form in a web browser, which sends it over to an application server. The application server inserts the user data into a query and sends it over to a database. The database returns the results for the query, which in turn are displayed to the user in a web page. This slide shows an example of a simple phone book manager, where the application returns the phonebook entries of a particular user, given the username and the appropriate password. Web browser User Input Query Database Web Page Result Set

Talk Overview [ACM CCS’07] CANDID Program Safe Web Transformer Web Application Web Application [ACM CCS’07]

SQL Injection Most systems separate code from data SQL queries can be constructed by arbitrary sequences of programming constructs that involve string operations Concatenation, substring …. Such construct also involve (untrusted) user inputs Inputs should be mere “data”, but in case of SQL results in “code” Result: Queries intended by the programmer can be “changed” by untrusted user input

Parse Structure for a Benign Query <sql_query> <where_clause> <cond_term> <cond_term> <cond> <cond> Select * from Table Conditions have two parts, joined by AND. <id> <lit> <lit> <id> WHERE username = ‘John’ AND password = ‘os’

Parse Structure for a Attack Query <sql_query> <where_clause> <comment> <cond_term> <cond_term> <cond> Select * from Table <cond> <id> <lit> Query structure changes. <lit> <lit> WHERE username = ‘John’ OR 1=1 -- AND …

Attacks Change Query Structure Boyd et. al [BK 04], ANCS ; Buehrer et. al. [BWS 05], SEM; Halfond et. al.[HO 05], ASE; Nguyen-Tuong et. al. [NGGSE 05], SEC; Pietraszek et. al[PB 05], RAID; Valeur et. al. [VMV 05], DIMVA; Su et. al. [SW 06], POPL ... <sql_query> <sql_query> <where_clause> <comment> <where_clause> <cond_term> <cond_term> <cond_term> <cond_term> <cond> <cond> <cond> <cond> <literal> <id> Colour change Leave with a strong stmt: Therefore, there has been a lot of research in this area to counter this problem. One important observation made by the previous researchers is that the structure of the malicious query is different from that of the benign query. The programmer, when writing the program has an idea about how the query’s structure should be for benign inputs. If we can find the programmer intended query structure, we can compare it with the query produced by the user input and find out if it is benign or not. <id> <lit> <lit> <lit> <id> <lit> WHERE username = ‘John’ OR 1=1 --’ AND ... WHERE username = ‘John’ AND password = ‘os’ Benign Query Attack Query

<where_clause> WHERE username = ‘?’ AND password = ‘?’ Prepared Statements <lit> <sql_query> <where_clause> <cond_term> <cond> <id> WHERE username = ‘?’ AND password = ‘?’ mysql> PREPARE stmt_name FROM " SELECT * FROM phonebook WHERE username = ? AND password = ?” placeholder for input Separates query structure from data Statements are NOT parsed for every user input Allow programmer to declare and finalize the structure of every query

Legacy Applications For existing applications adding PREPARE statements will prevent SQL injection attacks Hard to do automatically with static techniques Need to guess the structure of query at each query issue location Query issued at a location depends on path taken in program Human assisted efforts can add PREPARE statements Costly effort Problem: Is it possible to dynamically infer the benign query structure?

How can we guess benign candidate inputs for every execuction? High level idea : Dynamic Candidate Evaluations Create benign sample inputs (Candidate Inputs) for every user input Execute the program simultaneously over actual inputs and candidate inputs Generate a candidate query along with the actual query The candidate query is always non-attacking Actual query is possibly malicious Issue the actual query only if parse structures match Similarly, even in the case of benign inputs, benign candidate inputs are produced for each input variable. In this case, however, the query structures would match and the user query is sent to the database. . Actual I/P Actual Query Match Application SQL Parser DB Candidate I/P No Match Candidate Query How can we guess benign candidate inputs for every execuction?

Finding Benign Candidate Inputs Have to create a set of candidate inputs which Are Benign Issue a query at the same query issue location By following the same path in the program Candidate Path Actual Path Finding the benign candidate inputs, however, is not so straightforward. This is because the benign candidate inputs may follow a different path from the real path. This is possible in the case where the value of a conditional in the path of the program depends on the input. Therefore, we not only have to take care that the candidate inputs are benign, but also make sure that those inputs follow the same path as the real inputs. Finding the benign inputs which take the same path as the real inputs is difficult. Instead, we force the candidate inputs to follow the same path as the real inputs. We do this by executing the conditional only on the real inputs and forcing the candidate inputs to follow the same path as that of the reals. Problem: Hard In the most general case it is undecidable Query Issue Location

Our Solution : Use Manifestly benign inputs For every string create a sample string of ‘a’ s having the same length Candidate Input: uname = ‘aaaa’ pwd = ‘aa’ Shadow every intermediate string variable that depends on input For integer or boolean variable, use the originals Follow the original control flow Phonebook Record Manager John os User Name Password Submit Delete Display

Evaluate conditionals only on actual inputs Candidate Input : uname = “aaaa” pwd = “aa” display = true input str uname, str pwd, bool display User Input : uname = “john” pwd = “os” display = false Candidate Input : uname = “aaaa” pwd = “aa” true false display? query = ‘SELECT * from phonebook WHERE username = ‘ + uname + ’ AND password = ’ + pwd +’ Now assume that the delete button is selected making the real value of the delete variable true. The candidate input can be either true or false. Let’s assume that it is false, then the real and candidate inputs will take different paths and result in different queries. To avoid that, we force the candidate inputs to follow the same path as the real inputs by executing the conditional only on the real inputs and forcing the candidate inputs to take the same path. In this example, both the candidate and the real inputs form the DELETE query in the end. Forcing the candidate inputs to follow the real path may seem ad hoc, but it has a sound theoretical basis. query = ‘DELETE * from phonebook WHERE username = ‘ + uname + ’ AND password = ’ + pwd +’ Actual Query: DELETE * from phonebook WHERE username = ‘john’ AND password = ’ os’ Candidate Query: DELETE * from phonebook WHERE username = ‘aaaa’ AND password = ’aa’

CANDID Program Transformation Example i/p str uname; i/p str pwd; i/p bool delete; str uname_c; str pwd_c; uname = input_1, pwd = input_2, delete = input_3; uname_c = createSample(uname) , pwd_c = createSample(pwd); false true display? query = DELETE * from phonebook WHERE username = ‘ + uname + ’ AND password = ’ + pwd +’ query_c = DELETE * from phonebook WHERE username = ‘ + uname_c + ’ AND password = ’ + pwd_c +’; query = DELETE * from phonebook WHERE username = ‘ + uname + ’ AND password = ’ + pwd +’ Only strings are transformed Benign inputs are the same size as user input Method call duplicatedls query = SELECT * from phonebook WHERE username = ‘ + uname + ’ AND password = ’ + pwd +’ ; query = SELECT * from phonebook WHERE username = ‘ + uname + ’ AND password = ’ + pwd +’ ; query_c = SELECT * from phonebook WHERE username = ‘ + uname_c + ’ AND password = ’ + pwd_c +’; if(match_queries(query,query_c) == true) execute_query(query) execute_query(query)

Resilience of CANDID Input Splitting “Alan Turing” “aaaaaaaaaaa” Input space_index = 4 Instrumented Input Splitting Function Input Splitting Function space_index = 4 fn = input[0..3] = “Alan” fn_c = input_c[0..3] = “aaaa” ln = input[5..9] = “Turing” ln_c = input_c[5..9] = “aaaaaa” Although the CANDID transformation is very simple, it is resilient to various scenarios, two of which I will discuss in the next two slides. In the first scenario, using an example we demonstrate that the candid approach is resilient to the input splitting functions that may be used by the application program before the input is sent to the query. If the application has a filter function which splits the name into first and last names, the CANDID transformation would transform the function to also split the candidate inputs into two strings having the same length as the first and last names. Query SELECT ... WHERE first_name = “Alan” AND last_name = “Turing” SELECT ... WHERE first_name = “aaaa” AND last_name = “aaaaaa”

CANDID Implementation Architecture Offline View Online View java bytecode Java Bytecode transformer Instrumented Web Application Original Program Tomcat server Web Server SQL Parse Tree Checker The CANDID architecture consists of two views. In the offline view the application programs are transformed according to the CANDID transformation we have just seen. In the online view, the transformed application is deployed on the web server, where it dynamically detects and prevents the SQL injection attacks. The details of our implementation are in the paper. java DB Instrumented Web Application MySql Browser java bytecode

Acknowledgments: xkcd.com Thank You Questions? Acknowledgments: xkcd.com