Quote and concatenation command injection bypass
A command injection quote bypass defeats filters that blocklist whole command names. The shell strips empty quotes and line-continuation backslashes before execution, so `w'h'oami`, `wh""oami` and `wh\oami` all resolve to `whoami` at runtime while reading as something else to a naive string filter.
How it works
Shell word evaluation removes quoting syntax that doesn't enclose anything meaningful. A pair of empty single or double quotes inside a word (`w'h'oami`) is removed during quote processing, leaving the bare token `whoami`. A backslash before an ordinary character is also dropped. The command therefore executes normally, but a filter searching for the literal string `whoami` never sees it.
The same idea extends to concatenating a command from variables or substrings, and to inserting quotes into option strings. It targets filters that match on exact keywords rather than on the parsed, post-expansion command.
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.
w'h'oamiLinux / UnixEmpty single-quote pair inside the word is removed by the shell, yielding whoami.
wh""oamiLinux / UnixEmpty double-quote pair is stripped at runtime; defeats a 'whoami' keyword filter.
wh\oamiLinux / UnixBackslash before an ordinary char is dropped by the shell, reconstructing whoami.
/bin/cat /etc/pa''sswdLinux / UnixBreaks up a sensitive filename with an empty quote pair to bypass filename blocklists.
When it works
- The filter matches literal command/keyword strings rather than the parsed command.
- Input reaches a shell that performs quote removal and backslash processing.
When it fails
- No shell is involved; the quotes/backslashes remain literal and the program name doesn't resolve.
- An allowlist accepts only known-good values, so arbitrary tokens are rejected regardless of quoting.
Detection
Normalise inputs (strip empty quote pairs and backslashes) before matching, and flag command names that only resolve after quote removal.
Signals to look for
- Inputs with intra-word quotes or backslashes around would-be command names (w'h'oami, c"a"t).
- Process command lines where the executed binary differs from the raw request string once quotes are removed.
- Repeated near-miss requests probing a keyword filter with varied quoting.
Where to look
Remediation
The correct fix: Execute via an argv array with no shell; quote removal is a shell behaviour that never happens, so the tokens stay literal and harmless.
Principles
- Don't try to match dangerous keywords — attackers rewrite them with quotes, backslashes and concatenation.
- Shell-free execution removes the quote-processing step entirely.
- Allowlist values with a known shape instead of blocklisting command names.
Safe APIs by runtime
execFile/spawn with args array; the binary name is fixed by you, not the user.
execFile("/usr/bin/whoami", []);subprocess.run([...], shell=False) with a fixed program path.
subprocess.run(["/usr/bin/id"])Not a fix: Blocklisting command names like 'cat', 'whoami', 'nc'. Empty quotes, backslashes and variable concatenation reconstruct any name the shell will still execute.
For the full secure-coding matrix across languages, see the command injection prevention guide.