Class: Rex::Post::HWBridge::Extensions::Zigbee::Zigbee

Inherits:
Rex::Post::HWBridge::Extension show all
Defined in:
lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb

Overview

Zigbee extension - set of commands to be executed on zigbee compatible hw bridges

Instance Attribute Summary collapse

Attributes inherited from Rex::Post::HWBridge::Extension

#client, #name

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Zigbee

Returns a new instance of Zigbee.


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 17

def initialize(client)
  super(client, 'zigbee')

  # Alias the following things on the client object so that they
  # can be directly referenced
  client.register_extension_aliases(
    [
      {
        'name' => 'zigbee',
        'ext'  => self
      }
    ])
end

Instance Attribute Details

#target_deviceObject

Returns the value of attribute target_device


87
88
89
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 87

def target_device
  @target_device
end

Instance Method Details

#get_target_deviceString

Retrieves the default zigbee device ID

Returns:

  • (String)

    Zigbee device ID


39
40
41
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 39

def get_target_device
  self.target_device
end

#inject(dev, data) ⇒ Object

Injects a raw packet

Parameters:

  • dev (String)

    Zigbee Device ID

  • data (String)

    Raw hex data that will be Base64 encoded


59
60
61
62
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 59

def inject(dev, data)
  data = Base64.urlsafe_encode64(data)
  client.send_request("/zigbee/#{dev}/inject?data=#{data}")
end

#recv(dev) ⇒ Hash

Receives data from transceiver

Parameters:

  • dev (String)

    Zigbee Device ID

Returns:

  • (Hash)

    { data: HexString, valid_crc: X, rssi: X }


67
68
69
70
71
72
73
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 67

def recv(dev)
  data = client.send_request("/zigbee/#{dev}/recv")
  if data.size > 0
    data["data"] = Base64.urlsafe_decode64(data["data"]) if data.has_key? "data"
  end
  data
end

#set_channel(dev, channel) ⇒ Object

Sets the channel

Parameters:

  • dev (String)

    Device to affect

  • channel (Integer)

    Channel number


52
53
54
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 52

def set_channel(dev, channel)
  client.send_request("/zigbee/#{dev}/set_channel?chan=#{channel}")
end

#set_target_device(device) ⇒ Object

Sets the default target device

Parameters:

  • device (String)

    Target Zigbee device ID


33
34
35
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 33

def set_target_device(device)
  self.target_device = device
end

#sniffer_off(dev) ⇒ Object

Disables sniffer and puts the device in a state that can be changed (like adujsting channel)

Parameters:

  • dev (String)

    Zigbee Device ID


77
78
79
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 77

def sniffer_off(dev)
  client.send_request("/zigbee/#{dev}/sniffer_off")
end

#sniffer_on(dev) ⇒ Object

Enables sniffer receive mode. Not necessary to call before calling recv

Parameters:

  • dev (String)

    Zigbee Device ID


83
84
85
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 83

def sniffer_on(dev)
  client.send_request("/zigbee/#{dev}/sniffer_on")
end

#supported_devicesArray

Gets supported Zigbee Devices

Returns:

  • (Array)

    Devices


45
46
47
# File 'lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb', line 45

def supported_devices
  client.send_request("/zigbee/supported_devices")
end