sql injection v.2

25
SQL – injections for Dummies OWASP Community Lviv Bohdan Serednytskyi, Security Engineer, R&D Team, SoftServe August, 2012

Upload: tjylen-veselyj

Post on 23-Jan-2015

1.022 views

Category:

Documents


1 download

DESCRIPTION

Highlevel review of SQL injections technique and methods of avoiding security fails

TRANSCRIPT

Page 1: Sql Injection V.2

SQL – injections for Dummies

OWASP Community Lviv

Bohdan Serednytskyi, Security Engineer, R&D Team, SoftServe August, 2012

Page 2: Sql Injection V.2

Easy to exploit!

Common in Web Apps!

Severe impact!

Page 3: Sql Injection V.2

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

SQL-Injection

Page 4: Sql Injection V.2

SQL-Injection Impact

Page 5: Sql Injection V.2

Data Leakage

Page 6: Sql Injection V.2

Data Modification

Page 7: Sql Injection V.2

Denial of Access

Page 8: Sql Injection V.2

Data Loss

Page 9: Sql Injection V.2
Page 10: Sql Injection V.2

Complete host takeover

Page 11: Sql Injection V.2

Vulnerable request can handle Insert, Update, Delete

SQL-Injection

It is a flaw in "web application" development, it is not a DB or web server problem

Almost all SQL databases and programming languages are potentially vulnerable

Page 12: Sql Injection V.2

SQL-Injection Anatomy

SQL-injection

SQL-injection Blind SQL-injection

Blind SQL-injection Double blind SQL-injection

Page 13: Sql Injection V.2

База даних

WEB-server DB

SELECT first_name, last_name FROM users WHERE user_id = '%' or ‘0’=‘0’ union select null, version() #;

Scenario

Attacker

http://example.com/app/accountView?id='%' or ‘0’=‘0’ union select null, version() #

Page 14: Sql Injection V.2

private void queryDB(String u_name){

string sql = “select * from users where name = ‘ “ + u_name + “ ’ ”;

doQuery(sql);}

1) select * from users where name = ‘Jerry’

2) select * from users where name = ‘Jerry’ or ‘1’ =‘1’

Example

Page 15: Sql Injection V.2

1) http://newspaper.com/items.php?id=2 and 1=2

SELECT title, description, body FROM items WHERE ID = 2 and 1=2

2) http://newspaper.com/items.php?id=2 and 1=1

Example Blind SQL-injection

Page 16: Sql Injection V.2

Detection

Page 17: Sql Injection V.2

Discovery of Vulnerabilities

Fields in web form

Script parameters in URL query strings

Values stored in cookies or hidden fields

Page 18: Sql Injection V.2

Fuzzing

Character sequence: ' " ) # || + >

Delay query: ' waitfor delay '0:0:10'--

SQL reserved words with white space delimiters

Page 19: Sql Injection V.2

Protection

Page 20: Sql Injection V.2

String custname = request.getParameter("customerName");String query = "SELECT account_balance FROM user_data WHERE user_name = ? ";

PreparedStatement pstmt = connection.prepareStatement( query ); pstmt.setString( 1, custname); ResultSet results = pstmt.executeQuery( );

Use of Prepared Statements (Parameterized Queries)

Page 21: Sql Injection V.2

String custname = request.getParameter("customerName"); try {

CallableStatement cs = connection.prepareCall("{call sp_getAccountBalance(?)}");

cs.setString(1, custname); ResultSet results = cs.executeQuery();

// … result set handling }

catch (SQLException se) { // … logging and error handling }

Use of Stored Procedures

Page 22: Sql Injection V.2

Escaping all User Supplied Input

OWASP Enterprise Security API

Page 23: Sql Injection V.2

A security solution on the web application level which does not depend on the application itself

Web Application Firewall

Page 24: Sql Injection V.2

Additional Defenses

Least Privilege

White List Input Validation

IDS, IPS

Page 25: Sql Injection V.2