Black Hat Briefings USA 2004 Cameron Hotchkies cameron@0x90.org



Similar documents
Using SQL Server Management Studio

Automating SQL Injection Exploits

How To Create A Table In Sql (Ahem)

SQL Server An Overview

Ontrack PowerControls V8.1 for SQL ReadMe

Ontrack PowerControls User Guide Version 8.0

Microsoft SQL Server Connector for Apache Hadoop Version 1.0. User Guide

SQL Server Table Design - Best Practices

Webapps Vulnerability Report

ODBC Client Driver Help Kepware, Inc.

Web Application Hacking (Penetration Testing) 5-day Hands-On Course

Botnet-Powered SQL Injection Attacks A Deeper Look Within (VB, Sep. 2009) David Maciejak Guillaume Lovet

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

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

INTRUSION PROTECTION AGAINST SQL INJECTION ATTACKS USING REVERSE PROXY

How I hacked PacketStorm ( )

Intrusion detection for web applications

MS ACCESS DATABASE DATA TYPES

ASL IT SECURITY BEGINNERS WEB HACKING AND EXPLOITATION

Database Migration from MySQL to RDM Server

Manipulating Microsoft SQL Server Using SQL Injection

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

Analysis of SQL injection prevention using a proxy server

Maintaining Stored Procedures in Database Application

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

Spring,2015. Apache Hive BY NATIA MAMAIASHVILI, LASHA AMASHUKELI & ALEKO CHAKHVASHVILI SUPERVAIZOR: PROF. NODAR MOMTSELIDZE

Automating Security Testing. Mark Fallon Senior Release Manager Oracle

METHODS OF QUICK EXPLOITATION OF BLIND SQL INJECTION DMITRY EVTEEV

Fact Sheet In-Memory Analysis

Advanced PostgreSQL SQL Injection and Filter Bypass Techniques

Attack and Penetration Testing 101

Exposed Database( SQL Server) Error messages Delicious food for Hackers

Penetration Testing with Kali Linux

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

Using Web Security Scanners to Detect Vulnerabilities in Web Services

Pentests more than just using the proper tools

OWASP OWASP. The OWASP Foundation Selected vulnerabilities in web management consoles of network devices

Application Security Testing. Generic Test Strategy

Penetration Testing. NTS330 Unit 1 Penetration V1.0. February 20, Juan Ortega. Juan Ortega, juaorteg@uat.edu. 1 Juan Ortega, juaorteg@uat.

Blind SQL Injection Are your web applications vulnerable?

Report on the Train Ticketing System

White Paper. Blindfolded SQL Injection

Detecting (and even preventing) SQL Injection Using the Percona Toolkit and Noinject!

SQL Server Array Library László Dobos, Alexander S. Szalay

Web Application Security

Microsoft SQL connection to Sysmac NJ Quick Start Guide

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

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

Comparison of Open Source RDBMS

Penetration Testing Lessons Learned. Security Research

Penetration Testing. Types Black Box. Methods Automated Manual Hybrid. oless productive, more difficult White Box

Still Aren't Doing. Frank Kim

BLIND SQL INJECTION (UBC)

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

SQL Injection. Sajjad Pourali CERT of Ferdowsi University of Mashhad

FINAL DoIT v.8 APPLICATION SECURITY PROCEDURE

Software Assurance Tools: Web Application Security Scanner Functional Specification Version 1.0

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

Pre-authentication XXE vulnerability in the Services Drupal module

The Weakest Link: Mitigating Web Application Vulnerabilities. webscurity White Paper. webscurity Inc. Minneapolis, Minnesota USA

ABC LTD EXTERNAL WEBSITE AND INFRASTRUCTURE IT HEALTH CHECK (ITHC) / PENETRATION TEST

PHP Magic Tricks: Type Juggling. PHP Magic Tricks: Type Juggling

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

Understanding Web Application Security Issues

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

Microsoft SQL Server to Infobright Database Migration Guide

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

Check list for web developers

Blindfolded SQL Injection. Written By: Ofer Maor Amichai Shulman

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Threat Modeling. Categorizing the nature and severity of system vulnerabilities. John B. Dickson, CISSP

MYSQL DATABASE ACCESS WITH PHP

DISCOVERY OF WEB-APPLICATION VULNERABILITIES USING FUZZING TECHNIQUES

Best Practices in SQL Programming. Madhivanan

