Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/hardware/zigbee/zstumbler.rb
Views: 11784
##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{14Post Module to send beacon signals to the broadcast address while15channel hopping16},17'License' => MSF_LICENSE,18'Author' => ['Craig Smith'],19'Platform' => ['hardware'],20'SessionTypes' => ['hwbridge']21)22)23register_options([24OptInt.new('CHANNEL', [false, 'Disable channel hopping by forcing a channel (11-26)', nil]),25OptInt.new('LOOP', [false, 'How many times to loop over the channels (-1 will run in an endless loop)', 1]),26OptInt.new('DELAY', [false, 'Delay in seconds to listen on each channel', 2]),27OptString.new('DEVICE', [false, 'ZigBee device ID, defaults to target device', nil])28])29@seq = 030@channel = 1131@stumbled = {}32@loop_count = 033end3435def display_details(routerdata)36stackprofile_map = {370 => 'Network Specific',381 => 'ZigBee Standard',392 => 'ZigBee Enterprise'40}41stackver_map = {420 => 'ZigBee Prototype',431 => 'ZigBee 2004',442 => 'ZigBee 2006/2007'45}46spanid, source, extpanid, stackprofilever, channel = routerdata47stackprofilever = stackprofilever.unpack('H*')[0].hex48stackprofile = stackprofilever & 0x0f49stackver = (stackprofilever & 0xf0) >> 450profile = 'Unknown'51profile = stackprofile_map[stackprofile] if stackprofile_map.key? stackprofile52ver = 'Unknown'53ver = stackver_map[stackver] if stackver_map.key? stackver54print_status("New Network: PANID: 0x#{spanid.upcase} SOURCE: 0x#{source.upcase}")55print_status(" Ext PANID: #{extpanid.upcase.scan(/../).join(':')} Stack Profile: #{profile}")56print_status(" Stack Version: #{ver}")57print_status(" Channel: #{@channel}")58end5960def scan61@seq = 0 if @seq > 25562print_status("Scanning Channel #{@channel}")63set_channel(datastore['DEVICE'], @channel)64beacon = "\x03\x08#{@seq.chr}\xff\xff\xff\xff\x07"65inject(datastore['DEVICE'], beacon)66delay = Time.now + datastore['DELAY']67while delay > Time.now68pkt = recv(datastore['DEVICE'])69next unless pkt && !pkt.empty? && pkt['valid_crc']7071pktdecode = dot154_packet_decode(pkt['data'])72next unless (pktdecode['FSF'] & DOT154_FCF_TYPE_MASK) == DOT154_FCF_TYPE_BEACON7374key = "#{pktdecode['SPAN_ID']}#{pktdecode['SOURCE']}"75value = [pktdecode['SPAN_ID'], pktdecode['SOURCE'], pktdecode['EXT_PAN_ID'], pktdecode['STACK_PROFILE'], @channel]76if !@stumbled.key? key77@stumbled[key] = value78display_details(value)79end80end81sniffer_off(datastore['DEVICE']) # Needed to clear receive buffers82@seq += 183@channel += 1 if !datastore['CHANNEL']84@loop_count += 1 if (@channel > 26) || datastore['CHANNEL']85@channel = 11 if @channel > 2686end8788def run89if !get_target_device && !datastore['DEVICE']90print_error "No target device set. Either set one with the 'target' command or specify the DEVICE."91return92end93@channel = datastore['CHANNEL'] if datastore['CHANNEL']94@channel = 11 if @channel > 2695if datastore['LOOP'] == -196loop { scan }97else98scan while (@loop_count < datastore['LOOP'])99end100end101end102103104