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,78 @@ 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
93
+ raise NotImplementedError
97
94
end
98
95
99
- #
100
96
def desc
101
97
"Mainframe USS session"
102
98
end
99
+
103
100
attr_accessor :translate_1047 # tells the session whether or not to translate
104
101
# ebcdic (cp1047) <-> ASCII for certain mainframe payloads
105
102
# this will be used in post modules to be able to switch on/off the
106
103
# translation on file transfers, for instance
104
+
107
105
protected
108
106
109
107
##
110
108
#
111
109
# _interact_ring overridden to include decoding of cp1047 data
112
110
#
113
111
def _interact_ring
114
-
115
112
begin
113
+ rdr = framework . threads . spawn ( "RingMonitor" , false ) do
114
+ seq = nil
116
115
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 )
123
119
124
- # Update the sequence number if necessary
125
- seq = nseq || seq
120
+ # Update the sequence number if necessary
121
+ seq = nseq || seq
126
122
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
129
125
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 )
133
129
rescue EOFError => e
134
- #print_error("EOFError: #{e.class}: #{e}")
135
- break
130
+ print_error ( "EOFError: #{ e . class } : #{ e } " )
131
+ break
132
+ end
136
133
end
137
134
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 )
143
135
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 )
147
139
140
+ # Write input to the ring's input mechanism
141
+ shell_write ( user_input . gets ) if sd
142
+ end
148
143
ensure
149
144
rdr . kill
150
145
end
151
146
end
152
147
153
148
end
154
149
end
155
- end
0 commit comments