Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/meterpreter/extensions/extapi/clipboard/clipboard.rb
Views: 11798
# -*- coding: binary -*-12module Rex3module Post4module Meterpreter5module Extensions6module Extapi7module Clipboard89###10#11# This meterpreter extension contains extended API functions for12# querying and managing desktop windows.13#14###15class Clipboard1617def initialize(client)18@client = client19end2021#22# Get the target clipboard data in whichever format we can23# (if it's supported).24#25def get_data(download = false)26request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_GET_DATA)2728if download29request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_DOWNLOAD, true)30end3132response = client.send_request(request)3334return parse_dump(response)35end3637#38# Set the target clipboard data to a text value39#40def set_text(text)41request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_SET_DATA)4243request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT_CONTENT, text)4445client.send_request(request)4647return true48end4950#51# Start the clipboard monitor if it hasn't been started.52#53def monitor_start(opts)54request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_START)55request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_MON_WIN_CLASS, opts[:wincls])56request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_MON_CAP_IMG_DATA, opts[:cap_img])57return client.send_request(request)58end5960#61# Pause the clipboard monitor if it's running.62#63def monitor_pause64request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_PAUSE)65return client.send_request(request)66end6768#69# Dump the contents of the clipboard monitor to the local machine.70#71def monitor_dump(opts)72pull_img = opts[:include_images]73purge = opts[:purge]74purge = true if purge.nil?7576request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_DUMP)77request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_MON_CAP_IMG_DATA, pull_img)78request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_MON_PURGE, purge)7980response = client.send_request(request)8182return parse_dump(response)83end8485#86# Resume the clipboard monitor if it has been paused.87#88def monitor_resume89request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_RESUME)90return client.send_request(request)91end9293#94# Purge the contents of the clipboard capture without downloading.95#96def monitor_purge97request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_PURGE)98return client.send_request(request)99end100101#102# Stop the clipboard monitor and dump optionally it's contents.103#104def monitor_stop(opts)105dump = opts[:dump]106pull_img = opts[:include_images]107108request = Packet.create_request(COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_STOP)109request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_MON_DUMP, dump)110request.add_tlv(TLV_TYPE_EXT_CLIPBOARD_MON_CAP_IMG_DATA, pull_img)111112response = client.send_request(request)113unless dump114return response115end116117return parse_dump(response)118end119120attr_accessor :client121122private123124def parse_dump(response)125result = {}126127response.each(TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT) do |t|128ts = t.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_TIMESTAMP)129result[ts] ||= {}130131# fat chance of someone adding two different bits of text to the132# clipboard at the same time133result[ts]['Text'] = t.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT_CONTENT)134end135136response.each(TLV_TYPE_EXT_CLIPBOARD_TYPE_FILES) do |fs|137ts = fs.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_TIMESTAMP)138result[ts] ||= {}139result[ts]['Files'] ||= []140fs.each(TLV_TYPE_EXT_CLIPBOARD_TYPE_FILE) do |f|141result[ts]['Files'] << {142:name => f.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_FILE_NAME),143:size => f.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_FILE_SIZE)144}145end146end147148response.each(TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG) do |jpg|149if jpg150ts = jpg.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_TIMESTAMP)151result[ts] ||= {}152153# same story with images, there's no way more than one can come154# through on the same timestamp with differences155result[ts]['Image'] = {156:width => jpg.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG_DIMX),157:height => jpg.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG_DIMY),158:data => jpg.get_tlv_value(TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG_DATA)159}160end161end162163return result164end165166end167168end; end; end; end; end; end169170171