Time-based blind command injection
Time-based command injection confirms execution by injecting a command that deliberately delays the response. When the application returns no output and outbound network access is blocked, a measurable time difference between a delaying payload and a control request is often the only reliable signal that your command ran.
How it works
The tester injects a command that sleeps for a known interval and measures the server's response time. If a `sleep 10` payload makes the response consistently ~10 seconds slower than a baseline request, the command executed. Repeating with different intervals (0s, 5s, 10s) rules out coincidental latency.
The delay primitive differs by platform: Linux has `sleep N`; Windows cmd.exe lacks a reliable sleep, so testers use `ping -n N 127.0.0.1` (each ping ≈ 1 second) or `timeout /t N`. Command substitution (`$(sleep 5)`) lets the delay fire inside quoted contexts.
Representative payloads
Illustrative fragments for authorized testing. The injected marker commands (id, whoami) are harmless proofs of execution — swap in your engagement’s agreed markers.
; sleep 10Linux / UnixAdds ~10 seconds of delay on Linux if executed.
& ping -n 11 127.0.0.1Windows~10s delay on Windows: 11 localhost pings at ~1s each (first is immediate).
& timeout /t 10Windowscmd.exe timeout command for a 10-second delay (needs an interactive-style console in some contexts).
$(sleep 10)Linux / UnixDelay via command substitution — fires inside double-quoted contexts where separators don't.
When it works
- The request is synchronous, so the injected sleep stalls the response you're measuring.
- A delay primitive (sleep, ping, timeout) is available on the target OS.
When it fails
- Processing is asynchronous or the sleep runs in a backgrounded/detached job, so the response returns before the delay.
- Network jitter dwarfs the chosen interval — mitigated by using larger, repeated delays.
- No shell/exec is reachable (not injectable).
Detection
Alert on requests whose latency scales with an injected interval and on sleep/ping/timeout in process command lines.
Signals to look for
- Repeated requests to one endpoint with response times clustering around 5s/10s increments.
- Process-creation events for sleep, ping (with -n/-c counts) or timeout spawned by an application.
- Parameters containing sleep, ping -n, ping -c or timeout /t.
Where to look
Remediation
The correct fix: Eliminate the shell with an argv exec API and add execution timeouts; a delaying payload then never runs.
Principles
- Shell-free execution prevents the injected sleep/ping/timeout from executing at all.
- Set hard timeouts on any subprocess so a hung or slow child can't stall requests.
- Validate inputs to an allowlist as defense in depth.
Safe APIs by runtime
subprocess.run([...], shell=False, timeout=N).
subprocess.run(["ping", "-c1", host], timeout=5)execFile with a timeout option; no shell.
execFile("ping", ["-c1", host], { timeout: 5000 });Not a fix: Trying to filter the word 'sleep'. Attackers use ping, timeout, $(...) delays or busy loops to achieve the same measurable delay.
For the full secure-coding matrix across languages, see the command injection prevention guide.