Skip to content

Commit 095a110

Browse files
committed
Code and doc tweaks (minor).
Only one behavior change in the scan loop of zstumbler.rb to, when doing a scan across all the channels, keep it from retrying channel 11 again one last time just before it exits.
1 parent 4e9b894 commit 095a110

File tree

6 files changed

+65
-83
lines changed

6 files changed

+65
-83
lines changed

documentation/modules/post/hardware/zigbee/zstumbler.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ Actively scans the Zigbee channels by sending a beacon broadcast packet and list
44

55
**DEVICE**
66

7-
Zigbee Device ID. Defaults to the target device that is specified via the target command or if
8-
one device is presented when runnign 'supported_devices' it will use that device.
7+
ZigBee Device ID. Defaults to the target device that is specified via the target command or if
8+
one device is presented when running 'supported_devices' it will use that device.
99

1010
**CHANNEL**
1111

12-
The Channel to scan. This will prevent the stumbler from changing channels. Range is 11-25
13-
12+
The channel to scan. Setting this options will prevent the stumbler from changing channels. Range is 11-26, inclusive. Default: not set
13+
n
1414
**LOOP**
1515

16-
How many times to loop over the channels. Specifying a -1 will loop forever. The default is once.
16+
How many times to loop over the channels. Specifying a -1 will loop forever. Default: 1
1717

1818
**DELAY**
1919

20-
The delay in seconds to listen to each channel. The default is 2
20+
The delay in seconds to listen to each channel. Default: 2
2121

2222
## Scenarios
2323

24-
Scanning channel 11 for other Zigbee devices in the area.
24+
Scanning channel 11 for other ZigBee devices in the area.
2525

