Class: Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Extapi::Clipboard

Inherits:
Object
  • Object
show all
Includes:
Extensions::Extapi, Rex::Post::Meterpreter::Ui::Console::CommandDispatcher
Defined in:
lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb

Constant Summary collapse

Klass =
Console::CommandDispatcher::Extapi::Clipboard
@@get_data_opts =

Options for the clipboard_get_data command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-d" => [ true, "Download non-text content to the specified folder (default: current dir)", nil ]
)
@@set_text_opts =

Options for the clipboard_set_text command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ]
)
@@monitor_start_opts =

Options for the clipboard_monitor_start command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-i" => [ true, "Capture image content when monitoring (default: true)" ]
)
@@monitor_purge_opts =

Options for the clipboard_monitor_purge command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ]
)
@@monitor_pause_opts =

Options for the clipboard_monitor_pause command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ]
)
@@monitor_resume_opts =

Options for the clipboard_monitor_resumse command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ]
)
@@monitor_dump_opts =

Options for the clipboard_monitor_dump command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-i" => [ true,  "Indicate if captured image data should be downloaded (default: true)" ],
  "-f" => [ true,  "Indicate if captured file data should be downloaded (default: true)" ],
  "-p" => [ true,  "Purge the contents of the monitor once dumped (default: true)" ],
  "-d" => [ true,  "Download non-text content to the specified folder (default: current dir)" ]
)
@@monitor_stop_opts =

Options for the clipboard_monitor_stop command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-x" => [ true,  "Indicate if captured clipboard data should be dumped (default: true)" ],
  "-i" => [ true,  "Indicate if captured image data should be downloaded (default: true)" ],
  "-f" => [ true,  "Indicate if captured file data should be downloaded (default: true)" ],
  "-d" => [ true,  "Download non-text content to the specified folder (default: current dir)" ]
)

Constants included from Extensions::Extapi

