Environmental Variables
Command execution is affected by environmental variables.
They are not present in the command line executed, just exist in the current context.
In other words: commands process environmental variables.
Controlling environmental variables may provide control over a program.
Examples
The PATH variable contains a list of folders, which are searched when a command is issued.
If PATH=“/bin;/sbin;/usr/bin;/usr/sbin”, system(“ls”) will lead to bash searching for ls in those folders.
If an attacker controls PATH it may make an application call a different binary.
CVE-2014-6271 - Shellshock
Summary: Bash executes code present after the declaration of a function placed on an environmental variable
Will result in executing echo “Bad code”.
Issues seems to be innocuous as an attacker that calls env could call other command directly.
But... Some servers create env variables based on user content.
CGI: Common Gateway Interface.
Simple way of executing scripts that interact with clients through a web server
Operation:
Server receives a request.
Server creates environmental variables with the request content.
URL parameters
REQUEST body
ALL HTTP HEADERS!
Server executes the script.
If script uses bash at any point (e.g. Perl script that uses system), environmental variables may be executed.
Server returns the output to the client as the HTTP Response Body.
There are ways of returning headers also.
The User-Agent HTTP Header is converted into a ENV Variable.
Bash will execute the echo command with the content of the /etc/passwd file.
Output will be sent to clients as the response body.
Last updated