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

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

Overview

Extended API ADSI management user interface.

Constant Summary collapse

Klass =
Console::CommandDispatcher::Extapi::Adsi
DEFAULT_MAX_RESULTS =

Zero indicates “no limit”

0
DEFAULT_PAGE_SIZE =
0
@@adsi_user_enum_opts =

Options for the adsi_user_enum command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-m" => [ true, "Maximum results to return." ],
  "-p" => [ true, "Result set page size." ]
)
@@adsi_computer_enum_opts =

Options for the adsi_computer_enum command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-m" => [ true, "Maximum results to return." ],
  "-p" => [ true, "Result set page size." ]
)
@@adsi_domain_query_opts =

Options for the adsi_domain_query command.

Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner" ],
  "-m" => [ true, "Maximum results to return." ],
  "-p" => [ true, "Result set page size." ]
)

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

#adsi_computer_enum_usageObject



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

def adsi_computer_enum_usage
  print(
    "\nUsage: adsi_computer_enum <domain> [-h] [-m maxresults] [-p pagesize]\n\n" +
    "Enumerate the computers on the target domain.\n\n" +
    "Enumeration returns information such as the computer name, desc, and comment.\n" +
    @@adsi_computer_enum_opts.usage)
end

#adsi_domain_query_usageObject



131
132
133
134
135
136
137
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb', line 131

def adsi_domain_query_usage
  print(
    "\nUsage: adsi_domain_query <domain> <filter> <field 1> [field 2 [field ..]] [-h] [-m maxresults] [-p pagesize]\n\n" +
    "Enumerate the objects on the target domain.\n\n" +
    "Enumeration returns the set of fields that are specified.\n" +
    @@adsi_domain_query_opts.usage)
end

#adsi_user_enum_usageObject



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

def adsi_user_enum_usage
  print(
    "\nUsage: adsi_user_enum <domain> [-h] [-m maxresults] [-p pagesize]\n\n" +
    "Enumerate the users on the target domain.\n\n" +
    "Enumeration returns information such as the user name, SAM account name, locked\n" +
    "status, desc, and comment.\n" +
    @@adsi_user_enum_opts.usage)
end

#cmd_adsi_computer_enum(*args) ⇒ Object

Enumerate domain computers.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb', line 103

def cmd_adsi_computer_enum(*args)
  args.unshift("-h") if args.length == 0
  if args.include?("-h")
    adsi_computer_enum_usage
    return true
  end

  domain = args.shift
  filter = "(objectClass=computer)"
  fields = [
    "name",
    "distinguishedname",
    "description",
    "comment"
    ]
  args = [domain, filter] + fields + args
  return cmd_adsi_domain_query(*args)
end

#cmd_adsi_domain_query(*args) ⇒ Object

Enumerate domain objects.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb', line 142

def cmd_adsi_domain_query(*args)
  page_size = DEFAULT_PAGE_SIZE
  max_results = DEFAULT_MAX_RESULTS

  args.unshift("-h") if args.length < 3

  @@adsi_domain_query_opts.parse(args) { |opt, idx, val|
    case opt
    when "-p"
      page_size = val.to_i
    when "-m"
      max_results = val.to_i
    when "-h"
      adsi_domain_query_usage
      return true
    end
  }

  # Assume that the flags are passed in at the end. Safe?
  switch_index = args.index { |a| a.start_with?("-") }
  if switch_index
    args = args.first(switch_index)
  end

  domain = args.shift
  filter = args.shift

  objects = client.extapi.adsi.domain_query(domain, filter, max_results, page_size, args)

  table = Rex::Ui::Text::Table.new(
    'Header'    => "#{domain} Objects",
    'Indent'    => 0,
    'SortIndex' => 0,
    'Columns'   => objects[:fields]
  )

  objects[:results].each do |c|
    table << to_table_row(c)
  end

  print_line
  print_line(table.to_s)

  print_line("Total objects: #{objects[:results].length}")

  print_line

  return true
end

#cmd_adsi_user_enum(*args) ⇒ Object

Enumerate domain users.



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

def cmd_adsi_user_enum(*args)
  args.unshift("-h") if args.length == 0
  if args.include?("-h")
    adsi_user_enum_usage
    return true
  end

  domain = args.shift
  filter = "(objectClass=user)"
  fields = [
    "samaccountname",
    "name",
    "distinguishedname",
    "description",
    "comment"
    ]
  args = [domain, filter] + fields + args
  return cmd_adsi_domain_query(*args)
end

#commandsObject

List of supported commands.



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

def commands
  {
    "adsi_user_enum"     => "Enumerate all users on the specified domain.",
    "adsi_computer_enum" => "Enumerate all computers on the specified domain.",
    "adsi_domain_query"  => "Enumerate all objects on the specified domain that match a filter."
  }
end

#nameObject

Name for this dispatcher



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

def name
  "Extapi: ADSI Management"
end