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/msf/base/sessions/mainframe_shell.rb
Views: 11784
1
# -*- coding: binary -*-
2
3
4
module Msf::Sessions
5
6
###
7
#
8
# This class provides basic interaction with a Unix Systems Service
9
# command shell on a mainframe (IBM System Z) running Z/OS
10
# This session is initialized with a stream that will be used
11
# as the pipe for reading and writing the command shell.
12
#
13
# Date: Oct 8, 2015
14
# Author: Bigendian Smalls
15
#
16
###
17
class MainframeShell < Msf::Sessions::CommandShell
18
19
#
20
# This interface supports basic interaction.
21
#
22
include Msf::Session::Basic
23
24
#
25
# This interface supports interacting with a single command shell.
26
#
27
include Msf::Session::Provider::SingleCommandShell
28
29
##
30
#
31
# initialize as mf shell session
32
#
33
def initialize(*args)
34
self.platform = 'mainframe'
35
self.arch = ARCH_ZARCH
36
self.translate_1047 = true
37
super
38
end
39
40
##
41
#
42
# Returns the session description.
43
#
44
def desc
45
"Mainframe shell"
46
end
47
48
##
49
#
50
# override shell_read to include decode of cp1047
51
#
52
def shell_read(length=-1, timeout=1)
53
begin
54
rv = Rex::Text.from_ibm1047(rstream.get_once(length, timeout))
55
framework.events.on_session_output(self, rv) if rv
56
return rv
57
rescue ::Rex::SocketError, ::EOFError, ::IOError, ::Errno::EPIPE => e
58
shell_close
59
raise e
60
end
61
end
62
63
##
64
#
65
# override shell_write to include encode of cp1047
66
#
67
def shell_write(buf)
68
#mfimpl
69
return unless buf
70
71
begin
72
framework.events.on_session_command(self, buf.strip)
73
rstream.write(Rex::Text.to_ibm1047(buf))
74
rescue ::Rex::SocketError, ::EOFError, ::IOError, ::Errno::EPIPE => e
75
shell_close
76
raise e
77
end
78
end
79
80
def execute_file(full_path, args)
81
#mfimpl
82
raise NotImplementedError
83
end
84
85
def self.can_cleanup_files
86
false
87
end
88
89
# need to do more testing on this before we either use the default in command_shell
90
# or write a new one. For now we just make it unavailble. This prevents a hang on
91
# initial session creation. See PR#6067
92
undef_method :process_autoruns
93
94
def desc
95
"Mainframe USS session"
96
end
97
98
attr_accessor :translate_1047 # tells the session whether or not to translate
99
# ebcdic (cp1047) <-> ASCII for certain mainframe payloads
100
# this will be used in post modules to be able to switch on/off the
101
# translation on file transfers, for instance
102
103
protected
104
105
end
106
end
107
108