Ticket #684 (closed Bug: fixed)
Local File Inclusion Vulnerability
| Reported by: | Spoofed Existence | Owned by: | Shadowhand |
|---|---|---|---|
| Priority: | critical | Milestone: | |
| Component: | Core | Version: | SVN HEAD |
| Keywords: | Cc: |
Description
All Kohana versions I have investigated so far are vulnerable to a local file inclusion vulnerability in the default configuration. While ".." segments of an URI are removed properly, after removing this the segments are trim'ed. So, ".. " (two periods, followed by a space) is not stripped but later converted into "..". Since any number of directories are allowed to be specified, any file with the extension php could be included remotely.
To see this happen, create a file "/tmp/test.php" with PHP code "<?php die('test');". Then, request the following page (or leave out index.php if it's automatically used by rewriteurl): http://thehost/index.php/%20../%20../%20../%20../%20../%20../%20../%20../%20../tmp/test Possibly more " ../" segments will be needed. But finally the page will die with the message 'test'.
After the code is executed and the script continues, it looks for the controller class. When it's not found, it will display a 404 file not found. So usually you won't be able to see the output of the page, unless an error occurs or the page terminates the script.
This will have serious consequences if the user is able to write to a .php file. While this is not possible in the default configuration, it can very well be later. For instance, if an application writes user input to the logs, the user can write php code if it is not stripped by the item logging it. Then, a malicious user could include this file and execute his own PHP. The log items in the standard installation seem to be stripped properly. Also, this may pose security risks on shared hosts, where the PHP files are executed as different users. One user could write a file and include it from another user's script, possibly having read- or write-permissions where he shouldn't.
A workaround is to disallow a period in the segments. That is, remove the period from "$config_allowed?".
Spoofed Existence
