Add rudimentary Windows support to command_exists?

GSoC/Meterpreter_Web_Console
William Vu 2019-01-31 22:07:30 -06:00
parent d0d383c8db
commit 62560f9581
1 changed files with 7 additions and 1 deletions

View File

@ -240,7 +240,13 @@ module Msf::Post::Common
# @return [Boolean] # @return [Boolean]
# #
def command_exists?(cmd) def command_exists?(cmd)
cmd_exec("command -v #{cmd} && echo true").to_s.include? 'true' if session.platform == 'windows'
# https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/where_1
# https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/if
cmd_exec("cmd /c where /q #{cmd} & if not errorlevel 1 echo true").to_s.include? 'true'
else
cmd_exec("command -v #{cmd} && echo true").to_s.include? 'true'
end
rescue rescue
raise "Unable to check if command `#{cmd}' exists" raise "Unable to check if command `#{cmd}' exists"
end end