Integrating VoltDB with Hadoop

Detecting SQL Injection Vulnerabilities in Web Services

Financial Data Access with SQL, Excel & VBA

Finding XSS in Real World

Pentests more than just using the proper tools

F5 ASM i DB Monitoring w ofercie NASK

Architecting the Future of Big Data

Hacking de aplicaciones Web

SPARROW Gateway. Developer API. Version 2.00

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

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

WEB FOR PENTESTER II By Louis Nyffenegger

The SkySQL Administration Console

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

(WAPT) Web Application Penetration Testing

Louis Luke

XEP-0043: Jabber Database Access

The purpose of this report is to educate our prospective clients about capabilities of Hackers Locked.

Vulnerability Assessment and Penetration Testing

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

MIB Explorer Feature Matrix

Transcription:

Blind SQL Injection Automation Techniques Black Hat Briefings USA 2004 Cameron Hotchkies cameron@0x90.org

What is SQL Injection? Client supplied data passed to an application without appropriate data validation Processed as commands by the database

Frequently Used To: Perform operations on the database Bypass authentication mechanisms Read otherwise unavailable information from the database Write information such as new user accounts to the database

Three Forms of SQL Injection There are three main forms of SQL Injection used to read information from a database Redirection and reshaping a query Error message based Blind Injection

Blind SQL Injection Blind SQL Injection techniques can include forming queries resulting in boolean values, and interpreting the output HTML pages SQL Injection can result in significant data leakage and/or data modification attacks Blind attacks are essentially playing 20 questions with the web server

Why focus on Blind Injections? Blind injections are as common as any other injection Blind holes involve a false sense of security on the host Requires a larger investment of time to execute manual penetration against

Benefits of an Automated Tool We can ask the server as many yes/no questions as we want Finding the first letter of a username with a binary search takes 7 requests Finding the full username if it s 8 characters takes 56 requests To find the username is 8 characters takes 6 requests 62 requests just to find the username This adds up

Benefits Cont d Assuming it takes 10 seconds to make each request Assuming the pentester makes no mistakes The 8 character username takes over ten minutes What if we want the schema or the entire database?

Benefits Cont d If you want non-trivial penetration Table names Column names Actual Data This would take hours or days or longer depending on the size of the database

Sound Simple? An effective tool is more complex than a few shell scripts and netcat

Searching for Integers Select a range (usually starting with 0) Increase value exponentially by a factor of two until upper limit is discovered Partition halfway between upper limit and previous value Continue to halve sections until one value remains

Problem How do we recognize true vs false pages from the web server? We take pattern recognition for granted Can t we just do a string compare? NO! The whole point of a web application is to have dynamic content It s entirely likely that the section indicating the true/false is not the only dynamic content String comparison is suitable for error based injection but not blind injection

Solution One: Keyword Search Requires direct intervention of the user User interaction requires effort to be expended which is what we are trying to minimize

Solution Two: MD5 Sum Web Applications are designed to be dynamic MD5 causes large output changes from small input changes

Google vs. Hoogle

MD5 Sum Comparison MD5 does not handle changes well May work on some web applications, but not comprehensive

Solution Three: Text Difference Engine Text difference tools are designed to highlight informational changes that we are not concerned with. A lot of effort is wasted to retain information that will simply be discarded.

Solution Four: Parse HTML Tree Represent text as html entities in a tree data structure Look for differences in the shape of the trees If only non-markup data is changing, there will be no way to proceed in automation Easier to implement an xhtml parser than a realistic html parser

Solution Five: Linear Representation of ASCII Sums small input variation = small output variation

Signature Comparison Generating base cases Will need base cases for comparison of unknowns We already know guaranteed true/false pages We have multiple options for known base cases Easiest is 1=1 vs 1=0 http://www.vulnsite.com/catalog.asp?id=7 AND 1=1 http://www.vulnsite.com/catalog.asp?id=7 AND 1=0

Sample Signature Set

Realistic Signature Set

Tolerance Band Comparison Minor changes in textual content result in small overall changes in sum Changes still occur Allowing for tolerance instead of exact comparison in sums lessens false negatives Σ known Σ unknown / Σ known

Tolerance Band Comparison

Shortcomings of Tolerance Band Comparison It works, but there are a lot of unnecessary comparisons Doesn t take advantage of known garbage data

Subtractive Filter We can identify sums that are equal between conflicting base cases

