time-based blind sql injection using heavy queries

36
Speakers: Chema Alonso José Parada Informática64 Microsoft MS MVP Windows Security IT Pro Evangelist [email protected] [email protected]

Upload: chema-alonso

Post on 20-Jun-2015

6.955 views

Category:

Technology


0 download

DESCRIPTION

This presentation was delivered in Defcon 16 held in Las Vegas in 2008. It´s about Blind SQL Injection Techniques.

TRANSCRIPT

Page 1: Time-Based Blind SQL Injection using Heavy Queries

Speakers: Chema Alonso José ParadaInformática64 MicrosoftMS MVP Windows Security IT Pro [email protected]

[email protected]

Page 2: Time-Based Blind SQL Injection using Heavy Queries

AgendaCode Injections

What are Blind Attacks?Blind SQL Injection AttacksTime-Based Blind SQL Injection

Time-Based Blind SQL Injection using heavy queriesHeavy QueriesOptimization processes

Demos with MS SQL Server, Oracle, AcessMarathon Tool

DemoConclusions

Page 3: Time-Based Blind SQL Injection using Heavy Queries

Code Injection Attacks

(Lazy) Developers use input parameters directly in queries without sanitizing them previously.Command InjectionSQL InjectionLDAP InjectionXpath Injection

Page 4: Time-Based Blind SQL Injection using Heavy Queries

Blind AttacksAttacker injects code but can´t access directly to

the data.However this injection changes the behavior of

the web application. Then the attacker looks for differences between

true code injections (1=1) and false code injections (1=2) in the response pages to extract data.Blind SQL InjectionBiind Xpath InjectionBlind LDAP Injection

Page 5: Time-Based Blind SQL Injection using Heavy Queries

Blind SQL Injection AttacksAttacker injects:

“True where clauses”“False where clauses“Ex:

Program.php?id=1 and 1=1 Program.php?id=1 and 1=2

Program doesn’t return any visible data from database or data in error messages.

The attacker can´t see any data extracted from the database.

Page 6: Time-Based Blind SQL Injection using Heavy Queries

Blind SQL Injection AttacksAttacker analyzes the response pages looking

for differences between “True-Answer Page” and “False-Answer Page”:Different hashesDifferent html structureDifferent patterns (keywords)Different linear ASCII sums“Different behavior”

By example: Response Time

Page 7: Time-Based Blind SQL Injection using Heavy Queries

Blind SQL Injection AttacksIf any difference exists, then:

Attacker can extract all information from databaseHow? Using “booleanization”

MySQL: Program.php?id=1 and 100>(ASCII(Substring(user(),1,1)))

“True-Answer Page” or “False-Answer Page”? MSSQL:

Program.php?id=1 and 100>(Select top 1 ASCII(Substring(name,1,1))) from sysusers)

Oracle: Program.php?id=1 and 100>(Select

ASCII(Substr(username,1,1))) from all_users where rownum<=1)

Page 8: Time-Based Blind SQL Injection using Heavy Queries

Blind SQL Injection Attacks: ToolsSQLbfTools: Extract all information from

MySQL databases using patterns

Page 9: Time-Based Blind SQL Injection using Heavy Queries

Blind SQL Injection Attacks: Tools

Absinthe: Extract all information from MSSQL, PostgreSQL, Sybase and Oracle Databases using Linear sum of ASCII values.

Page 10: Time-Based Blind SQL Injection using Heavy Queries

Blind SQL Injection Attacks: Tools

Absinthe: Extract all information from MSSQL, PostgreSQL, Sybase and Oracle Databases using Linear sum of ASCII values.

Page 11: Time-Based Blind SQL Injection using Heavy Queries

Time-Based Blind SQL InjectionIn scenarios with no differences between

“True-Answer Page” and “False-Answer Page”, time delays could be use.

Injection forces a delay in the response page when the condition injected is True. - Delay functions:

SQL Server: waitfor Oracle: dbms_lock.sleep MySQL: sleep or Benchmark Function

Ex: ; if (exists(select * from users)) waitfor delay '0:0:5’

Page 12: Time-Based Blind SQL Injection using Heavy Queries

Exploit for Solar Empire Web Game

Page 13: Time-Based Blind SQL Injection using Heavy Queries

Time-Based Blind SQL Injection: Tools

SQL Ninja: Use exploitation of “Waitfor” method in MSSQL Databases

Page 14: Time-Based Blind SQL Injection using Heavy Queries

Time-Based Blind SQL InjectionAnd in these scenarios with no differences

between “true-answer page” and “false-answer page”…

What about databases engines without delay functions, i.e., MS Access, Oracle connection without PL/SQL support, DB2, etc…?

Is possible to perform an exploitation of Time-Based Blind SQL Injection Attacks?

Page 15: Time-Based Blind SQL Injection using Heavy Queries

“Where-Clause” execution orderSelect “whatever “From whateverWhere condition1 and condition2

- Condition1 lasts 10 seconds- Condition2 lasts 100 seconds

Which condition should be executed first?

Page 16: Time-Based Blind SQL Injection using Heavy Queries

The heavy condition first

Condition2 (100 sec) Condition1 (10 sec) Condition2 & condition1 Response Time

TRUE FALSE FALSE 110 sec

