================================================= 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 = "'; $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) : -------------------------------------------------------