|
| 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 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit4 < Msf::Auxiliary |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::Tcp |
| 13 | + include Msf::Auxiliary::Report |
| 14 | + include Msf::Auxiliary::Scanner |
| 15 | + |
| 16 | + def initialize |
| 17 | + super( |
| 18 | + 'Name' => 'SAPRouter Admin Request', |
| 19 | + 'Description' => %q{ |
| 20 | + Display the remote connection table from a SAPRouter. |
| 21 | + }, |
| 22 | + 'References' => [ |
| 23 | + [ 'URL', 'http://labs.mwrinfosecurity.com/tools/2012/04/27/sap-metasploit-modules/' ], |
| 24 | + [ 'URL', 'http://help.sap.com/saphelp_nw70ehp3/helpdata/en/48/6c68b01d5a350ce10000000a42189d/content.htm'], |
| 25 | + [ 'URL', 'http://www.onapsis.com/research-free-solutions.php' ] # Bizsploit Opensource ERP Pentesting Framework |
| 26 | + ], |
| 27 | + 'Author' => [ |
| 28 | + 'nomnkee', |
| 29 | + 'Mariano Nunez', # Wrote Bizploit, helped on this module, very cool guy |
| 30 | + 'Chris John Riley', # Testing |
| 31 | + 'Ian de Villiers', # Testing |
| 32 | + 'Joris van de Vis' # Testing |
| 33 | + ], |
| 34 | + 'License' => BSD_LICENSE |
| 35 | + ) |
| 36 | + register_options( |
| 37 | + [ |
| 38 | + Opt::RPORT(3299) |
| 39 | + ], self.class) |
| 40 | + end |
| 41 | + |
| 42 | + def get_data(size, packet_len) |
| 43 | + info = '' |
| 44 | + 1.upto(size) do |i| |
| 45 | + data = sock.recv(1) |
| 46 | + packet_len -= 1 |
| 47 | + if data == "\x00" |
| 48 | + sock.recv(size - i) |
| 49 | + packet_len -= size - i |
| 50 | + return info, packet_len |
| 51 | + break |
| 52 | + else |
| 53 | + info << data |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + def run_host(ip) |
| 59 | + host_port = "#{ip}:#{datastore['RPORT']}" |
| 60 | + type = 'ROUTER_ADM' |
| 61 | + version = 0x26 |
| 62 | + cmd = 0x2 |
| 63 | + count = 0 |
| 64 | + connected = 'false' |
| 65 | + port = datastore['RPORT'] |
| 66 | + source = '' |
| 67 | + destination = '' |
| 68 | + service = '' |
| 69 | + ni_packet = type + [0,version,cmd,0,0].pack("c*") |
| 70 | + ni_packet = [ni_packet.length].pack('N') << ni_packet |
| 71 | + saptbl = Msf::Ui::Console::Table.new( |
| 72 | + Msf::Ui::Console::Table::Style::Default, |
| 73 | + 'Header' => "[SAP] SAProuter Connection Table for #{ip}", |
| 74 | + 'Prefix' => "\n", |
| 75 | + 'Postfix' => "\n", |
| 76 | + 'Indent' => 1, |
| 77 | + 'Columns' => |
| 78 | + [ |
| 79 | + "Source", |
| 80 | + "Destination", |
| 81 | + "Service" |
| 82 | + ]) |
| 83 | + begin |
| 84 | + connect |
| 85 | + rescue ::Rex::ConnectionRefused |
| 86 | + print_status("#{host_port} - Connection refused") |
| 87 | + connected = false |
| 88 | + rescue ::Rex::ConnectionError, ::IOError, ::Timeout::Error |
| 89 | + print_status("#{host_port} - Connection timeout") |
| 90 | + connected = false |
| 91 | + rescue ::Exception => e |
| 92 | + print_error("#{host_port} - Exception #{e.class} #{e} #{e.backtrace}") |
| 93 | + connected = false |
| 94 | + end |
| 95 | + if connected != false |
| 96 | + print_good("#{host_port} - Connected to saprouter") |
| 97 | + print_good("#{host_port} - Sending ROUTER_ADM packet info request") |
| 98 | + sock.put(ni_packet) |
| 99 | + packet_len = sock.read(4).unpack('H*')[0].to_i 16 |
| 100 | + print_good("#{host_port} - Got INFO response") |
| 101 | + while packet_len !=0 |
| 102 | + count += 1 |
| 103 | + case count |
| 104 | + when 1 |
| 105 | + if packet_len > 150 |
| 106 | + sock.recv(150) |
| 107 | + packet_len -= 150 |
| 108 | + source, packet_len = get_data(46,packet_len) |
| 109 | + destination, packet_len = get_data(46,packet_len) |
| 110 | + service, packet_len = get_data(30,packet_len) |
| 111 | + sock.recv(2) |
| 112 | + packet_len -= 2 |
| 113 | + saptbl << [source, destination, service] |
| 114 | + while packet_len > 0 |
| 115 | + sock.recv(13) |
| 116 | + packet_len -= 13 |
| 117 | + source, packet_len = get_data(46,packet_len) |
| 118 | + destination, packet_len = get_data(46,packet_len) |
| 119 | + service, packet_len = get_data(30,packet_len) |
| 120 | + term = sock.recv(2) |
| 121 | + packet_len -= 2 |
| 122 | + saptbl << [source, destination, service] |
| 123 | + end |
| 124 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 125 | + else |
| 126 | + print_error("#{host_port} - No connected clients") |
| 127 | + sock.recv(packet_len) |
| 128 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 129 | + end |
| 130 | + when 2 |
| 131 | + data = sock.recv(packet_len) |
| 132 | + packet_len -= packet_len |
| 133 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 134 | + when 3 |
| 135 | + clients = sock.recv(packet_len) |
| 136 | + packet_len -= packet_len |
| 137 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 138 | + when 4 |
| 139 | + pwd = sock.recv(packet_len) |
| 140 | + print_good(pwd) |
| 141 | + packet_len -= packet_len |
| 142 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 143 | + when 5 |
| 144 | + routtab = sock.recv(packet_len) |
| 145 | + print_good(routtab) |
| 146 | + packet_len -= packet_len |
| 147 | + packet_len = sock.recv(4).unpack('H*')[0].to_i 16 |
| 148 | + end |
| 149 | + if packet_len == 0 |
| 150 | + break |
| 151 | + end |
| 152 | + end |
| 153 | + disconnect |
| 154 | + # TODO: This data should be saved somewhere. A note on the host would be nice. |
| 155 | + print(saptbl.to_s) |
| 156 | + end |
| 157 | + end |
| 158 | +end |
0 commit comments