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

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

Overview

Extended API window management user interface.

Constant Summary collapse

Klass =
Console::CommandDispatcher::Extapi::Window
@@window_enum_opts =

Options for the window_enum command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-p" => [ true,  "Parent window handle, used to enumerate child windows" ],
  "-u" => [ false, "Include unknown/untitled windows in the result set" ]
)

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_window_enum(*args) ⇒ Object

Enumerate top-level windows.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb', line 61

def cmd_window_enum(*args)
  parent_window = nil
  include_unknown = false

  @@window_enum_opts.parse(args) { |opt, idx, val|
    case opt
    when "-u"
      include_unknown = true
    when "-p"
      parent_window = val.to_i
      if parent_window == 0
        window_enum_usage
        return true
      end
    when "-h"
      window_enum_usage
      return true
    end
  }

  windows = client.extapi.window.enumerate(include_unknown, parent_window)

  header = parent_window ? "Child windows of #{parent_window}" : "Top-level windows"

  table = Rex::Ui::Text::Table.new(
    'Header'    => header,
    'Indent'    => 0,
    'SortIndex' => 0,
    'Columns'   => [
      'PID', 'Handle', 'Title'
    ]
  )

  windows.each { |w|
    table << [w[:pid], w[:handle], w[:title]]
  }

  print_line
  print_line(table.to_s)

  if parent_window.nil?
    print_line("Total top-level Windows: #{windows.length}")
  else
    print_line("Total child Windows: #{windows.length}")
  end

  print_line

  return true
end

#commandsObject

List of supported commands.



23
24
25
26
27
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb', line 23

def commands
  {
    "window_enum" => "Enumerate all current open windows"
  }
end

#nameObject

Name for this dispatcher



32
33
34
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb', line 32

def name
  "Extapi: Window Management"
end

#window_enum_usageObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb', line 45

def window_enum_usage
  print(
    "\nUsage: window_enum [-h] [-p parent_window] [-u]\n\n" +
    "Enumerate the windows on the target.\n\n" +
    "Enumeration returns the Process ID and Window Handle for each window\n" +
    "found. The Window Handle can be used for further calls to window_enum\n" +
    "or the railgun API.\n" +
    @@window_enum_opts.usage +
    "Note: Not all windows can be enumerated. An attempt to enumerate\n" +
    "      the children of such a window will result in a failure with the\n"+
    "      message \"Operation failed: The parameter is incorrect.\"\n\n")
end