SQL Injection.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Nick Feamster CS 6262 Spring 2009
9/9/2005 Developing "Secure" Web Applications 1 Methods & Concepts for Developing “Secure” Web Applications Peter Y. Hammond, Developer Wasatch Front Regional.
Introduction The concept of “SQL Injection”
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
DT211/3 Internet Application Development JSP: Processing User input.
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 IS 2150 / TEL 2810 Introduction to Security James Joshi Associate Professor, SIS Lecture 12.1 Nov 20, 2012 SQL Injection Cross-Site Scripting.
Check That Input Preventing SQL Injection Attacks By Andrew Morton For CS 410.
MIS Week 11 Site:
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
+ Websites Vulnerabilities. + Content Expand of The Internet Use of the Internet Examples Importance of the Internet How to find Security Vulnerabilities.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
(CPSC620) Sanjay Tibile Vinay Deore. Agenda  Database and SQL  What is SQL Injection?  Types  Example of attack  Prevention  References.
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.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications 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.
Attacking Applications: SQL Injection & Buffer Overflows.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
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.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
© Copyright 2013 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice. 1 RubyJax Brent Morris/
Attacking Data Stores Brad Stancel CSCE 813 Presentation 11/12/2012.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Injection CSC 482/582: Computer SecuritySlide #1.
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.
Aniket Joshi Justin Thomas. Agenda Introduction to SQL Injection SQL Injection Attack SQL Injection Prevention Summary.
Web Applications Testing By Jamie Rougvie Supported by.
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.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
CHAPTER 7 Unexpected Input. INTRODUCTION What is Unexpected Input? Something (normally user-supplied data) that is unexpected happen to an application.
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
Example – SQL Injection MySQL & PHP code: // The next instruction prompts the user is to supply an ID $personID = getIDstringFromUser(); $sqlQuery = "SELECT.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
SQL Injection Josh Mann. What is SQL Injection  SQL injection is a technique for exploiting web applications that use client-supplied data in SQL queries.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Error-based SQL Injection
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.
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.
Cosc 5/4765 Database security. Database Databases have moved from internal use only to externally accessible. –Organizations store vast quantities of.
CS3220 Web and Internet Programming Database Access with JDBC
Group 18: Chris Hood Brett Poche
Module: Software Engineering of Web Applications
CSCE 548 Student Presentation Ryan Labrador
SQL Primer Boston University CS558 Network Security Fall 2015
CSC 482/582: Computer Security
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Theodore Lawson CSCE548 Student Presentation, Topic #2
CS320 Web and Internet Programming Database Access with JDBC
SQL INJECTION ATTACKS.
SQL Injection Attacks Many web servers have backing databases
Intro to PHP & Variables
Intro to Ethical Hacking
Defense in Depth Web Server Custom HTTP Handler Input Validation
Chapter 13 Security Methods Part 3.
Lecture 2 - SQL Injection
Intro to Ethical Hacking
PHP Forms and Databases.
Lecture 27 Security I April 4, 2018 Open news web sites.
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

SQL Injection

SQL Injection SQL Injection is ranked number one in the CWE/SANS list of the top 25 most dangerous software errors!

SQL Injection: Basic Idea An application sends a form to user. An attacker submits form with SQL exploit data. The application builds string with exploit data. (does not filter the data) The application sends SQL query to a relational DBMS. The DBMS executes query, including exploit, sends data back to application. The application returns data to user.

Example: SQL Injection Form for “Email me my password” Assume that the application takes the user input and creates a SQL statement of the form select <fieldlist> from <table> where <field> = '<%=email%>'; Consider what would happen if the user entered the following into the form anything' or 'x' = 'x Email Address: value entered into form by the user

Example: SQL Injection (continued) SQL statement becomes select <fieldlist> from <table> where <field> = 'anything' or 'x' = 'x'; Note that the second statement is guaranteed to be true, and therefore the select statement would return the entire table. What if the response to submitting the form was something like At this point we know that the web site is subject to an SQL injection attack. Your login information has been mailed to john.doe@example.com

