Detection

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.

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

  • Content-Length header changes

  • Error messages

  • Changes in the data returned

  • Delays

  • Second-order (i.e. you inject somewhere, but another interaction is required to trigger the payload)

Test cases:

  • Test with single and double quotes

  • Test with comments or terminators to mask the rest of the query

  • Test with other special characters that can manipulate SQL statements

  • Test with boolean conditions and 1=1 and and 1=2 (closely monitor the application response, in particular the Content-Length header)

  • Test with functions that cause time delays

    • MySQL sleep(5)

    • PostgreSQL pg_sleep(5)

    • MS SQL Server WAITFOR DELAY '0:0:05'

    • Oracle dbms_pipe.receive_message(('x'),5)

  • Test with out-of-band (OOB) or out-of-band application security testing (OAST) techniques

  • Test for stacked queries

  • Test for UNION keyword

    • SELECT username,password FROM users UNION SELECT null,null

    • Test for the number of columns using null,null or ORDER BY 1 , ORDER BY 2

    • Test the data types with 'a',1 etc

  • Test with different encoding techniques

  • Test evasion techniques

    • Test with encoded payloads

    • Test with builting functions

      • E.g. CHAR()

    • Test ways to bypass commonly filtered characters

      • E.g. replacing space with /**/

Detection syntax

General

Copy

MySQL

Copy

PostgeSQL

Copy

Oracle

Copy

MSSQL

Copy

Other Payloads

Copy

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

Copy

Last updated