Class: Rex::Post::HWBridge::Ui::Console::CommandDispatcher::CustomMethods

Inherits:
Object
  • Object
show all
Includes:
Msf::Auxiliary::Report, Rex::Post::HWBridge::Ui::Console::CommandDispatcher
Defined in:
lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb

Overview

Custom Methods extension - a set of commands defined by the HW itself

Constant Summary collapse

@@generic_opts =
Rex::Parser::Arguments.new(
"-h" => [ false, "Help menu."                    ])

Instance Attribute Summary

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Msf::Auxiliary::Report

#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot

Methods included from Metasploit::Framework::Require

optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines

Methods included from Rex::Post::HWBridge::Ui::Console::CommandDispatcher

check_hash, #client, #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, #docs_dir, #help_to_s, included, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt

Constructor Details

#initialize(shell) ⇒ CustomMethods

Returns a new instance of CustomMethods.



15
16
17
18
19
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb', line 15

def initialize(shell)
  super
  @cmds = {}
  @custom_methods = {}
end

Instance Method Details

#cmd_generic_handler(*args) ⇒ Object

A generic handler for all custom commands



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb', line 73

def cmd_generic_handler(*args)
  cmd = __callee__.to_s.gsub(/^cmd_/,'')
  @@generic_opts.parse(args) { |opt, idx, val|
    case opt
    when "-h"
      cmd_generic_handler_help(cmd)
      return true
    end
  }
  if not has_required_args(cmd, args)
    print_error("Not all required arguments were used.  See command help (-h)")
    return true
  end
  res = client.custom_methods.send_request(cmd, args, @custom_methods)
  print_status(res["status"]) if res.key? "status"
  print_status(res["value"]) if res.key? "value"
end

#cmd_generic_handler_help(cmd) ⇒ Object

A generic help system to show the arguments needed for custom commands



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb', line 55

def cmd_generic_handler_help(cmd)
  @custom_methods.each do |meth|
    next unless meth["method_name"] =~ /#{cmd}$/
    args = ""
    args = "<args>" if meth["args"].size > 0
    print_line("Usage: #{cmd} #{args}")
    print_line
    meth["args"].each do |arg|
      req = ""
      req = "  *required*" if arg.key? "required" and arg["required"] == true
      print_line("  #{arg["arg_name"]}=<#{arg["arg_type"]}> #{req}")
    end
  end
end

#commandsObject

List of supported commands.



27
28
29
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb', line 27

def commands
  @cmds ||= {}
end

#has_required_args(cmd, args) ⇒ Object

Verify all required args are used



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb', line 94

def has_required_args(cmd, args)
  all_found = true
  arguments = {}
  args.each do |arg|
    (key, value) = arg.split('=')
    arguments[key] = value
  end
  @custom_methods.each do |meth|
    if meth["method_name"] =~ /#{cmd}$/
      meth["args"].each do |arg|
        if arg.key? "required" and arg["required"] == true
          all_found = false if not arguments.key? arg["arg_name"]
        end
      end
    end
  end
  all_found
end

#load_methods(m) ⇒ Object

Loaded from core and passed hash from custom_methods rest call



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb', line 38

def load_methods(m)
  @custom_methods = m
  m.each do |method|
    if method.key? "method_name"
      desc = "See HW manual for command description"
      desc = method["method_desc"] if method.key? "method_desc"
      cmd = method["method_name"]
      cmd = /\/(\S+)$/.match(cmd)
      @cmds[cmd] = method["method_desc"]
      eval("alias cmd_#{cmd} cmd_generic_handler")
    end
  end
end

#nameObject



31
32
33
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb', line 31

def name
  "Custom Methods"
end