Let’s take a look at a code fragment that is responsible for connecting language settings. Suppose the user language is stored as an HTTP cookie, and the default language is used if none exist.
$lang = 'en';
if (isset($_COOKIE['lang'])){
$lang = $_COOKIE['lang'];
}
include './languages/' . $lang . '.php';
Note: the call to ‘include’ can be replaced with ‘include_once’, ‘require’ or ‘require_once’.
Since the malicious user can control the parameters passed in cookies, he could set the value of ‘lang’ to
../../../../etc/passwd%00
When decoding the parameters, the %00 will be treated as line termination [1]. When the ‘include’ function is executed, everything after the line termination will be ignored, which will connect the following file:
./languages/../../../../etc/passwd
If the number of passes to the parent directory will be greater than the depth of the current one, the path will default to /etc/passwd, which will then be sent as the body of the HTTP request.