2626
```
2727
hwbridge > run post/hardware/zigbee/zstumbler channel=11

lib/msf/core/post/hardware/zigbee/utils.rb

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,103 +42,83 @@ module Utils
4242
DOT154_CRYPT_ENC_MIC64 = 0x06 #: Encryption, 64-bit MIC
4343
DOT154_CRYPT_ENC_MIC128 = 0x07 #: Encryption, 128-bit MIC
4444

45+
# Infer if the current session is for a ZigBee device.
46+
# @return [Boolean] true if session is for a ZigBee device, false otherwise
47+
def is_zigbee_hwbridge_session?
48+
return true if client.zigbee
49+
print_error("Not a ZigBee hwbridge session")
50+
false
51+
end
52+
53+
# Verify if a device has been specified.
54+
# @return [Boolean] true if device is specified, false otherwise
55+
def verify_device(device)
56+
return true if device
57+
print_line("No target device set, use 'target' or specify bus via the options.")
58+
false
59+
end
60+
4561
# Retrieves the target Zigbee device. This is typically set by the user via the
4662
# interactive HWBridge command line
4763
# @return [String] Zigbee device ID
4864
def get_target_device
49-
if not client.zigbee
50-
print_error("Not a Zigbee hwbridge session")
51-
return
52-
end
65+
return unless is_zigbee_hwbridge_session?
5366
return client.zigbee.get_target_device
5467
end
5568

5669
# Sets the target default Zigbee Device. This command typically isn't called via a script
5770
# Instead the user is expected to set this via the interactive HWBridge commandline
5871
# @param device [String] Zigbee device ID
5972
def set_target_device(device)
60-
if not client.zigbee
61-
print_error("Not a Zigbee hwbridge session")
62-
return
63-
end
73+
return unless is_zigbee_hwbridge_session?
6474
client.zigbee.set_target_device device
6575
end
6676

6777
# Sets the Zigbee Channel
6878
# @param device [String] Zigbee device ID
6979
# @param channel [Integer] Channel number, typically 11-25
7080
def set_channel(device, channel)
71-
if not client.zigbee
72-
print_error("Not a Zigbee hwbridge session")
73-
return {}
74-
end
75-
device = client.zigbee.target_device if not device
76-
if not device
77-
print_line("No target device set, use 'target' or specify bus via the options")
78-
return {}
79-
end
81+
return {} unless is_zigbee_hwbridge_session?
82+
device = client.zigbee.target_device unless device
83+
return {} unless verify_device(device)
8084
client.zigbee.set_channel(device, channel)
8185
end
8286

8387
# Inject raw packets. Need firmware on the zigbee device that supports transmission.
8488
# @param device [String] Zigbee device ID
8589
# @param data [String] Raw binary data sent as a string
8690
def inject(device, data)
87-
if not client.zigbee
88-
print_error("Not a Zigbee hwbridge session")
89-
return {}
90-
end
91-
device = client.zigbee.target_device if not device
92-
if not device
93-
print_line("No target device set, use 'target' or specify bus via the options")
94-
return {}
95-
end
91+
return {} unless is_zigbee_hwbridge_session?
92+
device = client.zigbee.target_device unless device
93+
return {} unless verify_device(device)
9694
client.zigbee.inject(device, data)
9795
end
9896

9997
# Recieves data from the Zigbee device
10098
# @param device [String] Zigbee device ID
10199
# @return [String] Binary blob of returned data
102100
def recv(device)
103-
if not client.zigbee
104-
print_error("Not a Zigbee hwbridge session")
105-
return {}
106-
end
107-
device = client.zigbee.target_device if not device
108-
if not device
109-
print_line("No target device set, use 'target' or specify bus via the options")
110-
return {}
111-
end
101+
return {} unless is_zigbee_hwbridge_session?
102+
device = client.zigbee.target_device unless device
103+
return {} unless verify_device(device)
112104
client.zigbee.recv(device)
113105
end
114106

115107
# Turn off Zigbee receiving
116108
# @param device [String] Zigbee device ID
117109
def sniffer_off(device)
118-
if not client.zigbee
119-
print_error("Not a Zigbee hwbridge session")
120-
return {}
121-
end
122-
device = client.zigbee.target_device if not device
123-
if not device
124-
print_line("No target device set, use 'target' or specify bus via the options")
125-
return {}
126-
end
110+
return {} unless is_zigbee_hwbridge_session?
111+
device = client.zigbee.target_device unless device
112+
return {} unless verify_device(device)
127113
client.zigbee.sniffer_off(device)
128114
end
129115

130116
# Turn on Zigbee receiving
131117
# @param device [String] Zigbee device ID
132118
def sniffer_on(device)
133-
if not client.zigbee
134-
print_error("Not a Zigbee hwbridge session")
135-
return {}
136-
end
137-
device = client.zigbee.target_device if not device
138-
if not device
139-
print_line("No target device set, use 'target' or specify bus via the options")
140-
return {}
141-
end
119+
return {} unless is_zigbee_hwbridge_session?
120+
device = client.zigbee.target_device unless device
121+
return {} unless verify_device(device)
142122
client.zigbee.sniffer_on(device)
143123
end
144124

lib/rex/post/hwbridge/ui/console/command_dispatcher/automotive.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def cmd_supported_buses
6363
def cmd_busconfig(*args)
6464
bus = ''
6565
bus_config_opts = Rex::Parser::Arguments.new(
66-
'-h' => [ false, 'Help Banner' ],
66+
'-h' => [ false, 'Help banner' ],
6767
'-b' => [ true, 'Target bus']
6868
)
6969
bus_config_opts.parse(args) do |opt, _idx, val|

lib/rex/post/hwbridge/ui/console/command_dispatcher/zigbee.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Rex
66
module Post
77
module HWBridge
88
module Ui
9+
910
###
1011
# Zigbee extension - set of commands to be executed on Zigbee compatible devices
1112
###
@@ -18,7 +19,7 @@ class Console::CommandDispatcher::Zigbee
1819
#
1920
def commands
2021
all = {
21-
'supported_devices' => 'Get supported zigbee devices',
22+
'supported_devices' => 'Get supported ZigBee devices',
2223
'target' => 'Set the target device id',
2324
'channel' => 'Set the channel'
2425
}
@@ -38,19 +39,19 @@ def set_target_device(device)
3839
#
3940
def cmd_supported_devices
4041
devices = client.zigbee.supported_devices
41-
if not devices or not devices.has_key? "devices"
42+
if !devices or !devices.has_key? "devices"
4243
print_line("error retrieving list of devices")
4344
return
4445
end
4546
devices = devices["devices"]
46-
if not devices.size > 0
47+
unless devices.size > 0
4748
print_line("none")
4849
return
4950
end
5051
set_target_device(devices[0]) if devices.size == 1
5152
str = "Supported Devices: "
52-
str += devices.join(', ')
53-
str += "\nUse device name to set your desired device, default is: #{self.target_device}"
53+
str << devices.join(', ')
54+
str << "\nUse device name to set your desired device, default is: #{self.target_device}"
5455
print_line(str)
5556
end
5657

@@ -60,7 +61,7 @@ def cmd_supported_devices
6061
def cmd_target(*args)
6162
self.target_device = ""
6263
device_opts = Rex::Parser::Arguments.new(
63-
'-h' => [ false, 'Help Banner' ],
64+
'-h' => [ false, 'Help banner' ],
6465
'-d' => [ true, 'Device ID' ]
6566
)
6667
device_opts.parse(args) do |opt, _idx, val|
@@ -83,9 +84,9 @@ def cmd_channel(*args)
8384
chan = 11
8485
dev = self.target_device if self.target_device
8586
xopts = Rex::Parser::Arguments.new(
86-
'-h' => [ false, 'Help Banner' ],
87-
'-d' => [ true, 'Zigbee Device' ],
88-
'-c' => [ true, 'channel number' ]
87+
'-h' => [ false, 'Help banner' ],
88+
'-d' => [ true, 'ZigBee device' ],
89+
'-c' => [ true, 'Channel number' ]
8990
)
9091
xopts.parse(args) do |opt, _idx, val|
9192
case opt
@@ -99,7 +100,7 @@ def cmd_channel(*args)
99100
chan = val.to_i
100101
end
101102
end
102-
if not dev
103+
if !dev
103104
print_line("You must specify or set a target device")
104105
return
105106
end

modules/post/hardware/zigbee/zstumbler.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MetasploitModule < Msf::Post
1313

1414
def initialize(info={})
1515
super( update_info( info,
16-
'Name' => 'Sends Beacons to Scan for Active Zigbee Networks',
16+
'Name' => 'Sends Beacons to Scan for Active ZigBee Networks',
1717
'Description' => %q{ Post Module to send beacon signals to the broadcast address while
1818
channel hopping},
1919
'License' => MSF_LICENSE,
@@ -22,10 +22,10 @@ def initialize(info={})
2222
'SessionTypes' => ['hwbridge']
2323
))
2424
register_options([
25-
OptInt.new('CHANNEL', [false, "Disable channel hopping by forcing a channel", nil]),
26-
OptInt.new('LOOP', [false, "How many times to loop over the channels. -1 is forever", 1]),
25+
OptInt.new('CHANNEL', [false, "Disable channel hopping by forcing a channel (11-26)", nil]),
26+
OptInt.new('LOOP', [false, "How many times to loop over the channels (-1 will run in an endless loop)", 1]),
2727
OptInt.new('DELAY', [false, "Delay in seconds to listen on each channel", 2]),
28-
OptString.new('DEVICE', [false, "Zigbee device ID, defaults to target device", nil])
28+
OptString.new('DEVICE', [false, "ZigBee device ID, defaults to target device", nil])
2929
], self.class)
3030
@seq = 0
3131
@channel = 11
@@ -55,8 +55,6 @@ def display_details(routerdata)
5555
end
5656

5757
def scan
58-
@loop_count += 1 if @channel > 26 or datastore["CHANNEL"]
59-
@channel = 11 if @channel > 26
6058
@seq = 0 if @seq > 255
6159
print_status("Scanning Channel #{@channel}")
6260
set_channel(datastore["DEVICE"], @channel)
@@ -80,14 +78,17 @@ def scan
8078
sniffer_off(datastore["DEVICE"]) # Needed to clear receive buffers
8179
@seq += 1
8280
@channel += 1 if not datastore["CHANNEL"]
81+
@loop_count += 1 if @channel > 26 or datastore["CHANNEL"]
82+
@channel = 11 if @channel > 26
8383
end
8484

8585
def run
8686
if not get_target_device and not datastore["DEVICE"]
87-
print_error "No target device set. Either set one with the 'target' command or specify the DEVICE"
87+
print_error "No target device set. Either set one with the 'target' command or specify the DEVICE."
8888
return
8989
end
9090
@channel = datastore["CHANNEL"] if datastore["CHANNEL"]
91+
@channel = 11 if @channel > 26
9192
if datastore["LOOP"] == -1
9293
while(1) do
9394
scan

tools/hardware/killerbee_msfrelay

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22
# KillerBee Metasploit relay server
33

44
import re
@@ -171,7 +171,7 @@ class MSFHandler(BaseHTTPRequestHandler):
171171

172172
class Killerbee_MSFRelay(cmd.Cmd):
173173
intro = """
174-
Killerbee Metasploit Relay
174+
KillerBee Metasploit Relay
175175
"""
176176

177177
def __init__(self, ip='0.0.0.0', port=8080):
@@ -191,7 +191,7 @@ class Killerbee_MSFRelay(cmd.Cmd):
191191
try:
192192
self._sock = HTTPServer((self._ip, self._port), MSFHandler)
193193
starttime = int(time.time())
194-
print("Killerbee MSFRelay running.")
194+
print("KillerBee MSFRelay running.")
195195
self._sock.serve_forever()
196196
except KeyboardInterrupt:
197197
self._sock.socket.close()
@@ -236,13 +236,13 @@ if __name__ == "__main__":
236236
if len(devs) > 0:
237237
dev_found = True
238238
elif not wait_msg:
239-
print("Insert Killerbee compatible Zigbee device. (You may need to add permissions)")
239+
print("Insert KillerBee compatible ZigBee device. (You may need to add permissions)")
240240
wait_msg = True
241241
except KeyboardInterrupt:
242242
sys.exit()
243243
except:
244244
if not wait_msg:
245-
print("Insert Killerbee compatible Zigbee device. (You may need to add permissions)")
245+
print("Insert KillerBee compatible ZigBee device. (You may need to add permissions)")
246246
wait_msg = True
247247

248248
beerelay = Killerbee_MSFRelay(ip, port)

0 commit comments

Comments
 (0)