Skip to content

Commit

Permalink
Land rapid7#11984, add meterpreter keyevent api for virtual key strokes
Browse files Browse the repository at this point in the history
Merge branch 'land-11984' into upstream-master
  • Loading branch information
bwatters-r7 committed Sep 10, 2019
2 parents e66179a + 809a990 commit 6703e9b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rex/post/meterpreter/extensions/stdapi/tlv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ module Stdapi
TLV_TYPE_MOUSE_ACTION = TLV_META_TYPE_UINT | 3015
TLV_TYPE_MOUSE_X = TLV_META_TYPE_UINT | 3016
TLV_TYPE_MOUSE_Y = TLV_META_TYPE_UINT | 3017
TLV_TYPE_KEYEVENT_SEND = TLV_META_TYPE_RAW | 3018

##
#
Expand Down
13 changes: 13 additions & 0 deletions lib/rex/post/meterpreter/extensions/stdapi/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ def keyboard_send(keys)
return true
end

#
# Send key events
#
def keyevent_send(key_code, action = 0)
key_data = [ action, key_code ].pack("VV")
request = Packet.create_request('stdapi_ui_send_keyevent')
request.add_tlv( TLV_TYPE_KEYEVENT_SEND, key_data )
response = client.send_request(request)
return true
end

#
# Mouse input
#
Expand All @@ -265,6 +276,8 @@ def mouse(mouseaction, x=-1, y=-1)
action = 5
when "rightup"
action = 6
when "doubleclick"
action = 7
else
action = mouseaction.to_i
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def commands
"keyscan_start" => "Start capturing keystrokes",
"keyscan_stop" => "Stop capturing keystrokes",
"keyboard_send" => "Send keystrokes",
"keyevent" => "Send key events",
"mouse" => "Send mouse events",
"screenshot" => "Grab a screenshot of the interactive desktop",
"screenshare" => "Watch the remote user's desktop in real time",
Expand All @@ -46,6 +47,7 @@ def commands
"keyscan_dump" => [ "stdapi_ui_get_keys_utf8" ],
"keyscan_start" => [ "stdapi_ui_start_keyscan" ],
"keyscan_stop" => [ "stdapi_ui_stop_keyscan" ],
"keyevent" => [ "stdapi_ui_send_keyevent" ],
"keyboard_send" => [ "stdapi_ui_send_keys" ],
"mouse" => [ "stdapi_ui_send_mouse" ],
"screenshot" => [ "stdapi_ui_desktop_screenshot" ],
Expand Down Expand Up @@ -442,6 +444,31 @@ def cmd_keyboard_send(*args)
print_status('Done')
end

#
# Send key events
#
def cmd_keyevent(*args)
action = 0
if args.length == 1
keycode = args[0].to_i
elsif args.length == 2
keycode = args[0].to_i
if args[1] == 'down'
action = 1
elsif args[1] == 'up'
action = 2
end
else
print_line("Usage: keyevent keycode [action] (press, up, down)")
print_line(" e.g: keyevent 13 press (send the enter key)")
print_line(" kevevent 17 down (control key down)\n")
return
end

client.ui.keyevent_send(keycode, action)
print_status('Done')
end

#
# Send mouse events
#
Expand All @@ -453,7 +480,7 @@ def cmd_mouse(*args)
elsif args.length == 3
client.ui.mouse(args[0], args[1], args[2])
else
print_line("Usage: mouse action (move, click, up, down, rightclick, rightup, rightdown)")
print_line("Usage: mouse action (move, click, up, down, rightclick, rightup, rightdown, doubleclick)")
print_line(" mouse [x] [y] (click)")
print_line(" mouse [action] [x] [y]")
print_line(" e.g: mouse click")
Expand Down

0 comments on commit 6703e9b

Please sign in to comment.