Land #10717, Enhance msfdb to check path for required commands

GSoC/Meterpreter_Web_Console
Brent Cook 2018-09-28 16:23:10 -05:00
commit c23e6cce5a
No known key found for this signature in database
GPG Key ID: 1FFAA0B24B708F96
1 changed files with 36 additions and 0 deletions

36
msfdb
View File

@ -12,6 +12,17 @@ require 'sysrandom/securerandom'
require 'uri' require 'uri'
require 'yaml' 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__) @script_name = File.basename(__FILE__)
@framework = File.expand_path(File.dirname(__FILE__)) @framework = File.expand_path(File.dirname(__FILE__))
@ -906,6 +917,27 @@ def invoke_command(commands, component, command)
end end
end 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| !Msf::Util::Helper.which(cmd).nil? }
puts missing_msg % { name: 'PostgreSQL' }
ret_val = false
end
other_cmds.each do |cmd|
if Msf::Util::Helper.which(cmd).nil?
puts missing_msg % { name: "'#{cmd}'" }
ret_val = false
end
end
ret_val
end
if $PROGRAM_NAME == __FILE__ if $PROGRAM_NAME == __FILE__
@ -915,6 +947,10 @@ if $PROGRAM_NAME == __FILE__
abort abort
end end
unless has_requirements
abort
end
# map component commands to methods # map component commands to methods
commands = { commands = {
database: { database: {