Brace expansion is a mechanism by which arbitrary strings may be generated. Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript. The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right. For instance:
Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed as follows:
$(command)
`command`
Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command.
There are several ways to work with encoded strings:
$'string' words:
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.
echo provides -e option to interpret of backslash escapes. Note the recognized sequences depend on a version of echo, as well as the -e option may not be present at all.
If you have parameter injection in a cli command that has been passed sensitive parameters, such as tokens or passwords, you can try to leak the passed secret with ps x -w.
# you can inject arbitrary parameters to <injection here> part
$ command --user username --token SECRET_TOKEN <injection here>
# send the vulnerable command to background with &
# and catch the parameters with ps x -w
$ command --user username --token SECRET_TOKEN & ps x -w
PID TTY STAT TIME COMMAND
1337 ? S 0:00 /usr/bin/command --user username --token SECRET_TOKEN
1574 ? R 0:00 ps x -w
This can be useful if the cli logs hide sensitive settings or sensitive data is not stored in the environment.
This can be useful if the cli logs hide sensitive data or sensitive data is not stored in the environment (for instance, Github Actions provide variable interpolation ${{...}} for injecting secrets, and you can't give access to secrets during execution). Another case is when you have blind injection and can redirect output of ps x -w to a file that you have access to.
List of commands
Combine the execution of multiple commands using the operators ;, &, &&, or ||, and optionally terminated by one of ;, &, or .
The basic form of parameter expansion is ${parameter}; the value of parameter is substituted:
$ a="es"; echo "t${a}t"
More complex forms of parameter expansions allow you to perform various operations. For instance, you can extract substrings and use them to create payloads:
Bash automatically assigns default values to a number of variables, such as HOME or PATH. Some of these variables can be used to create payloads. For instance, you can use IFS variable as a separator (this is possible since IFS contains a list of characters that separate fields):
$ cat$IFS/etc/passwd
$ echo${IFS}"test"
Moreover, you can override IFS and use any character as a separator:
# using single quotes in command names
$ w'h'o'am'i
# using double quotes in command names
$ w"h"o"am"i
# using backslashes and slahes in command names
$ w\ho\am\i
$ /\b\i\n/////s\h