SQL Injection. Sajjad Pourali sajjad@securation.com CERT of Ferdowsi University of Mashhad



Similar documents
SQL Injection. SQL Injection. CSCI 4971 Secure Software Principles. Rensselaer Polytechnic Institute. Spring

SQL Injection. The ability to inject SQL commands into the database engine through an existing application

WebCruiser Web Vulnerability Scanner User Guide

Serious Threat. Targets for Attack. Characterization of Attack. SQL Injection 4/9/2010 COMP On August 17, 2009, the United States Justice

Understanding Sql Injection

SQL INJECTION TUTORIAL

EC-Council CAST CENTER FOR ADVANCED SECURITY TRAINING. CAST 619 Advanced SQLi Attacks and Countermeasures. Make The Difference CAST.

PHP/MySQL SQL Injections: Understanding MySQL Union Poisoining. Jason A. Medeiros :: CEO :: Presented for DC619 All Content Grayscale Research 2008

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Time-Based Blind SQL Injection using Heavy Queries A practical approach for MS SQL Server, MS Access, Oracle and MySQL databases and Marathon Tool

Automating SQL Injection Exploits

How I hacked PacketStorm ( )

Managing Objects with Data Dictionary Views. Copyright 2006, Oracle. All rights reserved.

Advanced PostgreSQL SQL Injection and Filter Bypass Techniques

SECURING APACHE : THE BASICS - III

Advanced Security for Systems Engineering VO 01: Web Application Security

Webapps Vulnerability Report

SQL Injection January 23, 2013

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

SQL Injection for newbie

VIDEO intypedia007en LESSON 7: WEB APPLICATION SECURITY - INTRODUCTION TO SQL INJECTION TECHNIQUES. AUTHOR: Chema Alonso

Web Application Security

SQL injection: Not only AND 1=1. The OWASP Foundation. Bernardo Damele A. G. Penetration Tester Portcullis Computer Security Ltd

External Network & Web Application Assessment. For The XXX Group LLC October 2012

Concepts Design Basics Command-line MySQL Security Loophole

Testing Web Applications for SQL Injection Sam Shober

SQL Injection Optimization and Obfuscation Techniques

1. Building Testing Environment

SQL Injection 2.0: Bigger, Badder, Faster and More Dangerous Than Ever. Dana Tamir, Product Marketing Manager, Imperva

Check list for web developers

Agenda. SQL Injection Impact in the Real World Attack Scenario (1) CHAPTER 8 SQL Injection

Manipulating Microsoft SQL Server Using SQL Injection

INTRUSION PROTECTION AGAINST SQL INJECTION ATTACKS USING REVERSE PROXY

SQL Injection Vulnerabilities in Desktop Applications

Web Application Attacks And WAF Evasion

SQL INJECTION ATTACKS By Zelinski Radu, Technical University of Moldova

What? Me, Worry? I've Already Been Hacked. Haven't You?

BLIND SQL INJECTION (UBC)

FmPro Migrator - FileMaker to SQL Server

Advanced Web Technology 10) XSS, CSRF and SQL Injection 2

Analysis of SQL injection prevention using a proxy server

Black Hat Briefings USA 2004 Cameron Hotchkies

SQL INJECTION IN MYSQL

Secure Web Application Coding Team Introductory Meeting December 1, :00 2:00PM Bits & Pieces Room, Sansom West Room 306 Agenda

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

How? $ & developers defeat the most famous web vulnerability scanners or how to recognize old friends

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Web Applications Security: SQL Injection Attack

Sharding with postgres_fdw

Unit 10: Microsoft Access Queries

Cyber Security Challenge Australia 2014

White Paper. Blindfolded SQL Injection

Security and Control Issues within Relational Databases

MapReduce. MapReduce and SQL Injections. CS 3200 Final Lecture. Introduction. MapReduce. Programming Model. Example

Improved Penetration Testing of Web Apps and Databases with MatriXay

SQL Injection. By Artem Kazanstev, ITSO and Alex Beutel, Student

