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

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

Overview

Extended API WMI Querying interface.

Constant Summary collapse

Klass =
Console::CommandDispatcher::Extapi::Wmi
DEFAULT_MAX_RESULTS =

Zero indicates “no limit”

0
DEFAULT_PAGE_SIZE =
0
@@wmi_query_opts =

Options for the wmi_query command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-r" => [ true, "Specify a different root object (defaults to 'root\\CIMV2')" ]
)

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

Enumerate WMI objects.



58
59
60
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
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb', line 58

def cmd_wmi_query(*args)
  args.unshift("-h") if args.length < 1

  root = nil

  @@wmi_query_opts.parse(args) { |opt, idx, val|
    case opt
    when "-r"
      root = val
    when "-h"
      wmi_query_usage
      return true
    end
  }

  query = args.shift

  objects = client.extapi.wmi.query(query, root)

  if objects
    table = Rex::Ui::Text::Table.new(
      'Header'    => query,
      'Indent'    => 0,
      'SortIndex' => 0,
      'Columns'   => objects[:fields]
    )

    objects[:values].each do |c|
      table << c
    end

    print_line
    print_line(table.to_s)

    print_line("Total objects: #{objects[:values].length}")
  else
    print_status("The WMI query yielded no results.")
  end

  print_line

  return true
end

#commandsObject

List of supported commands.



27
28
29
30
31
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb', line 27

def commands
  {
    "wmi_query" => "Perform a generic WMI query and return the results"
  }
end

#nameObject

Name for this dispatcher



36
37
38
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb', line 36

def name
  "Extapi: WMI Querying"
end

#wmi_query_usageObject



48
49
50
51
52
53
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb', line 48

def wmi_query_usage
  print(
    "\nUsage: wmi_query <query string> [-r root]\n\n" +
    "Query the target and display the results.\n\n" +
    @@wmi_query_opts.usage)
end