githubEdit

SQLi

Mostly SQL injection vulnerabilities can be found using modern scanners. However, for more complex scenarios such as second-order SQLi, manual testing can also be used.

Detection

The goal with many of these tests is to invoke some behaviour change in the application. Be sure to closely monitor for:

Test cases:

Detection syntax

General

MySQL

PostgeSQL

Oracle

MSSQL

Other Payloads

Tools:

SQLmap

The easiest way to get started with SQLmap is to either save a request to a file or copy a request as curl and change the curl command to sqlmap.

Copying a request as cURL

SQLi

Common

Polyglot

Resources by type

R/W files

Blind SQLi

Blind SQL Injection

Blind SQL injection (Blind SQLi) is a type of SQL injection attack where the attacker can exploit the database, but the application does not display the output. Instead, the attacker must "infer" data by sending payloads and observing the application's behavior or responses.

A simple example:

  • A vulnearble webapp uses an API for its search to return the number of results found.

  • A user searches for a product, and the application returns with "X products found" without displaying product details.

  • The application uses the SQL query SELECT COUNT(*) FROM products WHERE product_name LIKE '%{searchTerm}%'.

  • An attacker could exploit this by injecting SQL conditions into the {searchTerm}.

  • For exmaple, searching for laptop' AND 1=1-- - returns "1 product found" and searching for laptop' AND 1=2-- - returns "0 products found", this behavior can be an indicator of a potential Blind SQLi vulnerability.

Blind SQLi is more time-consuming than regular SQLi but is just as dangerous. It can lead to:

  • Sensitive data exposure

  • Data manipulation

  • Authentication bypass

  • Potential discovery of hidden data

Other learning resources:

Writeups:

Checklist:

Second-order SQLi

Second-order SQL Injection

Second order SQL injection (also known as Stored SQL Injection) occurs when user input is first stored in the database, and later used without being validated or encoded. The injection opportunity occurs in the second operation, hence the name "second order".

A simple example:

  • A vulnerable webapp allows users to save their usernames.

  • An attacker can provide a malicious payload as their username, e.g. jeremy'); DROP TABLE users;-- -

  • Later, when the application tries to fetch the username for an operation (e.g., greeting a returning user), it executes the malicious payload.

This type of attack can lead to:

  1. Data loss or corruption.

  2. Compromise of the database.

  3. Sensitive data exposure.

  4. Remote code execution.

Checklist:

sqlmap

Last updated