#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.
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() - t0Notice 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:
- Alternative IP representations. Socket libraries (
inet_atonand 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]/). - URL parser differentials. A validator using one parser may extract the host after
@or before#differently fromcurlor a backend HTTP library. For example,http://192.0.2.10#@127.0.0.1/orhttp://allowed.example.test@127.0.0.1/can confuse regex-based host checks. - HTTP redirects. If the validator checks
http://example.test/hook(which resolves to a public address) and passes it to an HTTP client withallow_redirects=True, a302 Foundresponse pointing tohttp://169.254.169.254/latest/meta-data/reaches the internal endpoint on the second hop. - 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.
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:
- Parse URLstrict scheme (https only) and host check
- Resolve oncegetaddrinfo() and reject private/loopback/link-local CIDRs
- Pin socketconnect directly to validated IP with original Host/SNI
- 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 and302redirects to bypass the pre-check. - Leaving IMDSv1 enabled on cloud VMs: Cloud instances should enforce IMDSv2 (session token via
PUTand 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).