CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/base/sessions/hwbridge.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
require 'rex/post/hwbridge'
4
5
module Msf
6
module Sessions
7
8
###
9
#
10
# This class provides an interactive session with a hardware bridge.
11
# The hardware bridge must support the current API supported by Metasploit.
12
#
13
###
14
class HWBridge < Rex::Post::HWBridge::Client
15
16
#
17
# This interface supports basic interaction.
18
#
19
include Msf::Session::Basic
20
21
#
22
# This interface supports interactive commands.
23
#
24
include Msf::Session::Interactive
25
include Msf::Sessions::Scriptable
26
27
#
28
# Initialize the HWBridge console
29
#
30
def initialize(opts={})
31
super
32
#
33
# The module will manage it's alive state
34
#
35
self.alive = true
36
37
#
38
# Initialize the hwbridge client
39
#
40
self.init_hwbridge(rstream, opts)
41
42
#
43
# Create the console instance
44
#
45
self.console = Rex::Post::HWBridge::Ui::Console.new(self)
46
end
47
48
#
49
# Returns the type of session.
50
#
51
def self.type
52
"hwbridge"
53
end
54
55
def self.can_cleanup_files
56
false
57
end
58
59
#
60
# Returns the session description.
61
#
62
def desc
63
"Hardware bridge interface"
64
end
65
66
#
67
# We could tie this into payload UUID
68
#
69
def platform
70
"hardware"
71
end
72
73
#
74
# We could tie this into payload UUID
75
#
76
def arch
77
ARCH_CMD
78
end
79
80
#
81
# Session info based on the type of hw bridge we are connected to
82
# This information comes after connecting to a bridge and pulling status info
83
#
84
def info
85
if exploit
86
if exploit.hw_specialty
87
info = ""
88
exploit.hw_specialty.each_key do |k|
89
if exploit.hw_specialty[k] == true
90
info += "," if info.length > 0
91
info += k
92
end
93
end
94
return info
95
end
96
end
97
end
98
99
##
100
# :category: Msf::Session::Interactive implementors
101
#
102
# Initializes the console's I/O handles.
103
#
104
def init_ui(input, output)
105
self.user_input = input
106
self.user_output = output
107
console.init_ui(input, output)
108
console.set_log_source(log_source)
109
110
super
111
end
112
113
##
114
# :category: Msf::Session::Interactive implementors
115
#
116
# Resets the console's I/O handles.
117
#
118
def reset_ui
119
console.unset_log_source
120
console.reset_ui
121
end
122
123
124
##
125
# :category: Msf::Session::Interactive implementors
126
#
127
# Interacts with the hwbridge client at a user interface level.
128
#
129
def _interact
130
framework.events.on_session_interact(self)
131
# Call the console interaction subsystem of the meterpreter client and
132
# pass it a block that returns whether or not we should still be
133
# interacting. This will allow the shell to abort if interaction is
134
# canceled.
135
console.interact { self.interacting != true }
136
137
# If the stop flag has been set, then that means the user exited. Raise
138
# the EOFError so we can drop this handle like a bad habit.
139
raise EOFError if (console.stopped? == true)
140
end
141
142
def alive?
143
self.alive
144
end
145
146
#
147
# Calls the class method.
148
#
149
def type
150
self.class.type
151
end
152
153
#
154
# Loads the automotive extension
155
#
156
def load_automotive
157
original = console.disable_output
158
console.disable_output = true
159
console.run_single('load automotive')
160
console.disable_output = original
161
end
162
163
#
164
# Loads the zigbee extension
165
#
166
def load_zigbee
167
original = console.disable_output
168
console.disable_output = true
169
console.run_single('load zigbee')
170
console.disable_output = original
171
end
172
173
#
174
# Loads the rftransceiver extension
175
#
176
def load_rftransceiver
177
original = console.disable_output
178
console.disable_output = true
179
console.run_single('load rftransceiver')
180
console.disable_output = original
181
end
182
183
#
184
# Load custom methods provided by the hardware
185
#
186
def load_custom_methods
187
original = console.disable_output
188
console.disable_output = true
189
console.run_single('load_custom_methods')
190
console.disable_output = original
191
end
192
193
#
194
# The shell will have been initialized by default.
195
#
196
def shell_init
197
return true
198
end
199
200
attr_accessor :console # :nodoc:
201
attr_accessor :alive # :nodoc:
202
attr_accessor :api_version
203
attr_accessor :fw_version
204
attr_accessor :hw_version
205
attr_accessor :device_name
206
private
207
attr_accessor :rstream # :nodoc:
208
209
end
210
211
end
212
end
213
214