Exploits of a Mom

Finding SQL Injection Bugs Submit a single quote as input. If an error results, the application is vulnerable. If no error, check for any output changes. Submit two single quotes. Databases use two single quotes to represent the literal ' If an error disappears, the application is vulnerable. Try string or numeric operators. Oracle: '||'FOO MS-SQL: '+'FOO MySQL: ' 'FOO 2-2 81+19 49-ASCII(1)

Make Guesses for Field Names Enter data so that query becomes something like select ... where <field> = 'x' and email is null; -- Can try various values for field names such as email – email_addr email_address – mail Repeat on other forms to guess field names for password – pwd user_id – login_id name – last_name guess for field name comments out any remaining SQL parts

Make Guesses for Table Name Use a subquery. Enter data so that the query becomes something like select ... where email = 'x' and 1 = (select count(*) from users); --; Try different guesses. When the query returns “Email unknown”, we know that the SQL was well-formed and that we have guessed the table name. guess for table name

Impact of SQL Injection Leakage of sensitive information. Reputation decline. Modification of sensitive information. Loss of control of db server. Data loss. Denial of service.

Mitigating SQL Injection Use blacklists (a.k.a., filtering). filter out potentially bad characters such as a single quote Use whitelists. restrict input to only allowable characters such as letters, numbers, @ sign, etc. Process SQL queries using prepared statements, parameterized queries, or stored procedures. the user input is supplied as a value for the parameter Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid; e.g., Hibernate or Enterprise Java Beans.

Blacklists (a.k.a., Filtering) Filter out or sanitize known bad SQL meta-characters such as single quotes. Problems: Numeric parameters don’t use quotes. URL escaped metacharacters. Unicode encoded metacharacters. Did you miss any metacharacters? Although it’s easy to point out some dangerous characters, it’s harder to point to all of them.

JavaServer Pages (JSP) Filters in Java Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated with servlets, JSP pages, HTML pages, etc. Filters can be used to query the request and act accordingly block the request and response pair from passing any further modify the request headers and data, providing a customized version of the request modify the response headers and data, providing a customized version of the response. Think of filters as a chain of steps that requests and responses must go through before reaching a servlet, JSP page, or HTML page. ©SoftMoore Consulting

Filters in Action Server Filter 1 HTML Page Client (browser) JSP Page HTTP Request Filter 1 HTML Page Client (browser) HTTP Response JSP Page HTTP Request Client (browser) Filter 2 Servlet HTTP Response ©SoftMoore Consulting

BadInputFilter revisited BadInputFilter provides a frontline of defense against common web application security exploits such as SQL injection attacks and cross-site scripting. Unfortunately, BadInputFilter was designed for a specific version of Tomcat (a Java web server), and it breaks silently in newer versions of Tomcat. This paper provided an update and correction to BadInputFilter that should run correctly in any Java web server. John I. Moore, Jr.

Whitelist Reject input that doesn’t match your list of safe characters to accept. Identify which characters should be allowed for each input field. Reject input instead of attempting to repair. Might still need to handle some potentially dangerous characters such as single quotes in a name (e.g., O’Neill).

Prepared Statements in Java String query = "SELECT email FROM members WHERE name = ?"; PreparedStatement ps = connection.prepareStatement(query); ps.setString(1, formField); ResultSet rs = ps.executeQuery(); Since a prepared statement is parsed only once, there could also be performance benefits if it is reused multiple times (e.g., in a loop), but the performance benefits are minor compared to the security benefits.

Relevant Links SQL Injection Attacks by Example http://www.unixwiz.net/techtips/sql-injection.html SQL Injection (Wikipedia) https://en.wikipedia.org/wiki/SQL_injection BadInputFilter revisited (John Moore, JavaWorld) http://www.javaworld.com/article/2078901/open-source-tools/badinputfilter-revisited.html 2011 CWE/SANS Top 25 Most Dangerous Software Errors http://cwe.mitre.org/top25/ ©SoftMoore Consulting