Subtractive Filter This can be combined with the tolerance band to eliminate unnecessary comparisons

Adaptive Filter Allows the application to be profiled before testing against unknowns Removes junk data that could skew results Requires multiple base cases

Two Identical Samples 1 = 1 vs 2 = 2

Adaptive Filter Applied 1 = 1 vs 2 = 2

Benefits of Adaptive Filter Tolerance is mostly unnecessary at this point Removes most dynamic content unrelated to the data leakage

SQueaL SQueaL was created alongside the research being presented Written in C# for Windows & Linux Both Windows.Forms & Gtk-Sharp GUIs available Free for non-commercial use Black Hat Conference CDs include a commercially licensed version (Free for you) Exports data to an XML format for nice presentation to clients/phbs

SQueaL: Exporting Data SQueaL uses it s own XML format for saving exploit data <SQueaLdata version="0.01a"> <target address="vulnerable.org:8080/test.php" method="get" ssl="false"> <parameter name="prod_id" value="2" injectable="true" /> </target> <attackvector name="prod_id" buffer="2" type="blindtsqlinjection"> <truepage> <signature-item>3029</signature-item> <signature-item>3897</signature-item> <signature-item>572</signature-item>...

Gathering Table Info We start with the ID number for each table:... AND (SELECT COUNT(name) FROM sysobjects WHERE xtype=char(85)) > search_value... AND (SELECT MIN(id) FROM sysobjects WHERE id > prev_table_id AND xtype=char(85)) > search_value

More Table Info We can now retrieve each table s recognizable name... AND (SELECT TOP 1 LEN(name) FROM sysobjects WHERE id= table_id AND xtype=char(85)) > search_value... AND (SELECT ASCII(SUBSTRING(name, character_counter,1)) FROM sysobjects WHERE id=table_id) > search_value

Gathering Field Information Once we have the table information, we can move on to the fields... AND (SELECT COUNT(name) FROM syscolumns WHERE id=table_id) > search_value... AND (SELECT MIN(colid) FROM syscolumns WHERE colid > prev_colid AND id=table_id) > search_value

Field Info Cont d... AND (SELECT TOP 1 LEN(name) FROM sysobjects WHERE id=table_id AND colid=colid) > search_value... AND (SELECT ASCII(SUBSTRING(name, character_counter, 1)) FROM syscolumns WHERE id=table_id AND colid=colid) > search_value... AND (SELECT TOP 1 (xtype) FROM syscolumns WHERE id=table_id AND colid=colid) > search_value

Field Data Types Gathering field data types is faster, but requires knowledge the type mapping: 34 Image 36 UniqueIdentifier 52 SmallInt 58 SmallDateTime 60 Money 62 Float 104 Bit 108 Numeric 127 BigInt 167 VarChar 175 Char 231 NVarChar *Datatype values taken from MSDE 35 48 56 59 61 99 106 122 165 173 189 239 Text TinyInt Int Real DateTime Ntext Decimal SmallMoney VarBinary Binary Timestamp Nchar

SQueaL: Running Time Sample web application resulted in over 2700 HTTP requests If we use the 10 second estimate from earlier, this would have taken over 7.5 hours non-stop A real production database would be even larger and longer

Shortcomings / Mitigations User-Agent Noise generation / Server log DoS HTML Sums can be poisoned with random seeds Doesn t lower the bar for finding exploits Troubles with no carriage returns / auto generated HTML

Forced CRLF What happens when HTML is generated without carriage returns? Natural tendency to force carriage returns This will throw off the data At this point, an HTML parser would be needed

Conclusion Same techniques can be utilized with queries indicating invalid SQL Treat these as questions such as Is this syntax valid? which in now a yes/no question MD5 Bad for these purposes Same techniques can be utilized in other applications to interpret results from HTML responses XPath Injection LDAP Injection Use Parameterized code in an appropriate fashion to call stored procedures

References & Suggested Papers Advanced SQL Injection in SQL Server Applications [Chris Anley, NGS Systems] http://www.nextgenss.com/papers/advanced_sql_injection.pdf (more) Advanced SQL Injection [Chris Anley, NGS Systems] http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf Blind SQL Injection: Are your web-apps Vulnerable? [Kevin Spett, SPI Dynamics] http://www.spidynamics.com/whitepapers/blind_sqlinjection.pdf

Questions & Answers This, and other tools are available for download at: http://www.0x90.org/releases/