Path: blob/master/modules/post/hardware/zigbee/zstumbler.rb
19851 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Hardware::Zigbee::Utils78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Sends Beacons to Scan for Active ZigBee Networks',13'Description' => %q{14Send beacon signals to the broadcast address while channel hopping.15},16'License' => MSF_LICENSE,17'Author' => ['Craig Smith'],18'Platform' => ['hardware'],19'SessionTypes' => ['hwbridge'],20'Notes' => {21'Stability' => [CRASH_SAFE],22'SideEffects' => [],23'Reliability' => []24}25)26)27register_options([28OptInt.new('CHANNEL', [false, 'Disable channel hopping by forcing a channel (11-26)', nil]),29OptInt.new('LOOP', [false, 'How many times to loop over the channels (-1 will run in an endless loop)', 1]),30OptInt.new('DELAY', [false, 'Delay in seconds to listen on each channel', 2]),31OptString.new('DEVICE', [false, 'ZigBee device ID, defaults to target device', nil])32])33@seq = 034@channel = 1135@stumbled = {}36@loop_count = 037end3839def display_details(routerdata)40stackprofile_map = {410 => 'Network Specific',421 => 'ZigBee Standard',432 => 'ZigBee Enterprise'44}45stackver_map = {460 => 'ZigBee Prototype',471 => 'ZigBee 2004',482 => 'ZigBee 2006/2007'49}50spanid, source, extpanid, stackprofilever, _channel = routerdata51stackprofilever = stackprofilever.unpack('H*')[0].hex52stackprofile = stackprofilever & 0x0f53stackver = (stackprofilever & 0xf0) >> 454profile = 'Unknown'55profile = stackprofile_map[stackprofile] if stackprofile_map.key? stackprofile56ver = 'Unknown'57ver = stackver_map[stackver] if stackver_map.key? stackver58print_status("New Network: PANID: 0x#{spanid.upcase} SOURCE: 0x#{source.upcase}")59print_status(" Ext PANID: #{extpanid.upcase.scan(/../).join(':')} Stack Profile: #{profile}")60print_status(" Stack Version: #{ver}")61print_status(" Channel: #{@channel}")62end6364def scan65@seq = 0 if @seq > 25566print_status("Scanning Channel #{@channel}")67set_channel(datastore['DEVICE'], @channel)68beacon = "\x03\x08#{@seq.chr}\xff\xff\xff\xff\x07"69inject(datastore['DEVICE'], beacon)70delay = Time.now + datastore['DELAY']71while delay > Time.now72pkt = recv(datastore['DEVICE'])73next unless pkt && !pkt.empty? && pkt['valid_crc']7475pktdecode = dot154_packet_decode(pkt['data'])76next unless (pktdecode['FSF'] & DOT154_FCF_TYPE_MASK) == DOT154_FCF_TYPE_BEACON7778key = "#{pktdecode['SPAN_ID']}#{pktdecode['SOURCE']}"79value = [pktdecode['SPAN_ID'], pktdecode['SOURCE'], pktdecode['EXT_PAN_ID'], pktdecode['STACK_PROFILE'], @channel]80if !@stumbled.key? key81@stumbled[key] = value82display_details(value)83end84end85sniffer_off(datastore['DEVICE']) # Needed to clear receive buffers86@seq += 187@channel += 1 if !datastore['CHANNEL']88@loop_count += 1 if (@channel > 26) || datastore['CHANNEL']89@channel = 11 if @channel > 2690end9192def run93if !get_target_device && !datastore['DEVICE']94print_error "No target device set. Either set one with the 'target' command or specify the DEVICE."95return96end97@channel = datastore['CHANNEL'] if datastore['CHANNEL']98@channel = 11 if @channel > 2699if datastore['LOOP'] == -1100loop { scan }101else102scan while (@loop_count < datastore['LOOP'])103end104end105end106107108