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

Extended API window management user interface.

Constants

Klass

Public Class Methods

new(shell) click to toggle source

Initialize the instance

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb, line 40
def initialize(shell)
  super

  @status_map = {
    1 => "Stopped",
    2 => "Starting",
    3 => "Stopping",
    4 => "Running",
    5 => "Continuing",
    6 => "Pausing",
    7 => "Paused"
  }

  @start_type_map = {
    0 => "Boot",
    1 => "System",
    2 => "Automatic",
    3 => "Manual",
    4 => "Disabled"
  }
end

Public Instance Methods

cmd_service_control(*args) click to toggle source

Query a single service for more detail.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb, line 168
def cmd_service_control(*args)
  args.unshift("-h") if args.length != 2

  @@service_control_opts.parse(args) do |opt, idx, val|
    case opt
    when "-h"
      print(
        "\nUsage: service_control [-h] <servicename> <op>\n" +
        "   <servicename> : The name of the service to control.\n" +
        "            <op> : The operation to perform on the service.\n" +
        "                   Valid ops: start pause resume stop restart.\n\n")
        return true
    end
  end

  service_name = args[0]
  op = args[1]

  client.extapi.service.control(service_name, op)

  print_good("Operation #{op} succeeded.")
end
cmd_service_enum(*args) click to toggle source

Query a single service for more detail.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb, line 72
def cmd_service_enum(*args)
  @@service_enum_opts.parse(args) do |opt, idx, val|
    case opt
    when "-h"
      print(
        "\nUsage: service_enum [-h]\n\n" +
        "Enumerate services installed on the target.\n\n" +
        "Enumeration returns the Process ID, Status, and name of each installed\n" +
        "service that was enumerated. The 'Int' value indicates if the service is\n" +
        "able to interact with the desktop.\n\n")
        return true
    end
  end

  services = client.extapi.service.enumerate

  table = Rex::Ui::Text::Table.new(
    'Header'    => 'Service List',
    'Indent'    => 0,
    'SortIndex' => 3,
    'Columns'   => [
      'PID', 'Status', 'Int', 'Name (Display Name)'
    ]
  )

  services.each do |s|
    table << [
      s[:pid],
      @status_map[s[:status]],
      s[:interactive] ? "Y" : "N",
      "#{s[:name].downcase} (#{s[:display]})"
    ]
  end

  print_line
  print_line(table.to_s)
  print_line
  print_line("Total services: #{services.length}")
  print_line

  return true
end
cmd_service_query(*args) click to toggle source

Query a single service for more detail.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb, line 125
def cmd_service_query(*args)
  args.unshift("-h") if args.length != 1

  @@service_query_opts.parse(args) do |opt, idx, val|
    case opt
    when "-h"
      print(
        "\nUsage: service_query [-h] <servicename>\n" +
        "     <servicename>:  The name of the service to query.\n\n" +
        "Gets details information about a particular Windows service, including\n" +
        "binary path, DACL, load order group, start type and more.\n\n")
        return true
    end
  end

  service_name = args.shift

  detail = client.extapi.service.query(service_name)

  print_line
  print_line("Name        : #{service_name}")
  print_line("Display     : #{detail[:display]}")
  print_line("Account     : #{detail[:startname]}")
  print_line("Status      : #{@status_map[detail[:status]]}")
  print_line("Start Type  : #{@start_type_map[detail[:starttype]]}")
  print_line("Path        : #{detail[:path]}")
  print_line("L.O. Group  : #{detail[:logroup]}")
  print_line("Interactive : #{detail[:interactive] ? "Yes" : "No"}")
  print_line("DACL        : #{detail[:dacl]}")
  print_line

end
commands() click to toggle source

List of supported commands.

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb, line 22
def commands
  {
    "service_enum"    => "Enumerate all registered Windows services",
    "service_query"   => "Query more detail about a specific Windows service",
    "service_control" => "Control a single service (start/pause/resume/stop/restart)"
  }
end
name() click to toggle source

Name for this dispatcher

# File lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb, line 33
def name
  "Extapi: Service Management"
end