CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb
Views: 11705
1
#
2
# -*- coding: binary -*-
3
require 'rex/post/hwbridge/client'
4
5
module Rex
6
module Post
7
module HWBridge
8
module Extensions
9
module Zigbee
10
11
###
12
# Zigbee extension - set of commands to be executed on zigbee compatible hw bridges
13
###
14
15
class Zigbee < Extension
16
17
def initialize(client)
18
super(client, 'zigbee')
19
20
# Alias the following things on the client object so that they
21
# can be directly referenced
22
client.register_extension_aliases(
23
[
24
{
25
'name' => 'zigbee',
26
'ext' => self
27
}
28
])
29
end
30
31
# Sets the default target device
32
# @param device [String] Target Zigbee device ID
33
def set_target_device(device)
34
self.target_device = device
35
end
36
37
# Retrieves the default zigbee device ID
38
# @return [String] Zigbee device ID
39
def get_target_device
40
self.target_device
41
end
42
43
# Gets supported Zigbee Devices
44
# @return [Array] Devices
45
def supported_devices
46
client.send_request("/zigbee/supported_devices")
47
end
48
49
# Sets the channel
50
# @param dev [String] Device to affect
51
# @param channel [Integer] Channel number
52
def set_channel(dev, channel)
53
client.send_request("/zigbee/#{dev}/set_channel?chan=#{channel}")
54
end
55
56
# Injects a raw packet
57
# @param dev [String] Zigbee Device ID
58
# @param data [String] Raw hex data that will be Base64 encoded
59
def inject(dev, data)
60
data = Base64.urlsafe_encode64(data)
61
client.send_request("/zigbee/#{dev}/inject?data=#{data}")
62
end
63
64
# Receives data from transceiver
65
# @param dev [String] Zigbee Device ID
66
# @return [Hash] { data: HexString, valid_crc: X, rssi: X }
67
def recv(dev)
68
data = client.send_request("/zigbee/#{dev}/recv")
69
if data.size > 0
70
data["data"] = Base64.urlsafe_decode64(data["data"]) if data.has_key? "data"
71
end
72
data
73
end
74
75
# Disables sniffer and puts the device in a state that can be changed (like adujsting channel)
76
# @param dev [String] Zigbee Device ID
77
def sniffer_off(dev)
78
client.send_request("/zigbee/#{dev}/sniffer_off")
79
end
80
81
# Enables sniffer receive mode. Not necessary to call before calling recv
82
# @param dev [String] Zigbee Device ID
83
def sniffer_on(dev)
84
client.send_request("/zigbee/#{dev}/sniffer_on")
85
end
86
87
attr_accessor :target_device
88
89
end
90
91
end
92
end
93
end
94
end
95
end
96
97