Skip to content

Commit 430a83b

Browse files
Merge pull request #1 from wvu-r7/pr/6067
Clean up Msf::Sessions::MainframeShell
2 parents d53be87 + bbc1e43 commit 430a83b

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

lib/msf/base/sessions/mainframe_shell.rb

Lines changed: 27 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,77 @@ 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
9793
end
9894

99-
#
10095
def desc
10196
"Mainframe USS session"
10297
end
98+
10399
attr_accessor :translate_1047 # tells the session whether or not to translate
104100
# ebcdic (cp1047) <-> ASCII for certain mainframe payloads
105101
# this will be used in post modules to be able to switch on/off the
106102
# translation on file transfers, for instance
103+
107104
protected
108105

109106
##
110107
#
111108
# _interact_ring overridden to include decoding of cp1047 data
112109
#
113110
def _interact_ring
114-
115111
begin
112+
rdr = framework.threads.spawn("RingMonitor", false) do
113+
seq = nil
116114

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

121-
# Look for any pending data from the remote ring
122-
nseq,data = ring.read_data(seq)
119+
# Update the sequence number if necessary
120+
seq = nseq || seq
123121

124-
# Update the sequence number if necessary
125-
seq = nseq || seq
122+
# Write output to the local stream if successful
123+
user_output.print(Rex::Text.from_ibm1047(data)) if data
126124

127-
# Write output to the local stream if successful
128-
user_output.print(Rex::Text.from_ibm1047(data)) if data
129-
130-
begin
131-
# Wait for new data to arrive on this session
132-
ring.wait(seq)
125+
begin
126+
# Wait for new data to arrive on this session
127+
ring.wait(seq)
133128
rescue EOFError => e
134-
#print_error("EOFError: #{e.class}: #{e}")
135-
break
129+
print_error("EOFError: #{e.class}: #{e}")
130+
break
131+
end
136132
end
137133
end
138-
end
139134

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

139+
# Write input to the ring's input mechanism
140+
shell_write(user_input.gets) if sd
141+
end
148142
ensure
149143
rdr.kill
150144
end
151145
end
152146

153147
end
154148
end
155-
end

0 commit comments

Comments
 (0)