Skip to content

Commit 43eae0b

Browse files
committed
Clean up Msf::Sessions::MainframeShell
1 parent d53be87 commit 43eae0b

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

lib/msf/base/sessions/mainframe_shell.rb

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: binary -*-
2+
23
require 'msf/base/sessions/command_shell'
34

4-
module Msf
5-
module Sessions
5+
module Msf::Sessions
66

77
###
88
#
@@ -15,7 +15,7 @@ module Sessions
1515
# Author: Bigendian Smalls
1616
#
1717
###
18-
class Msf::Sessions::MainframeShell < Msf::Sessions::CommandShell
18+
class MainframeShell < Msf::Sessions::CommandShell
1919

2020
#
2121
# This interface supports basic interaction.
@@ -61,7 +61,6 @@ def shell_read(length=-1, timeout=1)
6161
framework.events.on_session_output(self, rv) if rv
6262
return rv
6363
rescue ::Rex::SocketError, ::EOFError, ::IOError, ::Errno::EPIPE => e
64-
#print_error("Socket error: #{e.class}: #{e}")
6564
shell_close
6665
raise e
6766
end
@@ -73,83 +72,78 @@ def shell_read(length=-1, timeout=1)
7372
#
7473
def shell_write(buf)
7574
#mfimpl
76-
return if not buf
75+
return unless buf
7776

7877
begin
7978
framework.events.on_session_command(self, buf.strip)
8079
rstream.write(Rex::Text.to_ibm1047(buf))
8180
rescue ::Rex::SocketError, ::EOFError, ::IOError, ::Errno::EPIPE => e
82-
#print_error("Socket error: #{e.class}: #{e}")
8381
shell_close
8482
raise e
8583
end
8684
end
8785

88-
#
8986
def execute_file(full_path, args)
9087
#mfimpl
9188
raise NotImplementedError
9289
end
9390

94-
#
9591
def process_autoruns(datastore)
9692
# mf not implemented yet
93+
raise NotImplementedError
9794
end
9895

99-
#
10096
def desc
10197
"Mainframe USS session"
10298
end
99+
103100
attr_accessor :translate_1047 # tells the session whether or not to translate
104101
# ebcdic (cp1047) <-> ASCII for certain mainframe payloads
105102
# this will be used in post modules to be able to switch on/off the
106103
# translation on file transfers, for instance
104+
107105
protected
108106

109107
##
110108
#
111109
# _interact_ring overridden to include decoding of cp1047 data
112110
#
113111
def _interact_ring
114-
115112
begin
113+
rdr = framework.threads.spawn("RingMonitor", false) do
114+
seq = nil
116115

117-
rdr = framework.threads.spawn("RingMonitor", false) do
118-
seq = nil
119-
while self.interacting
120-
121-
# Look for any pending data from the remote ring
122-
nseq,data = ring.read_data(seq)
116+
while self.interacting
117+
# Look for any pending data from the remote ring
118+
nseq,data = ring.read_data(seq)
123119

124-
# Update the sequence number if necessary
125-
seq = nseq || seq
120+
# Update the sequence number if necessary
121+
seq = nseq || seq
126122

127-
# Write output to the local stream if successful
128-
user_output.print(Rex::Text.from_ibm1047(data)) if data
123+
# Write output to the local stream if successful
124+
user_output.print(Rex::Text.from_ibm1047(data)) if data
129125

130-
begin
131-
# Wait for new data to arrive on this session
132-
ring.wait(seq)
126+
begin
127+
# Wait for new data to arrive on this session
128+
ring.wait(seq)
133129
rescue EOFError => e
134-
#print_error("EOFError: #{e.class}: #{e}")
135-
break
130+
print_error("EOFError: #{e.class}: #{e}")
131+
break
132+
end
136133
end
137134
end
138-
end
139-
140-
while self.interacting
141-
# Look for any pending input or errors from the local stream
142-
sd = Rex::ThreadSafe.select([ _local_fd ], nil, [_local_fd], 5.0)
143135

144-
# Write input to the ring's input mechanism
145-
shell_write(user_input.gets) if sd
146-
end
136+
while self.interacting
137+
# Look for any pending input or errors from the local stream
138+
sd = Rex::ThreadSafe.select([ _local_fd ], nil, [_local_fd], 5.0)
147139

140+
# Write input to the ring's input mechanism
141+
shell_write(user_input.gets) if sd
142+
end
148143
ensure
149144
rdr.kill
150145
end
151146
end
152147

153148
end
154149
end
155-
end

0 commit comments

Comments
 (0)