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/rftransceiver/rftransceiver.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 RFTransceiver
10
11
###
12
# RF Transceiver extension - set of commands to be executed on transceivers like the TI cc11XX
13
###
14
15
class RFTransceiver < Extension
16
17
def initialize(client)
18
super(client, 'rftransceiver')
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' => 'rftransceiver',
26
'ext' => self
27
}
28
])
29
end
30
31
# Gets supported USB Indexes
32
# @return [Array] Indexes
33
def supported_idx
34
client.send_request("/rftransceiver/supported_idx")
35
end
36
37
# Sets the frequency
38
# @param idx [Integer] HW Index
39
# @param opt [Hash] Optional: "mhz" => 24
40
# @param freq [Integer] Frequency to set
41
def set_freq(idx, freq, opt={})
42
request = "/rftransceiver/#{idx}/set_freq?freq=#{freq}"
43
request << "&mhz=#{opt['mhz']}" if opt.has_key? 'mhz'
44
client.send_request(request)
45
end
46
47
# Retrieves a list of supported Modulations
48
# @param idx [Integer] HW Index
49
# @return [Array] of Modulation strings
50
def get_supported_modulations(idx)
51
client.send_request("/rftransceiver/#{idx}/get_modulations")
52
end
53
54
# Sets the mode
55
# @param idx [Integer] HW Index
56
# @param mode [String] Either RX, TX or IDLE
57
def set_mode(idx, mode)
58
client.send_request("/rftransceiver/#{idx}/set_mode?mode=#{mode}")
59
end
60
61
# Sets the modulation value
62
# @param idx [Integer] HW Index
63
# @param mod [String] Modulation Technique
64
def set_modulation(idx, mod)
65
client.send_request("/rftransceiver/#{idx}/set_modulation?mod=#{mod}")
66
end
67
68
# Sets fixed packet len
69
# @param idx [Integer] HW Index
70
# @param len [Integer] Length to set
71
def make_pkt_flen(idx, len)
72
client.send_request("/rftransceiver/#{idx}/make_packet_flen?len=#{len}")
73
end
74
75
# Sets variable packet len
76
# @param idx [Integer] HW Index
77
# @param len [Integer] Length to set
78
def make_pkt_vlen(idx, len)
79
client.send_request("/rftransceiver/#{idx}/make_packet_vlen?len=#{len}")
80
end
81
82
# Transmits data
83
# @param idx [Integer] HW Index
84
# @param data [String] Data to transmit
85
# @param opt [Hash] Optional parameters: "repeat" => Integer, "offset" => Integer
86
def rfxmit(idx, data, opt={})
87
data = Base64.urlsafe_encode64(data)
88
request = "/rftransceiver/#{idx}/rfxmit?data=#{data}"
89
request << "&repeat=#{opt['repeat']}" if opt.has_key? 'repeat'
90
request << "&offset=#{opt['offset']}" if opt.has_key? 'offset'
91
client.send_request(request)
92
end
93
94
# Receives a packet
95
# @param idx [Integer] HW Index
96
# @param opt [Hash] Optional parameters: "timeout" => Integer, "blocksize" => Integer
97
# @return [Hash] "data" => <received data> "timestamp" => When it was received
98
def rfrecv(idx, opt={})
99
request = "/rftransceiver/#{idx}/rfrecv"
100
if opt.size() > 0
101
first = true
102
request << '?'
103
if opt.has_key? 'timeout'
104
request << "timeout=#{opt['timeout']}"
105
first = false
106
end
107
if opt.has_key? 'blocksize'
108
request << '&' unless first
109
request << "blocksize=#{opt['blocksize']}"
110
end
111
end
112
data = client.send_request(request)
113
# Note the data is initially base64 encoded
114
if data.size() > 0
115
data['data'] = Base64.urlsafe_decode64(data['data']) if data.has_key? 'data'
116
end
117
data
118
end
119
120
def enable_packet_crc(idx)
121
client.send_request("/rftransceiver/#{idx}/enable_packet_crc")
122
end
123
124
def enable_manchester(idx)
125
client.send_request("/rftransceiver/#{idx}/enable_machester")
126
end
127
128
def set_channel(idx, channel)
129
client.send_request("/rftransceiver/#{idx}/set_channel?channel=#{channel}")
130
end
131
132
def set_channel_bandwidth(idx, bandwidth, opt={})
133
request = "/rftransceiver/#{idx}/set_channel_bandwidth?bw=#{bandwidth}"
134
request << "&mhz=#{opt['mhz']}" if opt.has_key? 'mhz'
135
client.send_request(request)
136
end
137
138
def set_channel_spc(idx, opt={})
139
request = "/rftransceiver/#{idx}/set_channel_spc"
140
if opt.size > 0
141
request << '?'
142
first = true
143
if opt.has_key? 'chanspc'
144
request << "chanspc=#{opt['chanspc']}"
145
first = false
146
end
147
if opt.has_key? 'chanspc_m'
148
request << '&' unless first
149
request << "chanspc_m=#{opt['chanspc_m']}"
150
first = false
151
end
152
if opt.has_key? 'chanspc_e'
153
request << '&' unless first
154
request << "chanspc_e=#{opt['chanspc_e']}"
155
first = false
156
end
157
if opt.has_key? 'mhz'
158
request << '&' unless first
159
request << "mhz=#{opt['mhz']}"
160
end
161
end
162
client.send_request(request)
163
end
164
165
def set_baud_rate(idx, rate, opt={})
166
request = "/rftransceiver/#{idx}/set_baud_rate?rate=#{rate}"
167
request << "&mhz=#{opt['mhz']}" if opt.has_key? 'mhz'
168
client.send_request(request)
169
end
170
171
def set_deviation(idx, deviat, opt={})
172
request = "/rftransceiver/#{idx}/set_deviation?deviat=#{deviat}"
173
request << "&mhz=#{opt['mhz']}" if opt.has_key? 'mhz'
174
client.send_request(request)
175
end
176
177
def set_sync_word(idx, word)
178
client.send_request("/rftransceiver/#{idx}/set_sync_word?word=#{word}")
179
end
180
181
def set_sync_mode(idx, mode)
182
client.send_request("/rftransceiver/#{idx}/set_sync_mode?mode=#{mode}")
183
end
184
185
def set_number_preamble(idx, num)
186
client.send_request("/rftransceiver/#{idx}/set_number_preamble?num=#{num}")
187
end
188
189
def set_lowball(idx)
190
client.send_request("/rftransceiver/#{idx}/set_lowball")
191
end
192
193
def set_maxpower(idx)
194
client.send_request("/rftransceiver/#{idx}/set_maxpower")
195
end
196
197
def set_power(idx, power)
198
client.send_request("/rftransceiver/#{idx}/set_power?power=#{power}")
199
end
200
end
201
202
end
203
end
204
end
205
end
206
end
207
208
209