The Challenge
An application exposes a command-execution endpoint. Spaces and the word echo are blocked by the WAF. The goal is to run cat /flag.txt — but the command requires both a space and the ability to echo data. The WAF also appears to block direct paths.
Approach
Two shell variable tricks substitute the blocked characters:
${IFS}— the Internal Field Separator expands to a space (or tab/newline) in bash. Completely bypasses any literal space filter.${NULL}— an unset variable expands to the empty string. Inserting it inside a blocked word likeechobreaks the string match (ech${NULL}o) without affecting execution.
The full injection: encode the real command in base64, then pipe it through:
|
|
This echoes the base64 string (spaces replaced by ${IFS}, echo split by ${NULL}), pipes it to base64 -d to decode, and pipes the result to sh for execution.
Solution
|
|
base64.b64encode("cat /flag.txt".encode()).decode() produces Y2F0IC9mbGFnLnR4dA==. The filter sees no literal echo and no literal spaces — just ${NULL}, ${IFS}, and base64 characters. Bash reassembles the command and executes it.
What I Learned
Shell injection bypasses using ${IFS} and ${NULL} are well-documented techniques. The correct fix is to never pass user input to a shell at all — use subprocess with a list argument in Python, or a language-native implementation of whatever operation is needed. Blacklisting shell syntax is an arms race you will always lose.