Skip to main content
Blind/Time-Based SQLi & Filter-Bypass SSRF
Lesson 13 of 18

Blind/Time-Based SQLi & Filter-Bypass SSRF

Detect and verify boolean and time-based blind SQL injection without visible query output, understand how naive SSRF URL filters fail against IP encodings, redirects, and DNS rebinding, and implement durable server-side defences.

Advanced 34 min Web security
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Distinguish boolean-based, time-based, and out-of-band blind SQL injection signals
  • Explain how binary search reduces requests during boolean-based blind SQL injection verification
  • Identify why string blocklists and naive URL checks fail against alternative IP encodings, parser mismatches, redirects, and DNS rebinding
  • Implement SSRF egress controls that bind connections to validated IP addresses and block private or link-local ranges

Recommended first: SQL Injection FundamentalsSSRF Fundamentals & Local/Remote File Inclusion

#Why this matters

Modern web applications rarely print raw database stack traces or echo the body of an arbitrary internal HTTP fetch. Developers suppress SQL error messages, return uniform 200 OK or 202 Accepted pages, and add URL filters to stop requests to 127.0.0.1 or cloud metadata services.

Those controls stop basic probes, yet the underlying flaws often remain reachable. With blind SQL injection (SQLi), an attacker trades direct output for side-channel differences in page content or response timing. With filter-bypass Server-Side Request Forgery (SSRF), an attacker exploits differences between how a validator inspects a URL and how the underlying resolver and HTTP client actually connect to it.

#Boolean-based and time-based blind SQLi

When an application hides query output and error text, you look for oracles - observable differences caused by a condition inside the SQL statement.

Blind SQLi style Observable oracle Typical SQL primitive Main limitation
Boolean-based Response length, status code, or marker text AND 1=1 vs AND 1=2 Requires two distinct response states
Time-based Elapsed response duration CASE WHEN (...) THEN SLEEP(3) ELSE 0 END Sensitive to network jitter and server load
Out-of-band (OOB) External DNS or HTTP callback DB network functions (when enabled) Often blocked by egress firewalls

In boolean-based blind SQLi, testing every printable ASCII character sequentially takes up to 95 requests per character. Binary search cuts that to at most 7 requests per character by testing ASCII(SUBSTRING(...)) > mid and halving the range [32, 126] on each response.

Time-based blind SQLi is the fallback when even true and false queries produce identical HTTP responses, such as an analytics tracker or a password-reset endpoint. Because WAN latency varies, reliable lab verification establishes a baseline median latency first and triggers a modest sleep (2 to 3 seconds) only on the matching branch.

python
import time
import requests

TARGET = "http://lab.local/api/check"
BASELINE_TRUE = "1' AND 1=1-- "
BASELINE_FALSE = "1' AND 1=2-- "

def probe_boolean(session, payload):
    r = session.get(TARGET, params={"id": payload}, timeout=5)
    return len(r.text), r.status_code

def probe_timing(session, condition_sql, delay=2):
    payload = f"1' AND (SELECT CASE WHEN ({condition_sql}) THEN SLEEP({delay}) ELSE 0 END)-- "
    t0 = time.monotonic()
    session.get(TARGET, params={"id": payload}, timeout=10)
    return time.monotonic() - t0

Notice the defensive implication: suppressing verbose database errors never fixes SQL injection. If user input alters query syntax, side channels still expose data.

#Filter-bypass SSRF mechanics

A common but fragile SSRF defence parses the incoming URL string and rejects hostnames like localhost, 127.0.0.1, or 169.254.169.254. Attackers bypass naive URL filters through four mechanisms:

  1. Alternative IP representations. Socket libraries (inet_aton and URL resolvers) accept forms that string comparisons miss: decimal (2130706433), hex (0x7f000001), octal (0177.0.0.1), shorthand (127.1), and IPv6-mapped IPv4 (http://[::ffff:127.0.0.1]/).
  2. URL parser differentials. A validator using one parser may extract the host after @ or before # differently from curl or a backend HTTP library. For example, http://192.0.2.10#@127.0.0.1/ or http://allowed.example.test@127.0.0.1/ can confuse regex-based host checks.
  3. HTTP redirects. If the validator checks http://example.test/hook (which resolves to a public address) and passes it to an HTTP client with allow_redirects=True, a 302 Found response pointing to http://169.254.169.254/latest/meta-data/ reaches the internal endpoint on the second hop.
  4. DNS rebinding (TOCTOU). Even if the validator resolves the hostname to an IP before calling the HTTP client, a second resolution inside the client creates a time-of-check to time-of-use race.
DNS rebinding TOCTOU between validator and HTTP clientDNS rebinding TOCTOU between validator and HTTP clientAppValidatorDNSHttpClientLoopbackLookup rebind.example.test198.51.100.25 (TTL 0, public IP)Validator allows URL because 198.51.100.25 is publicLookup rebind.example.test127.0.0.1 (internal IP)GET /admin (bypassed filter)

When the application fetches the URL asynchronously and never returns the response body, testers detect blind SSRF using an out-of-band callback domain (such as a Burp Collaborator subdomain or a local listener on 192.0.2.1). An incoming DNS lookup or HTTP request proves the server made the outbound connection, and the User-Agent header often reveals the backend library.

#Defending and common mistakes

To eliminate blind SQLi completely, use parameterized queries for every value, validate fixed identifiers such as ORDER BY column names against a strict allow-list, enforce least-privilege database roles, and configure query execution timeouts alongside rate limiting on anomalous endpoints.

To stop filter-bypass SSRF, combine application validation with network isolation:

  1. Parse URLstrict scheme (https only) and host check
  2. Resolve oncegetaddrinfo() and reject private/loopback/link-local CIDRs
  3. Pin socketconnect directly to validated IP with original Host/SNI
  4. Disable redirectsor re-run full validation on every Location hop

Common mistakes observed in production reviews:

  • Relying on WAF rules or error suppression for SQLi: Both leave boolean and time-based side channels intact.
  • Using regex or blocklists on hostnames for SSRF: Fails against hex/octal/decimal IPs, IPv6-mapped IPv4, and CNAME records pointing to internal addresses.
  • Validating before calling requests.get(url): Allows DNS rebinding and 302 redirects to bypass the pre-check.
  • Leaving IMDSv1 enabled on cloud VMs: Cloud instances should enforce IMDSv2 (session token via PUT and hop limit 1) and restrict outbound proxy egress at the firewall.

#Summary

  • Blind SQL injection extracts data via response-state differences (boolean) or conditional delays (time-based) even when errors and query output are suppressed.
  • Binary search reduces boolean-based character extraction to at most 7 probes per ASCII character, while time-based probes require baseline latency calibration.
  • Naive SSRF blocklists fail against alternative IP encodings, URL parser differentials, HTTP redirects, and DNS rebinding TOCTOU races.
  • Durable defence pairs parameterized queries (for SQLi) with single-resolution IP validation, pinned connections, disabled redirects, and egress firewalling (for SSRF).

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge