SQL injection (SQLi)
Last updated
Last updated
SQL injection is a code injection technique, used to attack data-driven applications, in which malicious SQL statements are inserted into an entry field for execution (e.g. to dump the database contents to the attacker).
--
See
Create a list of input fields
First test '
or ;
Comments --
/* */
#
Enter different type, e.g. string instead of int
Monitor responses (Error may be hidden in JS or HTML)
Generic Error (e.g. just 500) -> blind SQL injection
Most basic 1' or '1' = '1
Evade braces and further conditions 1' or '1' = '1'))/*
App logic may expect exactly one result 1' or '1' = '1')) LIMIT 1/*
http://www.example.com/product.php?id=10 AND 1=2
Error or blank page -> vulnerable
http://www.example.com/product.php?id=10; INSERT INTO users (…)
MySql:
Oracle:
MS SQL Server:
PostgreSQL:
information_schema
The information_schema
table contains tables
and columns
from the database. Their respective names are table_name
and column_name
inside each table.
Retrieve all the table names:
Retrieve all the colum names inside from a table.
Determine number of columns Increase order by number until an error occurs.
Determine data types of columns Use null as placeholder for yet undetermined columns
Ensure more than one result is shown
Useful for blind SQL injections
Iterate one char at a time
TODO
TODO
TODO
TODO
https://github.com/fuzzdb-project/fuzzdb/tree/master/attack/sql-injection
https://github.com/dtrip/mysqloit
Url formats
GET <host>/index.php?id=1337
POST <host>/index.php --data="id=1337"
Commands
Grab banner?
Use request (e.g. from burp)
Crawl / enumerate
Dump / extract data
OS shell / get a remote shell
Test sqlninja
Set up listener
Execute sqlninja
config files
GET
POST
Whitespaces
Null bytes (%00)
Inline comments
URL encoding
Char encoding
String concatenation
Hex encoding
Declare variables
Alternative expression of 'or 1=1'
sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers.
Authorization: Basic <hash>