Skip to content

Commit 89d4f01

Browse files
committed
Make sure we close hashlist
1 parent abaec32 commit 89d4f01

File tree

1 file changed

+67
-68
lines changed

1 file changed

+67
-68
lines changed

modules/auxiliary/analyze/jtr_linux.rb

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -44,84 +44,83 @@ def run
4444
wordlist.write( build_seed().join("\n") + "\n" )
4545
wordlist.close
4646

47-
hashlist = Rex::Quickfile.new("jtrtmp")
48-
4947
myloots = myworkspace.loots.where('ltype=?', 'linux.hashes')
50-
unless myloots.nil? or myloots.empty?
51-
myloots.each do |myloot|
52-
usf = ''
53-
begin
54-
File.open(myloot.path, "rb") do |f|
55-
usf = f.read
56-
end
57-
rescue Exception => e
58-
print_error("Unable to read #{myloot.path} \n #{e}")
59-
end
60-
usf.each_line do |row|
61-
row.gsub!(/\n/, ":#{myloot.host.address}\n")
62-
hashlist.write(row)
48+
return if myloots.nil? or myloots.empty?
49+
50+
loot_data = ''
51+
52+
myloots.each do |myloot|
53+
usf = ''
54+
begin
55+
File.open(myloot.path, "rb") do |f|
56+
usf = f.read
6357
end
58+
rescue Exception => e
59+
print_error("Unable to read #{myloot.path} \n #{e}")
6460
end
65-
hashlist.close
66-
67-
print_status("HashList: #{hashlist.path}")
68-
69-
print_status("Trying Format:md5 Wordlist: #{wordlist.path}")
70-
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'md5')
71-
print_status("Trying Format:md5 Rule: All4...")
72-
john_crack(hashlist.path, :incremental => "All4", :format => 'md5')
73-
print_status("Trying Format:md5 Rule: Digits5...")
74-
john_crack(hashlist.path, :incremental => "Digits5", :format => 'md5')
75-
76-
77-
print_status("Trying Format:des Wordlist: #{wordlist.path}")
78-
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'des')
79-
print_status("Trying Format:des Rule: All4...")
80-
john_crack(hashlist.path, :incremental => "All4", :format => 'des')
81-
print_status("Trying Format:des Rule: Digits5...")
82-
john_crack(hashlist.path, :incremental => "Digits5", :format => 'des')
83-
84-
print_status("Trying Format:bsdi Wordlist: #{wordlist.path}")
85-
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'bsdi')
86-
print_status("Trying Format:bsdi Rule: All4...")
87-
john_crack(hashlist.path, :incremental => "All4", :format => 'bsdi')
88-
print_status("Trying Format:bsdi Rule: Digits5...")
89-
john_crack(hashlist.path, :incremental => "Digits5", :format => 'bsdi')
90-
91-
if datastore['Crypt']
92-
print_status("Trying Format:crypt Wordlist: #{wordlist.path}")
93-
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'crypt')
94-
print_status("Trying Rule: All4...")
95-
john_crack(hashlist.path, :incremental => "All4", :format => 'crypt')
96-
print_status("Trying Rule: Digits5...")
97-
john_crack(hashlist.path, :incremental => "Digits5", :format => 'crypt')
61+
usf.each_line do |row|
62+
row.gsub!(/\n/, ":#{myloot.host.address}\n")
63+
loot_data << row
9864
end
65+
end
66+
67+
hashlist = Rex::Quickfile.new("jtrtmp")
68+
hashlist.write(loot_data)
69+
hashlist.close
70+
71+
print_status("HashList: #{hashlist.path}")
72+
73+
print_status("Trying Format:md5 Wordlist: #{wordlist.path}")
74+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'md5')
75+
print_status("Trying Format:md5 Rule: All4...")
76+
john_crack(hashlist.path, :incremental => "All4", :format => 'md5')
77+
print_status("Trying Format:md5 Rule: Digits5...")
78+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'md5')
79+
80+
81+
print_status("Trying Format:des Wordlist: #{wordlist.path}")
82+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'des')
83+
print_status("Trying Format:des Rule: All4...")
84+
john_crack(hashlist.path, :incremental => "All4", :format => 'des')
85+
print_status("Trying Format:des Rule: Digits5...")
86+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'des')
87+
88+
print_status("Trying Format:bsdi Wordlist: #{wordlist.path}")
89+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'bsdi')
90+
print_status("Trying Format:bsdi Rule: All4...")
91+
john_crack(hashlist.path, :incremental => "All4", :format => 'bsdi')
92+
print_status("Trying Format:bsdi Rule: Digits5...")
93+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'bsdi')
94+
95+
if datastore['Crypt']
96+
print_status("Trying Format:crypt Wordlist: #{wordlist.path}")
97+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'crypt')
98+
print_status("Trying Rule: All4...")
99+
john_crack(hashlist.path, :incremental => "All4", :format => 'crypt')
100+
print_status("Trying Rule: Digits5...")
101+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'crypt')
102+
end
99103

100104

101-
cracked = john_show_passwords(hashlist.path)
105+
cracked = john_show_passwords(hashlist.path)
102106

103107

104-
print_status("#{cracked[:cracked]} hashes were cracked!")
108+
print_status("#{cracked[:cracked]} hashes were cracked!")
105109

106-
cracked[:users].each_pair do |k,v|
107-
if v[0] == "NO PASSWORD"
108-
passwd=""
109-
else
110-
passwd=v[0]
111-
end
112-
print_good("Host: #{v.last} User: #{k} Pass: #{passwd}")
113-
report_auth_info(
114-
:host => v.last,
115-
:port => 22,
116-
:sname => 'ssh',
117-
:user => k,
118-
:pass => passwd
119-
)
110+
cracked[:users].each_pair do |k,v|
111+
if v[0] == "NO PASSWORD"
112+
passwd=""
113+
else
114+
passwd=v[0]
120115
end
116+
print_good("Host: #{v.last} User: #{k} Pass: #{passwd}")
117+
report_auth_info(
118+
:host => v.last,
119+
:port => 22,
120+
:sname => 'ssh',
121+
:user => k,
122+
:pass => passwd
123+
)
121124
end
122-
123125
end
124-
125-
126-
127126
end

0 commit comments

Comments
 (0)