Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/base/sessions/tty.rb
59979 views
1
# -*- coding: binary -*-
2
3
4
module Msf
5
module Sessions
6
7
###
8
#
9
# This class provides basic interaction with a command shell on the remote
10
# endpoint. This session is initialized with a stream that will be used
11
# as the pipe for reading and writing the command shell.
12
#
13
###
14
class TTY
15
16
#
17
# This interface supports basic interaction.
18
#
19
include Msf::Session::Basic
20
21
#
22
# This interface supports interacting with a single command shell.
23
#
24
include Msf::Session::Provider::SingleCommandShell
25
26
#
27
# Returns the type of session.
28
#
29
def self.type
30
"tty"
31
end
32
33
#
34
# Returns the session description.
35
#
36
def desc
37
"Interactive TTY"
38
end
39
40
def run_cmd(cmd)
41
shell_write(cmd)
42
return rstream.get
43
end
44
#
45
# Calls the class method.
46
#
47
def type
48
self.class.type
49
end
50
51
#
52
# The shell will have been initialized by default.
53
#
54
def shell_init
55
return true
56
end
57
58
#
59
# Read from the command shell.
60
#
61
def shell_read(length = nil)
62
if length.nil?
63
rv = rstream.get
64
else
65
rv = rstream.read(length)
66
end
67
return rv
68
end
69
70
#
71
# Writes to the command shell.
72
#
73
def shell_write(buf)
74
rstream.write(buf)
75
end
76
77
#
78
# Closes the shell.
79
#
80
def shell_close()
81
rstream.close
82
end
83
84
def self.can_cleanup_files
85
true
86
end
87
88
end
89
90
end
91
end
92
93