Advanced SQL. Jim Mason. Web solutions for iseries engineer, build, deploy, support, train

Cracking the Perimeter via Web Application Hacking. Zach Grace, CISSP, CEH January 17, Mega Conference

Still Aren't Doing. Frank Kim

How to Make Your Oracle APEX Application Secure

IP Application Security Manager and. VMware vcloud Air

Security Test s i t ng Eileen Donlon CMSC 737 Spring 2008

SQL Injec*on Preven*on. May 3rd 2012

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Revisiting SQL Injection Will we ever get it right? Michael Sutton, Security Evangelist

Oracle Database 12c: Introduction to SQL Ed 1.1

Relational Databases for the Business Analyst

ASL IT Security Advanced Web Exploitation Kung Fu V2.0

Guarding Against SQL Server Attacks: Hacking, cracking, and protection techniques.

SQL INJECTION ATTACKS

Database security issues PETRA BILIĆ ALEXANDER SPARBER

SQL Injection Are Your Web Applications Vulnerable?

Understanding Web Application Security Issues

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

How About Security Testing?

Web Application Firewall Bypassing

Øredev Web application testing using a proxy. Lucas Nelson, Symantec Inc.

SQL Injection Attack Lab Using Collabtive

SQL Injection. Slides thanks to Prof. Shmatikov at UT Austin

E-Commerce: Designing And Creating An Online Store

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Stopping SQL Injection and. Manoranjan (Mano) Paul. Track: Operating Systems Security - Are we there yet?

DBMS Project. COP Spring Final Submission Report

Jet Data Manager 2012 User Guide

Using SQL Server Management Studio

Easy Method: Blind SQL Injection

AUTOMATE CRAWLER TOWARDS VULNERABILITY SCAN REPORT GENERATOR

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

ASL IT SECURITY BEGINNERS WEB HACKING AND EXPLOITATION

Updated SQL Injection

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

MySQL for Beginners Ed 3

Start Secure. Stay Secure. Blind SQL Injection. Are your web applications vulnerable? By Kevin Spett

Oracle Database 10g: Introduction to SQL

(WAPT) Web Application Penetration Testing

Web Development using PHP (WD_PHP) Duration 1.5 months

1. What is SQL Injection?

Transcription:

SQL Injection Sajjad Pourali sajjad@securation.com CERT of Ferdowsi University of Mashhad

SQL Injection Ability to inject SQL commands into the database engine Flaw in web application, not the DB or web server Many programmers are not fully aware of this problem 1

SQL Injection Risk Almost all databases and programming languages are vulnerable (MS SQL Server, MySQL, Oracle, Postgre, ) Attacker is able to: oadd new data o Delete current data o Modify current data Can gain access to other parts of the server 2

How SQL Injection Works Vulnerable Login Page uname = getrequeststring("username"); upass = getrequeststring("userpass"); sql = "SELECT * FROM Users WHERE Name ='" + uname + "' AND Pass ='" + upass + "'" 3

How SQL Injection Works ' or '1'='1 Vulnerable Login Page ' or '1'='1 sql = "SELECT * FROM Users WHERE Name ='' or '1'='1' AND Pass ='' or '1'='1''" 4

