githubEdit

SQLi

SQLi Methodology

SQL Injection Cheat Sheet

Complete SQL injection payloads for authorized penetration testing across all major database systems.


MySQL/MariaDB

1. Error-Based Tests

' OR 1=1-- -
' AND 1=2 UNION SELECT NULL-- -

2. Sort Columns (Find Maximum Column Count)

' ORDER BY 1-- -
' ORDER BY 2-- -
' ORDER BY 3-- -

Continue incrementing until error occurs

Alternative: UNION Method

' UNION SELECT NULL-- -
' UNION SELECT NULL,NULL-- -
' UNION SELECT NULL,NULL,NULL-- -

3. Find Version

4. Find Database Name

5. Find Current User

6. Find Databases

7. Find Tables from Database

8. Find Columns from Table

9. Dump Data


PostgreSQL

1. Error-Based Tests

2. Sort Columns (Find Maximum Column Count)

Continue incrementing until error occurs

3. Find Version

4. Find Database Name

5. Find Current User

6. Find Databases

7. Find Tables from Database

8. Find Columns from Table

9. Dump Data


Microsoft SQL Server (MSSQL)

1. Error-Based Tests

2. Sort Columns (Find Maximum Column Count)

Continue incrementing until error occurs

3. Find Version

4. Find Database Name

5. Find Current User

6. Find Databases

7. Find Tables from Database

8. Find Columns from Table

9. Dump Data


Oracle

1. Error-Based Tests

2. Sort Columns (Find Maximum Column Count)

Continue incrementing until error occurs

Note: Oracle requires FROM dual or valid table

3. Find Version

4. Find Database Name

Note: Oracle uses SID instead of traditional database names

5. Find Current User

6. Find Databases/Schemas

7. Find Tables from Schema

8. Find Columns from Table

9. Dump Data


SQLite

1. Error-Based Tests

2. Sort Columns (Find Maximum Column Count)

Continue incrementing until error occurs

3. Find Version

4. Find Database Name

N/A - SQLite uses file-based databases (single database per file)

5. Find Current User

N/A - SQLite has no user authentication concept

6. Find Databases

N/A - SQLite uses single database model

7. Find Tables

8. Find Columns from Table

9. Dump Data


Quick Reference Guide

Comment Styles by Database

Database
Comment Syntax

MySQL

-- -, #, /* */

PostgreSQL

--, /* */

MSSQL

--, /* */

Oracle

--, /* */

SQLite

--, /* */

String Concatenation by Database

Database
Concatenation Operator

MySQL

CONCAT() or `

PostgreSQL

`

MSSQL

+

Oracle

`

SQLite

`


Important Notes

⚠️ Authorization Required: These payloads are for authorized penetration testing only in controlled environments like OSCP labs.

πŸ” NULL Matching: When using UNION attacks, you must match the exact number of columns in the original query. Use NULL placeholders and replace them one at a time to extract data.

πŸ“ Testing Workflow:

  1. Test for SQL injection vulnerability

  2. Determine number of columns

  3. Identify database type and version

  4. Enumerate database structure

  5. Extract sensitive data

🎯 OSCP Tips:

  • Always document your findings

  • Try multiple injection points (GET, POST, cookies, headers)

  • Consider time-based and boolean-based blind injections if UNION doesn't work

  • Use SQLmap when manual exploitation is time-consuming


Last Updated: November 2025 For authorized security testing only

1) Confirmation of a potential SQLi

Alternatively, you can use BurpSuite Intruder with SQLi wordlists as well.

2) Find the number of columns in the table

MySQL

Repeat this input until you get a response from the server

PostgreSQL

Automated

3) Find DB Version

MySQL

MSSQL

PostgreSQL

4) Find Databases

MySQL

PostgreSQL

5) Find tables names (DB=Users)

SQLite

6) Find the columns name of a table (Table=User)

SQLite

7) Dump data (group_concat(username,” | β€œ,password))

SQLite

8) Create wordlists for credential stuffing attacks

Another thing to check in an SQLi is RCE capabilities (file write or OS command execution)

1) File write

2) Execute payload on webserver

Various triggers for SQLi

1) Single Quote

2) Double Quote

Blind SQLi

Determine database name

Determine table name

Determine column name

Extract column content

Login Bypass

Standard OR-based bypass

Bypass with LIMIT (useful when multiple entries might be returned)

Bypass by using string comparison (a common trick when numeric bypass fails)

Using AND to combine conditions and exploit certain scenarios

More obfuscated example (avoiding use of typical 1=1):

Bypass with string comparison (works for both MySQL and MSSQL)

OR-based bypass with a numeric comparison

Bypass with LIMIT for MySQL (restricts to 1 entry)

MSSQL version of limiting output with TOP

SQL Truncation

Truncation-based SQL injection occurs when the database limits user input based on a specified length, discarding any characters beyond that limit. This can be exploited by an attacker to manipulate user data. For example, an attacker can create a new user with a name like 'admin' and their own password, potentially causing multiple entries for the same username. If both entries are evaluated as 'admin', the attacker could gain unauthorized access to the legitimate admin account.

In the following example, the database truncates the username after a certain length (e.g., 10 characters). The attacker uses this to create a conflicting account:

Stored Procedures

1) Open SQL Server Management Studio, connect to the database, then go to:

Right-click on Stored Procedures, then:

Add the name of the Stored Procedure (without the dbo. part), then press OK.

2) Find interesting stored procedures and press:

3) If you find anything interesting, open Visual Studio and load the entire solution of the web app.

4) Try to find where the Stored Procedure is called within the code.

5) Check which function is located, check variables, and where it is called by clicking on:

6) Try to reproduce the vulnerability.

Blind SQL Injection Payloads

1) Manual Exploitation

10-second delay boolean test

Guess the name of the table schema (Instead of 'users', it can be literally ANYTHING, so you may need an educated guess on how to find it.)

Guess the column names of the table schema (Same principle, just guesswork!)

Guess a column name with the LIKE (%) operator. (Do this letter by letter to brute force it until you get a positive response from the SQL server)

Guess how many columns there are in the table

Verify the name of the user from the table in the database

Update the user's password

Confirm update

2) Python Code Snippets

Enumerate the number of databases

Dump database names

Automated

1) SQLmap

Capture request with Burp Suite by right-clicking on the request, then save as a file. Then you can use the request file with SQLmap to proceed with the SQL injection.

Dump database name

Dump database

SQLmap can also crack any hashes it detects after it finishes the database dump.

Last updated