Extensions::Extapi::COMMAND_ID_EXTAPI_ADSI_DOMAIN_QUERY, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_GET_DATA, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_DUMP, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_PAUSE, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_PURGE, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_RESUME, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_START, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_STOP, Extensions::Extapi::COMMAND_ID_EXTAPI_CLIPBOARD_SET_DATA, Extensions::Extapi::COMMAND_ID_EXTAPI_NTDS_PARSE, Extensions::Extapi::COMMAND_ID_EXTAPI_PAGEANT_SEND_QUERY, Extensions::Extapi::COMMAND_ID_EXTAPI_SERVICE_CONTROL, Extensions::Extapi::COMMAND_ID_EXTAPI_SERVICE_ENUM, Extensions::Extapi::COMMAND_ID_EXTAPI_SERVICE_QUERY, Extensions::Extapi::COMMAND_ID_EXTAPI_WINDOW_ENUM, Extensions::Extapi::COMMAND_ID_EXTAPI_WMI_QUERY, Extensions::Extapi::EXTENSION_ID_EXTAPI, Extensions::Extapi::TLV_TYPE_EXTENSION_EXTAPI, Extensions::Extapi::TLV_TYPE_EXTENSION_PAGEANT_BLOB_IN, Extensions::Extapi::TLV_TYPE_EXTENSION_PAGEANT_ERRORMESSAGE, Extensions::Extapi::TLV_TYPE_EXTENSION_PAGEANT_RETURNEDBLOB, Extensions::Extapi::TLV_TYPE_EXTENSION_PAGEANT_SIZE_IN, Extensions::Extapi::TLV_TYPE_EXTENSION_PAGEANT_STATUS, Extensions::Extapi::TLV_TYPE_EXT_ADSI_ARRAY, Extensions::Extapi::TLV_TYPE_EXT_ADSI_BIGNUMBER, Extensions::Extapi::TLV_TYPE_EXT_ADSI_BOOL, Extensions::Extapi::TLV_TYPE_EXT_ADSI_DN, Extensions::Extapi::TLV_TYPE_EXT_ADSI_DOMAIN, Extensions::Extapi::TLV_TYPE_EXT_ADSI_FIELD, Extensions::Extapi::TLV_TYPE_EXT_ADSI_FILTER, Extensions::Extapi::TLV_TYPE_EXT_ADSI_MAXRESULTS, Extensions::Extapi::TLV_TYPE_EXT_ADSI_NUMBER, Extensions::Extapi::TLV_TYPE_EXT_ADSI_PAGESIZE, Extensions::Extapi::TLV_TYPE_EXT_ADSI_PATH, Extensions::Extapi::TLV_TYPE_EXT_ADSI_PATH_PATH, Extensions::Extapi::TLV_TYPE_EXT_ADSI_PATH_TYPE, Extensions::Extapi::TLV_TYPE_EXT_ADSI_PATH_VOL, Extensions::Extapi::TLV_TYPE_EXT_ADSI_RAW, Extensions::Extapi::TLV_TYPE_EXT_ADSI_RESULT, Extensions::Extapi::TLV_TYPE_EXT_ADSI_STRING, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_DOWNLOAD, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_MON_CAP_IMG_DATA, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_MON_DUMP, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_MON_PURGE, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_MON_WIN_CLASS, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_FILE, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_FILES, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_FILE_NAME, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_FILE_SIZE, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG_DATA, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG_DIMX, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_IMAGE_JPG_DIMY, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_TEXT_CONTENT, Extensions::Extapi::TLV_TYPE_EXT_CLIPBOARD_TYPE_TIMESTAMP, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_CTRL_NAME, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_CTRL_OP, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_ENUM_DISPLAYNAME, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_ENUM_GROUP, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_ENUM_INTERACTIVE, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_ENUM_NAME, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_ENUM_PID, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_ENUM_STATUS, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_DACL, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_DISPLAYNAME, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_INTERACTIVE, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_LOADORDERGROUP, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_PATH, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_STARTNAME, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_STARTTYPE, Extensions::Extapi::TLV_TYPE_EXT_SERVICE_QUERY_STATUS, Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_CLASSNAME, Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_GROUP, Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_HANDLE, Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_INCLUDEUNKNOWN, Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_PID, Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_TITLE, Extensions::Extapi::TLV_TYPE_EXT_WMI_DOMAIN, Extensions::Extapi::TLV_TYPE_EXT_WMI_ERROR, Extensions::Extapi::TLV_TYPE_EXT_WMI_FIELD, Extensions::Extapi::TLV_TYPE_EXT_WMI_FIELDS, Extensions::Extapi::TLV_TYPE_EXT_WMI_QUERY, Extensions::Extapi::TLV_TYPE_EXT_WMI_VALUE, Extensions::Extapi::TLV_TYPE_EXT_WMI_VALUES, Extensions::Extapi::TLV_TYPE_NTDS_PATH, Extensions::Extapi::TLV_TYPE_NTDS_TEST

Instance Attribute Summary

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Rex::Post::Meterpreter::Ui::Console::CommandDispatcher

check_hash, #client, #docs_dir, #filter_commands, #initialize, #log_error, #msf_loaded?, #session, set_hash, #unknown_command

Methods included from Msf::Ui::Console::CommandDispatcher::Session

#cmd_background, #cmd_background_help, #cmd_exit, #cmd_irb, #cmd_irb_help, #cmd_irb_tabs, #cmd_pry, #cmd_pry_help, #cmd_resource, #cmd_resource_help, #cmd_resource_tabs, #cmd_sessions, #cmd_sessions_help

Methods included from Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt

Instance Method Details

#cmd_clipboard_get_data(*args) ⇒ Object

Get the data from the target’s clipboard



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 74

def cmd_clipboard_get_data(*args)
  download_content = false
  download_path = nil
  @@get_data_opts.parse(args) { |opt, idx, val|
    case opt
    when "-d"
      download_content = true
      download_path = val
    when "-h"
      print_clipboard_get_data_usage
      return true
    end
  }

  dump = client.extapi.clipboard.get_data(download_content)

  if dump.length == 0
    print_error( "The current Clipboard data format is not supported." )
    return false
  end

  parse_dump(dump, download_content, download_content, download_path)
  return true
end

#cmd_clipboard_monitor_dump(*args) ⇒ Object

Dump the clipboard monitor contents to the local machine.



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 296

