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/rex/post/hwbridge/ui/console/interactive_channel.rb
Views: 1904
1
# -*- coding: binary -*-
2
module Rex
3
module Post
4
module HWBridge
5
module Ui
6
7
###
8
#
9
# Mixin that is meant to extend the base channel class from hwbridge in a
10
# manner that adds interactive capabilities.
11
#
12
###
13
module Console::InteractiveChannel
14
15
include Rex::Ui::Interactive
16
17
#
18
# Interacts with self.
19
#
20
def _interact
21
# If the channel has a left-side socket, then we can interact with it.
22
if (self.lsock)
23
self.interactive(true)
24
25
interact_stream(self)
26
27
self.interactive(false)
28
else
29
print_error("Channel #{self.cid} does not support interaction.")
30
31
self.interacting = false
32
end
33
end
34
35
#
36
# Called when an interrupt is sent.
37
#
38
def _interrupt
39
prompt_yesno("Terminate channel #{self.cid}?")
40
end
41
42
#
43
# Suspends interaction with the channel.
44
#
45
def _suspend
46
# Ask the user if they would like to background the session
47
if (prompt_yesno("Background channel #{self.cid}?") == true)
48
self.interactive(false)
49
50
self.interacting = false
51
end
52
end
53
54
#
55
# Closes the channel like it aint no thang.
56
#
57
def _interact_complete
58
begin
59
self.interactive(false)
60
61
self.close
62
rescue IOError
63
end
64
end
65
66
#
67
# Reads data from local input and writes it remotely.
68
#
69
def _stream_read_local_write_remote(channel)
70
data = user_input.gets
71
return if not data
72
73
self.on_command_proc.call(data.strip) if self.on_command_proc
74
self.write(data)
75
end
76
77
#
78
# Reads from the channel and writes locally.
79
#
80
def _stream_read_remote_write_local(channel)
81
data = self.lsock.sysread(16384)
82
83
self.on_print_proc.call(data.strip) if self.on_print_proc
84
self.on_log_proc.call(data.strip) if self.on_log_proc
85
user_output.print(data)
86
end
87
88
#
89
# Returns the remote file descriptor to select on
90
#
91
def _remote_fd(stream)
92
self.lsock
93
end
94
95
attr_accessor :on_log_proc
96
97
end
98
99
end
100
end
101
end
102
end
103
104