CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

30
CNIT 129S: Securing Web Applications Ch 9: Attacking Data Stores

Transcript of CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Page 1: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

CNIT 129S: Securing Web Applications

Ch 9: Attacking Data Stores

Page 2: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Data Stores• Most common types are SQL, XML, and

LDAP

• High-value target for attackers

• SQL injection is the #1 vulnerability in Web apps

• Responsible for more than 90% of all stolen data

Page 3: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Injecting into Interpreted Contexts

Page 4: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Interpreted Languages

• Code is not compiled

• It's executed line-by-line

• Many core languages used in Web apps run interpreted

• SQL, LDAP, Perl, PHP

Page 5: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Code Injection

Page 6: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Compiled Languages

• Code injection vulnerabilities are more rare

• Injection has to be written in machine language

• Higher skill level required

Page 7: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Bypassing a Login• Authentication code

• Enter username of • admin'

• and any password

• Logs in as admin

Page 8: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

If Admin Username is Unknown

• Enter this username

• Query becomes

• Log in as first user in the database, typically the administrator

Page 9: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)
Page 10: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

The UNION Operator

• Combines two SELECT statements to produce a single result set

Page 11: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Single SELECT Query

Page 12: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Using UNION

Page 13: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

# for Comments• Note: some apps use different comment

characters

• Try all of these at the end of your injection

• --

• #

• /*

Page 14: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Requirements for UNION

• The two result sets must have the same structure

• Number of fields and data types

• Attacker must know the name of the table of interest and its column names

Page 15: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Wrong # of Columns

Page 16: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Different Data Types• This works because the numerical data is converted to

strings

• It would fail if the first row were numbers, and the others strings

Page 17: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Hack Steps

Page 18: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Find the Number of Columns

• NULL matches any data type

• Query will fail until the # of columns is correct

Page 19: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Using NULL

Page 20: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Find a String Column

• If query succeeds, the 'a' column is string

Page 21: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Find Database Version

Page 22: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Finding Version

Page 23: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Vulnerable SF College• I notified them in 2013; years later, they fixed it

• Link Ch 8b

Page 24: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Example: MS-SQL

Page 25: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Search Address Book for "Matthew"

Page 26: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Single Column

Page 27: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

5 Columns

Page 28: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Find String Column

Page 29: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Get Table and Column Names

Page 30: CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)

Get Credentials