Skip to content

Commit 7e1a14f

Browse files
committed
Land rapid7#2254 - Fix TypeError can't convert nil into String
This fixes TypeError can't convert nil into String errors.
2 parents 4790d8d + 7e37130 commit 7e1a14f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

lib/msf/core/auxiliary/jtr.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,17 @@ def john_cracked_passwords
101101
def john_show_passwords(hfile, format=nil)
102102
res = {:cracked => 0, :uncracked => 0, :users => {} }
103103

104+
john_command = john_binary_path
105+
106+
if john_command.nil?
107+
print_error("John the Ripper executable not found")
108+
return res
109+
end
110+
104111
pot = john_pot_file
105112
conf = ::File.join(john_base_path, "confs", "john.conf")
106113

107-
cmd = [ john_binary_path, "--show", "--conf=#{conf}", "--pot=#{pot}", hfile]
114+
cmd = [ john_command, "--show", "--conf=#{conf}", "--pot=#{pot}", hfile]
108115

109116
if format
110117
cmd << "--format=" + format
@@ -140,6 +147,13 @@ def john_unshadow(passwd_file,shadow_file)
140147

141148
retval=""
142149

150+
john_command = john_binary_path
151+
152+
if john_command.nil?
153+
print_error("John the Ripper executable not found")
154+
return nil
155+
end
156+
143157
if File.exists?(passwd_file)
144158
unless File.readable?(passwd_file)
145159
print_error("We do not have permission to read #{passwd_file}")
@@ -161,7 +175,7 @@ def john_unshadow(passwd_file,shadow_file)
161175
end
162176

163177

164-
cmd = [ john_binary_path.gsub(/john$/, "unshadow"), passwd_file , shadow_file ]
178+
cmd = [ john_command.gsub(/john$/, "unshadow"), passwd_file , shadow_file ]
165179

166180
if RUBY_VERSION =~ /^1\.8\./
167181
cmd = cmd.join(" ")
@@ -237,9 +251,16 @@ def john_crack(hfile, opts={})
237251

238252
res = {:cracked => 0, :uncracked => 0, :users => {} }
239253

254+
john_command = john_binary_path
255+
256+
if john_command.nil?
257+
print_error("John the Ripper executable not found")
258+
return nil
259+
end
260+
240261
# Don't bother making a log file, we'd just have to rm it when we're
241262
# done anyway.
242-
cmd = [ john_binary_path, "--session=" + john_session_id, "--nolog"]
263+
cmd = [ john_command, "--session=" + john_session_id, "--nolog"]
243264

244265
if opts[:conf]
245266
cmd << ( "--conf=" + opts[:conf] )

0 commit comments

Comments
 (0)