diff --git a/lib/msf/core/auxiliary/jtr.rb b/lib/msf/core/auxiliary/jtr.rb index 6b9ddb322b3c..140fa94ee443 100644 --- a/lib/msf/core/auxiliary/jtr.rb +++ b/lib/msf/core/auxiliary/jtr.rb @@ -37,45 +37,57 @@ def initialize(info = {}) autodetect_platform end + # @return [String] the run path instance variable if the platform is detectable, nil otherwise. def autodetect_platform - cpuinfo_base = ::File.join(Msf::Config.install_root, "data", "cpuinfo") return @run_path if @run_path - - case ::RUBY_PLATFORM - when /mingw|cygwin|mswin/ - data = `"#{cpuinfo_base}/cpuinfo.exe"` rescue nil - case data - when /sse2/ - @run_path ||= "run.win32.sse2/john.exe" - when /mmx/ - @run_path ||= "run.win32.mmx/john.exe" - else - @run_path ||= "run.win32.any/john.exe" - end - - when /x86_64-linux/ - ::FileUtils.chmod(0755, "#{cpuinfo_base}/cpuinfo.ia64.bin") rescue nil - data = `#{cpuinfo_base}/cpuinfo.ia64.bin` rescue nil - case data - when /mmx/ - @run_path ||= "run.linux.x64.mmx/john" - else - @run_path ||= "run.linux.x86.any/john" - end - - when /i[\d]86-linux/ - ::FileUtils.chmod(0755, "#{cpuinfo_base}/cpuinfo.ia32.bin") rescue nil - data = `#{cpuinfo_base}/cpuinfo.ia32.bin` rescue nil - case data - when /sse2/ - @run_path ||= "run.linux.x86.sse2/john" - when /mmx/ - @run_path ||= "run.linux.x86.mmx/john" - else - @run_path ||= "run.linux.x86.any/john" + cpuinfo_base = ::File.join(Msf::Config.data_directory, "cpuinfo") + if File.directory?(cpuinfo_base) + data = nil + + case ::RUBY_PLATFORM + when /mingw|cygwin|mswin/ + fname = "#{cpuinfo_base}/cpuinfo.exe" + if File.exists?(fname) and File.executable?(fname) + data = %x{"#{fname}"} rescue nil + end + case data + when /sse2/ + @run_path ||= "run.win32.sse2/john.exe" + when /mmx/ + @run_path ||= "run.win32.mmx/john.exe" + else + @run_path ||= "run.win32.any/john.exe" + end + when /x86_64-linux/ + fname = "#{cpuinfo_base}/cpuinfo.ia64.bin" + if File.exists? fname + ::FileUtils.chmod(0755, fname) rescue nil + data = %x{"#{fname}"} rescue nil + end + case data + when /mmx/ + @run_path ||= "run.linux.x64.mmx/john" + else + @run_path ||= "run.linux.x86.any/john" + end + when /i[\d]86-linux/ + fname = "#{cpuinfo_base}/cpuinfo.ia32.bin" + if File.exists? fname + ::FileUtils.chmod(0755, fname) rescue nil + data = %x{"#{fname}"} rescue nil + end + case data + when /sse2/ + @run_path ||= "run.linux.x86.sse2/john" + when /mmx/ + @run_path ||= "run.linux.x86.mmx/john" + else + @run_path ||= "run.linux.x86.any/john" + end end end - @run_path + + return @run_path end def john_session_id