1
1
# -*- coding: binary -*-
2
+
2
3
require 'msf/base/sessions/command_shell'
3
4
4
- module Msf
5
- module Sessions
5
+ module Msf ::Sessions
6
6
7
7
###
8
8
#
@@ -15,7 +15,7 @@ module Sessions
15
15
# Author: Bigendian Smalls
16
16
#
17
17
###
18
- class Msf :: Sessions :: MainframeShell < Msf ::Sessions ::CommandShell
18
+ class MainframeShell < Msf ::Sessions ::CommandShell
19
19
20
20
#
21
21
# This interface supports basic interaction.
@@ -61,7 +61,6 @@ def shell_read(length=-1, timeout=1)
61
61
framework . events . on_session_output ( self , rv ) if rv
62
62
return rv
63
63
rescue ::Rex ::SocketError , ::EOFError , ::IOError , ::Errno ::EPIPE => e
64
- #print_error("Socket error: #{e.class}: #{e}")
65
64
shell_close
66
65
raise e
67
66
end
@@ -73,83 +72,77 @@ def shell_read(length=-1, timeout=1)
73
72
#
74
73
def shell_write ( buf )
75
74
#mfimpl
76
- return if not buf
75
+ return unless buf
77
76
78
77
begin
79
78
framework . events . on_session_command ( self , buf . strip )
80
79
rstream . write ( Rex ::Text . to_ibm1047 ( buf ) )
81
80
rescue ::Rex ::SocketError , ::EOFError , ::IOError , ::Errno ::EPIPE => e
82
- #print_error("Socket error: #{e.class}: #{e}")
83
81
shell_close
84
82
raise e
85
83
end
86
84
end
87
85
88
- #
89
86
def execute_file ( full_path , args )
90
87
#mfimpl
91
88
raise NotImplementedError
92
89
end
93
90
94
- #
95
91
def process_autoruns ( datastore )
96
92
# mf not implemented yet
97
93
end
98
94
99
- #
100
95
def desc
101
96
"Mainframe USS session"
102
97
end
98
+
103
99
attr_accessor :translate_1047 # tells the session whether or not to translate
104
100
# ebcdic (cp1047) <-> ASCII for certain mainframe payloads
105
101
# this will be used in post modules to be able to switch on/off the
106
102
# translation on file transfers, for instance
103
+
107
104
protected
108
105
109
106
##
110
107
#
111
108
# _interact_ring overridden to include decoding of cp1047 data
112
109
#
113
110
def _interact_ring
114
-
115
111
begin
112
+ rdr = framework . threads . spawn ( "RingMonitor" , false ) do
113
+ seq = nil
116
114
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 )
120
118
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
123
121
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
126
124
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 )
133
128
rescue EOFError => e
134
- #print_error("EOFError: #{e.class}: #{e}")
135
- break
129
+ print_error ( "EOFError: #{ e . class } : #{ e } " )
130
+ break
131
+ end
136
132
end
137
133
end
138
- end
139
134
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 )
147
138
139
+ # Write input to the ring's input mechanism
140
+ shell_write ( user_input . gets ) if sd
141
+ end
148
142
ensure
149
143
rdr . kill
150
144
end
151
145
end
152
146
153
147
end
154
148
end
155
- end
0 commit comments