TRUE TRUE TRUE 110 sec

FALSE Not evaluated FALSE 100 sec

Page 17: Time-Based Blind SQL Injection using Heavy Queries

The light condition first

Condition1 (10 sec) Condition2 (100 sec) Condition1 & condition2 Response Time

TRUE FALSE FALSE 110 sec

TRUE TRUE TRUE 110 sec

FALSE Not evaluated FALSE 10 sec

Page 18: Time-Based Blind SQL Injection using Heavy Queries

Time-Based Blind SQL Injectionusing Heavy QueriesAttacker can perform an exploitation

delaying the “True-answer page” using a heavy query.

It depends on how the database engine evaluates the where clauses in the query.

There are two types of database engines:Databases without optimization processDatabases with optimization process

Page 19: Time-Based Blind SQL Injection using Heavy Queries

Databases without optimization process

The engine evaluates the condition in the where-clause from left to right or from right to left depending on the database engine Select items from table where codition1 and

condition2.It is a developer task to evaluate the lighter

condition in first place for better performance.Examples:

Oracle (without statistics or poor tuned): Right to Left

Access: Right to Left

Page 20: Time-Based Blind SQL Injection using Heavy Queries

Databases with optimization processThe engine estimates the cost of the condition

evaluations in the where clause and executes the lighter first. No matter where it is.

Select items from table where codition1 and condition2.It is a database engine task to improve the

performance of the query.Examples

MS SQL ServerOracle (statistics ON and well tuned)

An Attacker could exploit a Blind SQL Injection attack using heavy queries to obtain a delay in the “True-answer page” in both cases.

Page 21: Time-Based Blind SQL Injection using Heavy Queries

Time-Based Blind SQL Injectionusing Heavy QueriesAttacker could inject a heavy Cross-Join condition

for delaying the response page in True-Injections. The Cross-join injection must be heavier than the

other condition.Attacker only have to know or to guess the name

of a table with select permission in the database.Example in MSSQL:

Program.php?id=1 and (SELECT count(*) FROM sysusers AS sys1, sysusers as sys2, sysusers as sys3, sysusers AS sys4, sysusers AS sys5, sysusers AS sys6, sysusers AS sys7, sysusers AS sys8)>0 and 300>(select top 1 ascii(substring(name,1,1)) from sysusers)

Page 22: Time-Based Blind SQL Injection using Heavy Queries

“Default” tables to construct a heavy queries

Microsoft SQL Server sysusers

Oracle all_users

MySQL (versión 5) information_schema.columns

Microsoft Access MSysAccessObjects (97 & 2000 version) MSysAccessStorage (2003 & 2007)

22

Page 23: Time-Based Blind SQL Injection using Heavy Queries

“Default” tables to construct a heavy queries…or whatever you can guess

ClientsCustomersNewsLoginsUsersProviders….Use your imagination…

Page 24: Time-Based Blind SQL Injection using Heavy Queries

Demo 1: MS SQL Server

Query lasts 14 seconds -> True-Answer

Page 25: Time-Based Blind SQL Injection using Heavy Queries

Demo 1: MS SQL Server

Query lasts 1 second -> False-Answer

Page 26: Time-Based Blind SQL Injection using Heavy Queries

Demo 2: Oracle

Query Lasts 22 seconds –> True-Answer

Page 27: Time-Based Blind SQL Injection using Heavy Queries

Demo 2: Oracle

Query Lasts 1 second –> False-Answer

Page 28: Time-Based Blind SQL Injection using Heavy Queries

Demo 3: Access 2000

Query Lasts 6 seconds –> True-Answer

Page 29: Time-Based Blind SQL Injection using Heavy Queries

Demo 3: Access 2000

Query Lasts 1 second –> False-Answer

Page 30: Time-Based Blind SQL Injection using Heavy Queries

Demo 4: Access 2007

Query Lasts 39 seconds –> True-Answer

Page 31: Time-Based Blind SQL Injection using Heavy Queries

Demo 4: Access 2007

Query Lasts 1 second –> False-Answer

Page 32: Time-Based Blind SQL Injection using Heavy Queries

Marathon ToolAutomates Time-Based Blind SQL Injection

Attacks using Heavy Queries in SQL Server, MySQL, MS Access and Oracle Databases.

Schema Extraction from known databasesExtract data using heavy queries not matter

in which database engine (without schema)Developed in .NETSource code available

Page 33: Time-Based Blind SQL Injection using Heavy Queries
Page 34: Time-Based Blind SQL Injection using Heavy Queries

ConclusionsTime-Based Blind SQL Injection using Heavy

Queries works with any database.The delay generated with a heavy query

depends on the environment of the database and the network connection.

It is possible to extract all the information stored in the database using this method.

It is another bullet….

Page 35: Time-Based Blind SQL Injection using Heavy Queries

Questions?

Page 36: Time-Based Blind SQL Injection using Heavy Queries

Speakers:Chema Alonso

[email protected] Microsoft MVP Windows Security Security Consultant Informática64

José Parada [email protected] Microsoft IT Pro Evangelist Microsoft

Authors: Chema Alonso ([email protected]) Daniel Kachakil ([email protected]) Rodolfo Bordón ([email protected]) Antonio Guzmán ([email protected]) Marta Beltrán ([email protected])

36