From 43eae0b97f96f073270e8b79899c6cf88abd55fa Mon Sep 17 00:00:00 2001 From: William Vu Date: Mon, 26 Oct 2015 12:15:45 -0500 Subject: [PATCH 1/2] Clean up Msf::Sessions::MainframeShell --- lib/msf/base/sessions/mainframe_shell.rb | 62 +++++++++++------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/lib/msf/base/sessions/mainframe_shell.rb b/lib/msf/base/sessions/mainframe_shell.rb index ae28962198..ed1eca5865 100644 --- a/lib/msf/base/sessions/mainframe_shell.rb +++ b/lib/msf/base/sessions/mainframe_shell.rb @@ -1,8 +1,8 @@ # -*- coding: binary -*- + require 'msf/base/sessions/command_shell' -module Msf -module Sessions +module Msf::Sessions ### # @@ -15,7 +15,7 @@ module Sessions # Author: Bigendian Smalls # ### -class Msf::Sessions::MainframeShell < Msf::Sessions::CommandShell +class MainframeShell < Msf::Sessions::CommandShell # # This interface supports basic interaction. @@ -61,7 +61,6 @@ class Msf::Sessions::MainframeShell < Msf::Sessions::CommandShell framework.events.on_session_output(self, rv) if rv return rv rescue ::Rex::SocketError, ::EOFError, ::IOError, ::Errno::EPIPE => e - #print_error("Socket error: #{e.class}: #{e}") shell_close raise e end @@ -73,37 +72,36 @@ class Msf::Sessions::MainframeShell < Msf::Sessions::CommandShell # def shell_write(buf) #mfimpl - return if not buf + return unless buf begin framework.events.on_session_command(self, buf.strip) rstream.write(Rex::Text.to_ibm1047(buf)) rescue ::Rex::SocketError, ::EOFError, ::IOError, ::Errno::EPIPE => e - #print_error("Socket error: #{e.class}: #{e}") shell_close raise e end end - # def execute_file(full_path, args) #mfimpl raise NotImplementedError end - # def process_autoruns(datastore) # mf not implemented yet + raise NotImplementedError end - # def desc "Mainframe USS session" end + attr_accessor :translate_1047 # tells the session whether or not to translate # ebcdic (cp1047) <-> ASCII for certain mainframe payloads # this will be used in post modules to be able to switch on/off the # translation on file transfers, for instance + protected ## @@ -111,40 +109,37 @@ class Msf::Sessions::MainframeShell < Msf::Sessions::CommandShell # _interact_ring overridden to include decoding of cp1047 data # def _interact_ring - begin + rdr = framework.threads.spawn("RingMonitor", false) do + seq = nil - rdr = framework.threads.spawn("RingMonitor", false) do - seq = nil - while self.interacting + while self.interacting + # Look for any pending data from the remote ring + nseq,data = ring.read_data(seq) - # Look for any pending data from the remote ring - nseq,data = ring.read_data(seq) + # Update the sequence number if necessary + seq = nseq || seq - # Update the sequence number if necessary - seq = nseq || seq + # Write output to the local stream if successful + user_output.print(Rex::Text.from_ibm1047(data)) if data - # Write output to the local stream if successful - user_output.print(Rex::Text.from_ibm1047(data)) if data - - begin - # Wait for new data to arrive on this session - ring.wait(seq) + begin + # Wait for new data to arrive on this session + ring.wait(seq) rescue EOFError => e - #print_error("EOFError: #{e.class}: #{e}") - break + print_error("EOFError: #{e.class}: #{e}") + break + end end end - end - while self.interacting - # Look for any pending input or errors from the local stream - sd = Rex::ThreadSafe.select([ _local_fd ], nil, [_local_fd], 5.0) - - # Write input to the ring's input mechanism - shell_write(user_input.gets) if sd - end + while self.interacting + # Look for any pending input or errors from the local stream + sd = Rex::ThreadSafe.select([ _local_fd ], nil, [_local_fd], 5.0) + # Write input to the ring's input mechanism + shell_write(user_input.gets) if sd + end ensure rdr.kill end @@ -152,4 +147,3 @@ class Msf::Sessions::MainframeShell < Msf::Sessions::CommandShell end end -end From bbc1e43149989a5016c8fa780f27a78b9aae6c29 Mon Sep 17 00:00:00 2001 From: William Vu Date: Mon, 26 Oct 2015 14:45:21 -0500 Subject: [PATCH 2/2] Remove raise, since it broke things Need to pass through silently. --- lib/msf/base/sessions/mainframe_shell.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/msf/base/sessions/mainframe_shell.rb b/lib/msf/base/sessions/mainframe_shell.rb index ed1eca5865..87eb488d0d 100644 --- a/lib/msf/base/sessions/mainframe_shell.rb +++ b/lib/msf/base/sessions/mainframe_shell.rb @@ -90,7 +90,6 @@ class MainframeShell < Msf::Sessions::CommandShell def process_autoruns(datastore) # mf not implemented yet - raise NotImplementedError end def desc