Use Msf::Util::Helper.which method

This commit is contained in:
Matthew Kienow
2018-09-28 14:48:23 -04:00
parent 55cf17bf15
commit c3a2b72836
+13 -21
View File
@@ -12,6 +12,17 @@ require 'sysrandom/securerandom'
require 'uri'
require 'yaml'
msfbase = __FILE__
while File.symlink?(msfbase)
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
require 'msf/util/helper'
@script_name = File.basename(__FILE__)
@framework = File.expand_path(File.dirname(__FILE__))
@@ -906,38 +917,19 @@ def invoke_command(commands, component, command)
end
end
# Searches the user's path for the executable file that would be run had the
# command actually been invoked.
# @param cmd [String] command name
# @param return_all [Boolean] If true, returns a list of all instances of
# executable found (instead of just the first one). Default: false.
# @return [Array] instance or instances of executable found based on return_all, or nil.
def which(cmd, return_all: false)
return nil if cmd.empty?
found = []
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exe_file = File.join(path, cmd)
found << exe_file if !File.directory?(exe_file) && File.executable?(exe_file)
break if !return_all && found.size > 0
end
return found.empty? ? nil : found
end
def has_requirements
ret_val = true
postgresql_cmds = %w(psql pg_ctl initdb createdb)
other_cmds = %w(bundle thin)
missing_msg = 'Missing requirement: %<name>s does not appear to be installed or is not in the environment path'
unless postgresql_cmds.all? { |cmd| !which(cmd).nil? }
unless postgresql_cmds.all? { |cmd| !Msf::Util::Helper.which(cmd).nil? }
puts missing_msg % { name: 'PostgreSQL' }
ret_val = false
end
other_cmds.each do |cmd|
if which(cmd).nil?
if Msf::Util::Helper.which(cmd).nil?
puts missing_msg % { name: "'#{cmd}'" }
ret_val = false
end