Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/ui/console/command_dispatcher/resource.rb
Views: 11787
# -*- coding: binary -*-12#3# Rex4#5678module Msf9module Ui10module Console11module CommandDispatcher1213#14# {CommandDispatcher} for commands related to background jobs in Metasploit Framework.15#16class Resource1718include Msf::Ui::Console::CommandDispatcher192021def commands22{23"resource" => "Run the commands stored in a file",24"makerc" => "Save commands entered since start to a file",25}26end2728#29# Returns the name of the command dispatcher.30#31def name32"Resource Script"33end3435def cmd_resource_help36print_line "Usage: resource path1 [path2 ...]"37print_line38print_line "Run the commands stored in the supplied files (- for stdin)."39print_line "Resource files may also contain ERB or Ruby code between <ruby></ruby> tags."40print_line41print_line "See also: makerc"42print_line43end4445def cmd_resource(*args)46if args.empty?47cmd_resource_help48return false49end5051args.each do |res|52res_expand = ::File.expand_path(res)53good_res = nil54if res == '-'55good_res = res56elsif ::File.file?(res_expand) && File.readable?(res_expand)57good_res = res_expand58else59# let's check to see if it's in the scripts/resource dir (like when tab completed)60[61::Msf::Config.script_directory + ::File::SEPARATOR + 'resource',62::Msf::Config.user_script_directory + ::File::SEPARATOR + 'resource'63].each do |dir|64res_path = dir + ::File::SEPARATOR + res65if ::File.file?(res_path) && File.readable?(res_path)66good_res = res_path67break68end69end70end71if good_res72driver.load_resource(good_res)73else74print_error("#{res} is not a valid resource file")75next76end77end78end7980#81# Tab completion for the resource command82#83# @param str [String] the string currently being typed before tab was hit84# @param words [Array<String>] the previously completed words on the command line. words is always85# at least 1 when tab completion has reached this stage since the command itself has been completed8687def cmd_resource_tabs(str, words)88tabs = []89#return tabs if words.length > 190if !str.nil? && (str.start_with?('~') || str =~ /^#{Regexp.escape(File::SEPARATOR)}/)91# then you are probably specifying a full path so let's just use normal file completion92return tab_complete_filenames(str, words)93elsif (not words[1] or not words[1].match(/^\//))94# then let's start tab completion in the scripts/resource directories95begin96[97::Msf::Config.script_directory + File::SEPARATOR + "resource",98::Msf::Config.user_script_directory + File::SEPARATOR + "resource",99'.'100].each do |dir|101next unless ::File.exist?(dir)102tabs += ::Dir.new(dir).find_all { |e|103path = dir + File::SEPARATOR + e104::File.file?(path) && File.readable?(path)105}106end107rescue108end109else110tabs += tab_complete_filenames(str,words)111end112return tabs113end114115def cmd_makerc_help116print_line "Usage: makerc <output rc file>"117print_line118print_line "Save the commands executed since startup to the specified file."119print_line120end121122def cmd_makerc_tabs(str, words)123tab_complete_filenames(str, words)124end125126#127# Saves commands executed since the ui started to the specified msfrc file128#129def cmd_makerc(*args)130if args.empty? || args.include?('-h')131cmd_makerc_help132return false133end134driver.save_recent_history(args[0])135end136end137138end139end140end141end142143144