Blind SQL Injection
Overview
SQL is a standardized language for interacting with relational databases.
Top 5 Databases (Dec 2022)
1
Oracle
2
MySQL
3
Microsoft SQL Server
4
PostgreSQL
5
IBM Db2
Note: This module focuses on Blind SQL Injection using MSSQL. Techniques can be adapted to other databases since SQL is standardized.
Interacting with MSSQL
SQLCMD (Windows, Command Line)
Microsoft's command-line tool for MSSQL.
Connection Syntax
sqlcmd -S 'SQL01' -U 'thomas' -P 'TopSecretPassword23!' -d bsqlintro -W-S
Server name
-U
Username
-P
Password
-d
Database
-W
Remove trailing spaces
Running Queries
Note: Type
GOto execute the query batch.
Example Output
JOIN Query Example
Impacket-MSSQLClient (Linux, Command Line)
Part of Impacket toolset, preinstalled on many security distros.
Connection Syntax
Running Queries
Pentesting Features
Enable xp_cmdshell:
SQL Server Management Studio (Windows, GUI)
Microsoft's GUI tool for MSSQL administration.
Workflow
Connect - Enter server name, authentication, credentials
Browse - Open
Databasesβ[database]βTablesQuery - Right-click database β
New QueryExecute - Click
Executebutton
Common Enumeration Queries
List Tables
List Columns
Example Column Output
Users table:
Posts table:
Complex Query Example
Requirements
Find password hash where:
First name begins with 'S'
Email > 20 characters
Wrote post with title starting with 'N'
Sorted by first name ascending
Query
Quick Reference
Connection Commands
SQLCMD
Windows
sqlcmd -S <server> -U <user> -P <pass> -d <db>
Impacket
Linux
impacket-mssqlclient <user>:'<pass>'@<server> -db <db>
SSMS
Windows
GUI connection dialog
Useful SQL Syntax
Top N rows
SELECT TOP N ...
String starts with
LIKE 'X%'
String length
LEN(column)
Join tables
JOIN table ON condition
Order results
ORDER BY column ASC/DESC
References
Last updated