Class: Msf::Ui::Console::CommandDispatcher::Resource

Inherits:
Object
  • Object
show all
Includes:
Msf::Ui::Console::CommandDispatcher
Defined in:
lib/msf/ui/console/command_dispatcher/resource.rb

Overview

Msf::Ui::Console::CommandDispatcher for commands related to background jobs in Metasploit Framework.

Instance Attribute Summary

Attributes included from Msf::Ui::Console::CommandDispatcher

#driver

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

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Msf::Ui::Console::CommandDispatcher

#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #initialize, #load_config, #log_error, #remove_lines

Methods included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #initialize, #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

Instance Method Details

#cmd_makerc(*args) ⇒ Object

Saves commands executed since the ui started to the specified msfrc file



130
131
132
133
134
135
136
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 130

def cmd_makerc(*args)
  if args.empty? || args.include?('-h')
    cmd_makerc_help
    return false
  end
  driver.save_recent_history(args[0])
end

#cmd_makerc_helpObject



116
117
118
119
120
121
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 116

def cmd_makerc_help
  print_line "Usage: makerc <output rc file>"
  print_line
  print_line "Save the commands executed since startup to the specified file."
  print_line
end

#cmd_makerc_tabs(str, words) ⇒ Object



123
124
125
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 123

def cmd_makerc_tabs(str, words)
  tab_complete_filenames(str, words)
end

#cmd_resource(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 46

def cmd_resource(*args)
  if args.empty?
    cmd_resource_help
    return false
  end

  args.each do |res|
    res_expand = ::File.expand_path(res)
    good_res = nil
    if res == '-'
      good_res = res
    elsif ::File.file?(res_expand) && File.readable?(res_expand)
      good_res = res_expand
    else
      # let's check to see if it's in the scripts/resource dir (like when tab completed)
      [
        ::Msf::Config.script_directory + ::File::SEPARATOR + 'resource',
        ::Msf::Config.user_script_directory + ::File::SEPARATOR + 'resource'
      ].each do |dir|
        res_path = dir + ::File::SEPARATOR + res
        if ::File.file?(res_path) && File.readable?(res_path)
          good_res = res_path
          break
        end
      end
    end
    if good_res
      driver.load_resource(good_res)
    else
      print_error("#{res} is not a valid resource file")
      next
    end
  end
end

#cmd_resource_helpObject



36
37
38
39
40
41
42
43
44
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 36

def cmd_resource_help
  print_line "Usage: resource path1 [path2 ...]"
  print_line
  print_line "Run the commands stored in the supplied files (- for stdin)."
  print_line "Resource files may also contain ERB or Ruby code between <ruby></ruby> tags."
  print_line
  print_line "See also: makerc"
  print_line
end

#cmd_resource_tabs(str, words) ⇒ Object

Tab completion for the resource command

at least 1 when tab completion has reached this stage since the command itself has been completed

Parameters:

  • str (String)

    the string currently being typed before tab was hit

  • words (Array<String>)

    the previously completed words on the command line. words is always



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 88

def cmd_resource_tabs(str, words)
  tabs = []
  #return tabs if words.length > 1
  if !str.nil? && (str.start_with?('~') || str =~ /^#{Regexp.escape(File::SEPARATOR)}/)
    # then you are probably specifying a full path so let's just use normal file completion
    return tab_complete_filenames(str, words)
  elsif (not words[1] or not words[1].match(/^\//))
    # then let's start tab completion in the scripts/resource directories
    begin
      [
        ::Msf::Config.script_directory + File::SEPARATOR + "resource",
        ::Msf::Config.user_script_directory + File::SEPARATOR + "resource",
        '.'
      ].each do |dir|
        next unless ::File.exist?(dir)
        tabs += ::Dir.new(dir).find_all { |e|
          path = dir + File::SEPARATOR + e
          ::File.file?(path) && File.readable?(path)
        }
      end
    rescue
    end
  else
    tabs += tab_complete_filenames(str,words)
  end
  return tabs
end

#commandsObject



22
23
24
25
26
27
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 22

def commands
  {
    "resource"   => "Run the commands stored in a file",
    "makerc"     => "Save commands entered since start to a file",
  }
end

#nameObject

Returns the name of the command dispatcher.



32
33
34
# File 'lib/msf/ui/console/command_dispatcher/resource.rb', line 32

def name
  "Resource Script"
end