|
| 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 Nuñez (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. I'd also like to thank Chris John Riley, |
| 15 | +# Ian de Villiers and Joris van de Vis who have Beta tested the modules and |
| 16 | +# provided excellent feedback. Some people just seem to enjoy hacking SAP :) |
| 17 | +## |
| 18 | + |
| 19 | +require 'msf/core' |
| 20 | + |
| 21 | +class Metasploit4 < Msf::Auxiliary |
| 22 | + |
| 23 | + include Msf::Auxiliary::Report |
| 24 | + include Msf::Auxiliary::Scanner |
| 25 | + include Msf::Exploit::Remote::Tcp |
| 26 | + |
| 27 | + def initialize |
| 28 | + super( |
| 29 | + 'Name' => 'SAPRouter Admin Request', |
| 30 | + 'Version' => '$Revision$', |
| 31 | + 'Description' => %q{ |
| 32 | + SAPRouter Admin Request (display remote route information). |
| 33 | + http://help.sap.com/saphelp_nw70ehp3/helpdata/en/48/6c68b01d5a350ce10000000a42189d/content.htm |
| 34 | + }, |
| 35 | + 'References' => [[ 'URL', 'http://labs.mwrinfosecurity.com' ]], |
| 36 | + 'Author' => [ 'nmonkee' ], |
| 37 | + 'License' => BSD_LICENSE |
| 38 | + ) |
| 39 | + register_options( |
| 40 | + [ |
| 41 | + Opt::RPORT(3299) |
| 42 | + ], self.class) |
| 43 | + end |
| 44 | + |
| 45 | + def get_data(size, packet_len) |
| 46 | + info = '' |
| 47 | + for i in 1..size |
| 48 | + data = sock.recv(1) |
| 49 | + packet_len -= 1 |
| 50 | + if data == "\x00" |
| 51 | + sock.recv(size - i) |
| 52 | + packet_len -= size - i |
| 53 | + return info, packet_len |
| 54 | + break |
| 55 | + elsif |
| 56 | + info << data |
| 57 | + end |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + def run_host(ip) |
| 62 | + type = 'ROUTER_ADM' |
| 63 | + version = 0x26 |
| 64 | + cmd = 0x2 |
| 65 | + count = 0 |
| 66 | + connected = 'false' |
| 67 | + port = datastore['RPORT'] |
| 68 | + source = '' |
| 69 | + destination = '' |
| 70 | + service = '' |
| 71 | + ni_packet = type + [0,version,cmd,0,0].pack("c*") |
| 72 | + ni_packet = [ni_packet.length].pack('N') << ni_packet |
| 73 | + saptbl = Msf::Ui::Console::Table.new( |
| 74 | + Msf::Ui::Console::Table::Style::Default, |
| 75 | + 'Header' => "[SAP] SAProuter Connection Table for #{ip}", |
| 76 | + 'Prefix' => "\n", |
| 77 | + 'Postfix' => "\n", |
| 78 | + 'Indent' => 1, |
| 79 | + 'Columns' => |
| 80 | + [ |
| 81 | + "Source", |
| 82 | + "Destination", |
| 83 | + "Service" |
| 84 | + ]) |
| 85 | + begin |
| 86 | + connect |
| 87 | + rescue ::Rex::ConnectionRefused |
| 88 | + print_status("#{ip}:#{datastore['RPORT']} - connection refused") |
| 89 | + connected == 'false' |
| 90 | + rescue ::Rex::ConnectionError, ::IOError, ::Timeout::Error |
| 91 | + print_status("#{ip}:#{datastore['RPORT']} - connection timeout") |
| 92 | + connected == 'false' |
| 93 | + rescue ::Exception => e |
| 94 | + print_error("#{ip}:#{datastore['RPORT']} - exception #{e.class} #{e} #{e.backtrace}") |
| 95 | + connected == 'false' |
| 96 | + end |
| 97 | + if connected != 'false' |
| 98 | + print_good("connected to saprouter") |
| 99 | + print_good("sending ROUTER_ADM packet info request") |
| 100 | + sock.put(ni_packet) |
| 101 | + packet_len = sock.read(4).unpack('H*')[0].to_i 16 |
| 102 | + print_good("got INFO response") |
| 103 | + while packet_len !=0 |
| 104 | + count += 1 |
| 105 | + case count |
| 106 | + when 1 |
| 107 | + if packet_len > 150 |
| 108 | + sock.recv(150) |
| 109 | + packet_len -= 150 |
| 110 | + source, packet_len = get_data(46,packet_len) |
| 111 | + destination, packet_len = get_data(46,packet_len) |
| 112 | + service, packet_len = get_data(30,packet_len) |
| 113 | + sock.recv(2) |
| 114 | + packet_len -= 2 |
| 115 | + saptbl << [source, destination, service] |
| 116 | + while packet_len !=0 |
| 117 | + sock.recv(13) |
| 118 | + packet_len -= 13 |
| 119 | + source, packet_len = get_data(46,packet_len) |
| 120 | + destination, packet_len = get_data(46,packet_len) |
| 121 | + service, packet_len = get_data(30,packet_len) |
| 122 | + term = sock.recv(2) |
| 123 | + packet_len -= 2 |
| 124 | + saptbl << [source, destination, service] |
| 125 | + end |
| 126 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 127 | + else |
| 128 | + print_error("no connected clients :'(") |
| 129 | + sock.recv(packet_len) |
| 130 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 131 | + end |
| 132 | + when 2 |
| 133 | + data = sock.recv(packet_len) |
| 134 | + packet_len -= packet_len |
| 135 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 136 | + when 3 |
| 137 | + clients = sock.recv(packet_len) |
| 138 | + packet_len -= packet_len |
| 139 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 140 | + when 4 |
| 141 | + pwd = sock.recv(packet_len) |
| 142 | + print_good(pwd) |
| 143 | + packet_len -= packet_len |
| 144 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 145 | + when 5 |
| 146 | + routtab = sock.recv(packet_len) |
| 147 | + print_good(routtab) |
| 148 | + packet_len -= packet_len |
| 149 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 150 | + end |
| 151 | + if packet_len == 0 |
| 152 | + break |
| 153 | + end |
| 154 | + end |
| 155 | + disconnect |
| 156 | + print(saptbl.to_s) |
| 157 | + end |
| 158 | + end |
| 159 | +end |
0 commit comments