How SQL Injection Works admin'-- Vulnerable Login Page sql = "SELECT * FROM Users WHERE Name ='admin'--' AND Pass =''''" 5

SQL Injection Testing Methodology 1) Input Validation 2) Info. Gathering 3) 1=1 Attacks 5) OS Interaction 4) Extracting Data 6) OS Cmd Prompt 7) Expand Influence 6

Input Validation 1) Input Validation 2) Info. Gathering 3) 1=1 Attacks 5) OS Interaction 4) Extracting Data 6) OS Cmd Prompt 7) Expand Influence 7

Discovery of Vulnerabilities Vulnerabilities can be anywhere (check all entry points) ofields in web forms o Script parameters in URL query strings o Values stored in cookies,headers or hidden files Generate and insert random strings through fuzzing ocharacter Sequences: ' " ) # + > o Delay query: and sleep(10)=1 Analyze application s response 8

Information Gathering 1) Input Validation 2) Info. Gathering 3) 1=1 Attacks 5) OS Interaction 4) Extracting Data 6) OS Cmd Prompt 7) Expand Influence 9

Information Gathering Our goal is to find out the following: 1. Output Mechanism 2. Understand the query 3. Determine database type 4. Find out user privilege level 5. Determine OS interaction level 10

1) Exploring output mechanisms Using result sets in the web application Error messages Craft SQL queries that generate specific types of error messages with valuable information Blind SQL Injection Use time delays or error signatures to extract information Much slower and more difficult 11

Extracting Information with Error Messages ExtractValue Error (MySQL) and ExtractValue(1,Query) Result is unable to Extract values from xml string Type Mismatch (MS SQL) or 1=convert(int,Query) Error messages shows the data that could not get converted 12

Blind SQL Injection We can use different known outcomes and condition Or we can use if statements ; select if ((condition),sleep(10),1)) -- Can run all queries, but with no debugging information! Only Yes/No responses We can extract ASCII one bit at a time Very time consuming but easier with automated tools like BBQ 13

2) Understanding the Query The query can be: SELECT UPDATE INSERT Other Knowing the context helps What is the form / page trying to do with our input? What is the name of the field / parameter? 14

SELECT Statement Most injections will land in the middle of a select statement In the select, we almost always end up in the where section SELECT * FROM table WHERE x = 'normalinput' Injection Data -- GROUP BY x HAVING x = y ORDER BY x 15

UPDATE Statement In a change your password section of an app we may have: UPDATE users SET password = 'new password' WHERE login = logged.user AND password = 'old password If you inject a new password and comment the rest, you end up changing every password in the table! 16

Determining a SELECT Query Structure 1. Try to replicate an error-free navigation Could be as simple as ' and '1'='1 Or ' and '1'='2 2. Generate specific query Determine table and column names ' union select table_name form information_schema.tables 17

3) Determining Database Engine Type Most times the error messages will let us know which type of database engine we are working with In other cases We can make an educated guess based on OS and Web Server Or we can use DB-specific characters, commands or stored procedures Manually request database information (blind SQL injection) 18

Some Differences MS SQL T-SQL MySQL Access Oracle PL/SQL DB2 Postgres PL/pgSQL Concaten ate Strings ' '+' ' concat (" ", " ") " "&" " ' ' ' ' " "+" " ' ' ' ' Null replace Isnull() Ifnull() Iff(Isnull()) Ifnull() Ifnull() COALESCE() Position CHARINDEX LOCATE() InStr() InStr() InStr() TEXTPOS() Op Sys interactio n xp_cmdshell select into outfile / dumpfile #date# utf_file import from export to Call Cast Yes No No No Yes Yes 19

1 = 1 Attacks 1) Input Validation 2) Info. Gathering 3) 1=1 Attacks 5) OS Interaction 4) Extracting Data 6) OS Cmd Prompt 7) Expand Influence 20

System Tables General INFORMATION_SCHEMA TABLES COLUMNS. Oracle SYS USER_TABLES USER_VIEWS ALL_TABLES USER_TAB_COLUMNS USER_CATALOG MySQL Mysql User Host MS SQL Server Master Sysobjects Syscolumns Systypes Sysdatabases 21

Enumeration using Metadata Enumerating databases in MySQL Select schema_name from information_schema.schemata Enumerating tables in MySQL Select column_name from information_schema.tables where table_schema= dbname Enumerating columns in MySQL Select column_name from information_schema.columns where table_name = tablename 22

Mitigation Techniques Primary Defenses: Use of Prepared Statements (Parameterized Queries) Use of Stored Procedures Escaping all User Supplied Input Additional Defenses: Also Enforce: Least Privilege Also Perform: White List Input Validation 23

Question!? 24