def cmd_clipboard_monitor_dump(*args)
  purge = true
  download_images = true
  download_files = true
  download_path = nil

  @@monitor_dump_opts.parse(args) { |opt, idx, val|
    case opt
    when "-d"
      download_path = val
    when "-i"
      download_images = val.downcase != 'false'
    when "-f"
      download_files = val.downcase != 'false'
    when "-p"
      purge = val.downcase != 'false'
    when "-h"
      print_clipboard_monitor_dump_usage
      return true
    end
  }

  dump = client.extapi.clipboard.monitor_dump({
    :include_images => download_images,
    :purge          => purge
  })

  parse_dump(dump, download_images, download_files, download_path)

  print_good("Clipboard monitor dumped")
end

#cmd_clipboard_monitor_pause(*args) ⇒ Object

Pause the clipboard monitor captured contents



229
230
231
232
233
234
235
236
237
238
239
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 229

def cmd_clipboard_monitor_pause(*args)
  @@monitor_pause_opts.parse(args) { |opt, idx, val|
    case opt
    when "-h"
      print_clipboard_monitor_pause_usage
      return true
    end
  }
  client.extapi.clipboard.monitor_pause
  print_good("Clipboard monitor paused successfully")
end

#cmd_clipboard_monitor_purge(*args) ⇒ Object

Purge the clipboard monitor captured contents



198
199
200
201
202
203
204
205
206
207
208
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 198

def cmd_clipboard_monitor_purge(*args)
  @@monitor_purge_opts.parse(args) { |opt, idx, val|
    case opt
    when "-h"
      print_clipboard_monitor_purge_usage
      return true
    end
  }
  client.extapi.clipboard.monitor_purge
  print_good("Captured clipboard contents purged successfully")
end

#cmd_clipboard_monitor_resume(*args) ⇒ Object

resume the clipboard monitor captured contents



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 260

def cmd_clipboard_monitor_resume(*args)
  @@monitor_resume_opts.parse(args) { |opt, idx, val|
    case opt
    when "-h"
      print_clipboard_monitor_resume_usage
      return true
    end
  }
  client.extapi.clipboard.monitor_resume
  print_good("Clipboard monitor resumed successfully")
end

#cmd_clipboard_monitor_start(*args) ⇒ Object

Start the clipboard monitor.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 154

def cmd_clipboard_monitor_start(*args)
  capture_images = true

  @@monitor_start_opts.parse(args) { |opt, idx, val|
    case opt
    when "-i"
      # default this to true
      capture_images = val.downcase != 'false'
    when "-h"
      print_clipboard_monitor_start_usage
      return true
    end
  }

  client.extapi.clipboard.monitor_start({
    # random class and window name so that it isn't easy
    # to track via a script
    :wincls  => Rex::Text.rand_text_alpha(8),
    :cap_img => capture_images
  })

  print_good("Clipboard monitor started")
end

#cmd_clipboard_monitor_stop(*args) ⇒ Object

Stop the clipboard monitor.



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 352

def cmd_clipboard_monitor_stop(*args)
  dump_data = true
  download_images = true
  download_files = true
  download_path = nil

  @@monitor_stop_opts.parse(args) { |opt, idx, val|
    case opt
    when "-d"
      download_path = val
    when "-x"
      dump_data = val.downcase != 'false'
    when "-i"
      download_images = val.downcase != 'false'
    when "-f"
      download_files = val.downcase != 'false'
    when "-h"
      print_clipboard_monitor_stop_usage
      return true
    end
  }

  dump = client.extapi.clipboard.monitor_stop({
    :dump           => dump_data,
    :include_images => download_images
  })

  parse_dump(dump, download_images, download_files, download_path) if dump_data

  print_good("Clipboard monitor stopped")
end

#cmd_clipboard_set_text(*args) ⇒ Object

Set the clipboard data to the given text.



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 115

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

#commandsObject

List of supported commands.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 24

