Blog | G5 Cyber Security

Blind SQLi: Column Name Guessing

TL;DR

This guide shows how to find a column name in a database using Blind SQL Injection. We’ll use boolean-based techniques and tools like sqlmap.

Understanding Blind SQLi

Blind SQL Injection happens when the web application doesn’t show error messages or data directly, but you can still infer information by observing its behaviour (e.g., whether a page loads differently). We’ll focus on boolean-based injection where we ask ‘yes/no’ questions.

Step 1: Identify a Vulnerable Parameter

  1. Find an input field: Look for search boxes, login forms, or any place you can enter data.
  2. Test for Injection: Try basic SQL injection payloads like ' OR '1'='1 and see if the response changes significantly. If it does, you likely have a vulnerability. Be careful not to break the application!

Step 2: Determine the Database Management System (DBMS)

Knowing your DBMS helps tailor payloads. You can try common functions or error messages:

If you get a different response, it suggests the DBMS is present.

Step 3: Guessing Column Names

  1. Initial Setup: Assume the table name is known (or find it first using similar techniques). Let’s say the table is called ‘users’.
  2. Boolean-Based Payloads: We’ll test each column name one by one. Start with common names like ‘id’, ‘username’, ‘password’, ’email’.
  3. Crafting the Payload: The basic structure will be something like this (example for MySQL): ' AND IF(SUBSTRING((SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'users' LIMIT 1, 0), 1, 1) = 'i', 1, 0)
  4. Explanation:

Step 4: Automating with sqlmap

sqlmap can automate this process:

sqlmap -u "http://example.com/vulnerable_page?param=value" --dbs users --columns -p param

sqlmap will try different column names and report those that are found.

Step 5: Refining the Guess

  1. Iterate: If sqlmap doesn’t find all columns, manually refine your payloads. Increase the length of the substring you extract (e.g., SUBSTRING(..., 1, 2)).
  2. Character by Character: If you know a column exists but not its full name, guess character by character using boolean-based injection and payloads like this (MySQL): ' AND IF(SUBSTRING((SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'users' LIMIT 1, 0), 1, 1) = 'a', 1, 0) Change ‘a’ to each letter of the alphabet.

Important Considerations

Exit mobile version