Wildcard and globbing command injection bypass
A wildcard command injection bypass uses shell globbing — the `?` and `*` characters — to name a binary or file without typing its literal path. The shell expands `/bin/c?t` to `/bin/cat` and `/???/??t` to a matching path at runtime, so a filter that blocks the strings `cat` or `/bin/` never sees them in the request.
How it works
Before executing a command, the shell performs filename expansion (globbing): `?` matches any single character and `*` matches any sequence. `/bin/c?t` expands to any file in /bin matching that pattern — `/bin/cat`. `/???/??t` is a more aggressive variant that matches a three-letter directory and a binary ending in `t`.
Globbing also enables argument tricks: `/bin/cat /etc/pa*wd` matches /etc/passwd, and some utilities can be driven entirely through glob-matched option files. Because expansion happens at runtime against the real filesystem, the literal sensitive strings never appear in the attacker's input.
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.
/bin/c?t /etc/passwdLinux / Unix? matches one character so c?t expands to cat; avoids the literal 'cat'.
/???/??t /etc/passwdLinux / UnixAggressive globbing: three-char dir + two-char-plus-t binary resolves to /bin/cat on many systems.
/bin/cat /etc/pa*wdLinux / UnixWildcard in the filename matches /etc/passwd without typing it literally.
/usr/bin/w*Linux / UnixMatches binaries starting with w (e.g. whoami, w); useful to probe which tools exist.
Note: Globs that match multiple files can expand to several arguments — narrow the pattern.
When it works
- Input reaches a shell that performs filename expansion against a filesystem containing the target binary/file.
- The filter matches literal names/paths rather than the resolved command.
When it fails
- No shell is involved; globs are passed literally and don't match anything.
- The pattern matches nothing (bash leaves it literal unless failglob/nullglob is set), or matches too many files and breaks the command.
Detection
Flag glob metacharacters in command-driving inputs and compare the raw request against the resolved command line.
Signals to look for
- Inputs containing ? or * inside path-like tokens (/???/, c?t, pa*wd).
- Process command lines where the executed path differs from the request after glob expansion.
- Access to sensitive files (/etc/passwd) reached via wildcarded paths.
Where to look
Remediation
The correct fix: Use shell-free argv execution with program paths your code controls; globbing only happens in a shell, so user input can't name binaries by pattern.
Principles
- Fix the program path in code; never let user input choose the binary.
- Shell-free execution disables filename expansion of user input.
- Constrain file arguments to an allowlisted directory and canonicalise paths.
Safe APIs by runtime
execFile with a hard-coded binary path and validated file arguments.
execFile("/bin/cat", [resolveWithinBaseDir(userFile)]);subprocess.run([...], shell=False); resolve/validate paths with pathlib.
subprocess.run(["/bin/cat", str(safe_path)])Not a fix: Blocklisting binary names or '/bin/'. Globs like /???/??t and c?t resolve to the same binaries at runtime without those literal strings.
For the full secure-coding matrix across languages, see the command injection prevention guide.