def commands
  all = {
    'clipboard_get_data'       => "Read the target's current clipboard (text, files, images)",
    'clipboard_set_text'       => "Write text to the target's clipboard",
    'clipboard_monitor_start'  => 'Start the clipboard monitor',
    'clipboard_monitor_pause'  => 'Pause the active clipboard monitor',
    'clipboard_monitor_resume' => 'Resume the paused clipboard monitor',
    'clipboard_monitor_dump'   => 'Dump all captured clipboard content',
    'clipboard_monitor_purge'  => 'Delete all captured clipboard content without dumping it',
    'clipboard_monitor_stop'   => 'Stop the clipboard monitor'
  }
  reqs = {
    'clipboard_get_data'       => [COMMAND_ID_EXTAPI_CLIPBOARD_GET_DATA],
    'clipboard_set_text'       => [COMMAND_ID_EXTAPI_CLIPBOARD_SET_DATA],
    'clipboard_monitor_start'  => [COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_START],
    'clipboard_monitor_pause'  => [COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_PAUSE],
    'clipboard_monitor_resume' => [COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_RESUME],
    'clipboard_monitor_dump'   => [COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_DUMP],
    'clipboard_monitor_purge'  => [COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_PURGE],
    'clipboard_monitor_stop'   => [COMMAND_ID_EXTAPI_CLIPBOARD_MONITOR_STOP],
  }
  filter_commands(all, reqs)
end

#nameObject

Name for this dispatcher



51
52
53
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 51

def name
  'Extapi: Clipboard Management'
end


63
64
65
66
67
68
69
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 63

def print_clipboard_get_data_usage
  print(
    "\nUsage: clipboard_get_data [-h] [-d]\n\n" +
    "Attempts to read the data from the target's clipboard. If the data is in a\n" +
    "supported format, it is read and returned to the user.\n" +
    @@get_data_opts.usage + "\n")
end

Help for the clipboard_monitor_dump command.



286
287
288
289
290
291
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 286

def print_clipboard_monitor_dump_usage
  print(
    "\nUsage: clipboard_monitor_dump [-d true|false] [-d downloaddir] [-h]\n\n" +
    "Dump the capture clipboard contents to the local machine..\n\n" +
    @@monitor_dump_opts.usage + "\n")
end

Help for the clipboard_monitor_pause command.



220
221
222
223
224
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 220

def print_clipboard_monitor_pause_usage
  print("\nUsage: clipboard_monitor_pause [-h]\n\n" +
    "Pause the currently running clipboard monitor thread.\n\n" +
    @@monitor_pause_opts.usage + "\n")
end

Help for the clipboard_monitor_purge command.



188
189
190
191
192
193
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 188

def print_clipboard_monitor_purge_usage
  print("\nUsage: clipboard_monitor_purge [-h]\n\n" +
    "Purge the captured contents from the monitor. This does not stop\n" +
    "the monitor from running, it just removes captured content.\n\n" +
    @@monitor_purge_opts.usage + "\n")
end

Help for the clipboard_monitor_resume command.



251
252
253
254
255
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 251

def print_clipboard_monitor_resume_usage
  print("\nUsage: clipboard_monitor_resume [-h]\n\n" +
    "Resume the currently paused clipboard monitor thread.\n\n" +
    @@monitor_resume_opts.usage + "\n")
end

Help for the clipboard_monitor_start command.



140
141
142
143
144
145
146
147
148
149
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 140

def print_clipboard_monitor_start_usage
  print(
    "\nUsage: clipboard_monitor_start [-i true|false] [-h]\n\n" +
    "Starts a background clipboard monitoring thread. The thread watches\n" +
    "the clipboard on the target, under the context of the current desktop, and when\n" +
    "changes are detected the contents of the clipboard are captured. Contents can be\n" +
    "dumped periodically. Image content can be captured as well (and will be by default)\n" +
    "however this can consume quite a bit of memory.\n\n" +
    @@monitor_start_opts.usage + "\n")
end

Help for the clipboard_monitor_stop command.



342
343
344
345
346
347
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 342

def print_clipboard_monitor_stop_usage
  print(
    "\nUsage: clipboard_monitor_stop [-d true|false] [-x true|false] [-d downloaddir] [-h]\n\n" +
    "Stops a clipboard monitor thread and returns the captured data to the local machine.\n\n" +
    @@monitor_stop_opts.usage + "\n")
end


106
107
108
109
110
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 106

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