Summery
$IFS stands for Internal Field Separator. It’s a Bash variable that defines which characters the shell uses to split unquoted text into separate words. By default, it contains space and a tab.
From the pentesting perspective, it can help to bypass simplistic space filters (which only check for a space or a tab) in command injection and other shell-injection scenarios.
$IFS can be used in a number of ways:
$IFS- When the variables boundaries are clearly defined${IFS}- When the variables boundaries are not cleanly defined. The braces explicitly mark the end of the variable name. This is usually the “go to” syntax for most scenerios.IFS=' '- For when you want$IFSto act stictkly as a space without any other effects, you can then for example call it inside bash scripts.
For example, this script takes the string cat /etc/passwd and splits it into two variables, then executes the command using those variables.
IFS=' ' # Set IFS to space
input="cat /etc/passwd"
read -r cmd arg <<< "$input"
$cmd $arg
Line by line:
IFS=' '- Sets the field separator to a space.input="cat /etc/passwd"- Stores the command as a string.read -r cmd arg <<< "$input"- Reads the string and splits it at whitespace:cmd=cat,arg=/etc/passwd.$cmd $arg- Expands tocat /etc/passwdand executes it, printing the contents of the file.
There are also many other methods we can utilize to bypass space filters. For example, we can use the Bash Brace Expansion feature, which automatically adds spaces between arguments wrapped between braces - {ls,-la}.