Skip to content

Commit 809b429

Browse files
author
jvazquez-r7
committed
Land @2243, @wchen-r7's patch for [SeeRM rapid7#8312]
2 parents 0af2f1c + d0b56e1 commit 809b429

File tree

6 files changed

+207
-153
lines changed

6 files changed

+207
-153
lines changed

modules/auxiliary/analyze/jtr_aix.rb

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,59 +32,66 @@ def initialize
3232

3333
def run
3434
wordlist = Rex::Quickfile.new("jtrtmp")
35+
begin
36+
wordlist.write( build_seed().join("\n") + "\n" )
37+
ensure
38+
wordlist.close
39+
end
3540

36-
wordlist.write( build_seed().join("\n") + "\n" )
37-
wordlist.close
41+
myloots = myworkspace.loots.find(:all, :conditions => ['ltype=?', 'aix.hashes'])
42+
return if myloots.nil? or myloots.empty?
3843

39-
hashlist = Rex::Quickfile.new("jtrtmp")
44+
loot_data = ''
4045

41-
myloots = myworkspace.loots.find(:all, :conditions => ['ltype=?', 'aix.hashes'])
42-
unless myloots.nil? or myloots.empty?
43-
myloots.each do |myloot|
44-
begin
45-
usf = File.open(myloot.path, "rb")
46-
rescue Exception => e
47-
print_error("Unable to read #{myloot.path} \n #{e}")
48-
next
49-
end
50-
usf.each_line do |row|
51-
row.gsub!(/\n/, ":#{myloot.host.address}\n")
52-
hashlist.write(row)
46+
myloots.each do |myloot|
47+
usf = ''
48+
begin
49+
File.open(myloot.path, "rb") do |f|
50+
usf = f.read
5351
end
52+
rescue Exception => e
53+
print_error("Unable to read #{myloot.path} \n #{e}")
54+
next
55+
end
56+
usf.each_line do |row|
57+
row.gsub!(/\n/, ":#{myloot.host.address}\n")
58+
loot_data << row
5459
end
55-
hashlist.close
60+
end
5661

57-
print_status("HashList: #{hashlist.path}")
62+
hashlist = Rex::Quickfile.new("jtrtmp")
63+
hashlist.write(loot_data)
64+
hashlist.close
5865

59-
print_status("Trying Format:des Wordlist: #{wordlist.path}")
60-
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'des')
61-
print_status("Trying Format:des Rule: All4...")
62-
john_crack(hashlist.path, :incremental => "All4", :format => 'des')
63-
print_status("Trying Format:des Rule: Digits5...")
64-
john_crack(hashlist.path, :incremental => "Digits5", :format => 'des')
66+
print_status("HashList: #{hashlist.path}")
6567

66-
cracked = john_show_passwords(hashlist.path)
68+
print_status("Trying Format:des Wordlist: #{wordlist.path}")
69+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'des')
70+
print_status("Trying Format:des Rule: All4...")
71+
john_crack(hashlist.path, :incremental => "All4", :format => 'des')
72+
print_status("Trying Format:des Rule: Digits5...")
73+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'des')
6774

75+
cracked = john_show_passwords(hashlist.path)
6876

69-
print_status("#{cracked[:cracked]} hashes were cracked!")
7077

71-
cracked[:users].each_pair do |k,v|
72-
if v[0] == "NO PASSWORD"
73-
passwd=""
74-
else
75-
passwd=v[0]
76-
end
77-
print_good("Host: #{v.last} User: #{k} Pass: #{passwd}")
78-
report_auth_info(
79-
:host => v.last,
80-
:port => 22,
81-
:sname => 'ssh',
82-
:user => k,
83-
:pass => passwd
84-
)
78+
print_status("#{cracked[:cracked]} hashes were cracked!")
79+
80+
cracked[:users].each_pair do |k,v|
81+
if v[0] == "NO PASSWORD"
82+
passwd=""
83+
else
84+
passwd=v[0]
8585
end
86+
print_good("Host: #{v.last} User: #{k} Pass: #{passwd}")
87+
report_auth_info(
88+
:host => v.last,
89+
:port => 22,
90+
:sname => 'ssh',
91+
:user => k,
92+
:pass => passwd
93+
)
8694
end
87-
8895
end
8996

9097
end

modules/auxiliary/analyze/jtr_linux.rb

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -41,84 +41,89 @@ def initialize
4141
def run
4242
wordlist = Rex::Quickfile.new("jtrtmp")
4343

44-
wordlist.write( build_seed().join("\n") + "\n" )
45-
wordlist.close
46-
47-
hashlist = Rex::Quickfile.new("jtrtmp")
44+
begin
45+
wordlist.write( build_seed().join("\n") + "\n" )
46+
ensure
47+
wordlist.close
48+
end
4849

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

70+
hashlist = Rex::Quickfile.new("jtrtmp")
71+
hashlist.write(loot_data)
72+
hashlist.close
73+
74+
print_status("HashList: #{hashlist.path}")
75+
76+
print_status("Trying Format:md5 Wordlist: #{wordlist.path}")
77+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'md5')
78+
print_status("Trying Format:md5 Rule: All4...")
79+
john_crack(hashlist.path, :incremental => "All4", :format => 'md5')
80+
print_status("Trying Format:md5 Rule: Digits5...")
81+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'md5')
82+
83+
84+
print_status("Trying Format:des Wordlist: #{wordlist.path}")
85+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'des')
86+
print_status("Trying Format:des Rule: All4...")
87+
john_crack(hashlist.path, :incremental => "All4", :format => 'des')
88+
print_status("Trying Format:des Rule: Digits5...")
89+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'des')
90+
91+
print_status("Trying Format:bsdi Wordlist: #{wordlist.path}")
92+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'bsdi')
93+
print_status("Trying Format:bsdi Rule: All4...")
94+
john_crack(hashlist.path, :incremental => "All4", :format => 'bsdi')
95+
print_status("Trying Format:bsdi Rule: Digits5...")
96+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'bsdi')
97+
98+
if datastore['Crypt']
99+
print_status("Trying Format:crypt Wordlist: #{wordlist.path}")
100+
john_crack(hashlist.path, :wordlist => wordlist.path, :rules => 'single', :format => 'crypt')
101+
print_status("Trying Rule: All4...")
102+
john_crack(hashlist.path, :incremental => "All4", :format => 'crypt')
103+
print_status("Trying Rule: Digits5...")
104+
john_crack(hashlist.path, :incremental => "Digits5", :format => 'crypt')
105+
end
97106

98-
cracked = john_show_passwords(hashlist.path)
99107

108+
cracked = john_show_passwords(hashlist.path)
100109

101-
print_status("#{cracked[:cracked]} hashes were cracked!")
102110

103-
cracked[:users].each_pair do |k,v|
104-
if v[0] == "NO PASSWORD"
105-
passwd=""
106-
else
107-
passwd=v[0]
108-
end
109-
print_good("Host: #{v.last} User: #{k} Pass: #{passwd}")
110-
report_auth_info(
111-
:host => v.last,
112-
:port => 22,
113-
:sname => 'ssh',
114-
:user => k,
115-
:pass => passwd
116-
)
111+
print_status("#{cracked[:cracked]} hashes were cracked!")
112+
113+
cracked[:users].each_pair do |k,v|
114+
if v[0] == "NO PASSWORD"
115+
passwd=""
116+
else
117+
passwd=v[0]
117118
end
119+
print_good("Host: #{v.last} User: #{k} Pass: #{passwd}")
120+
report_auth_info(
121+
:host => v.last,
122+
:port => 22,
123+
:sname => 'ssh',
124+
:user => k,
125+
:pass => passwd
126+
)
118127
end
119-
120128
end
121-
122-
123-
124129
end

modules/auxiliary/client/smtp/emailer.rb

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,82 @@ def initialize(info = {})
4646
deregister_options('SUBJECT')
4747
end
4848

49+
def load_yaml_conf
50+
opts = {}
51+
52+
File.open(datastore['YAML_CONFIG'], "rb") do |f|
53+
yamlconf = YAML::load(f)
54+
55+
opts['to'] = yamlconf['to']
56+
opts['from'] = yamlconf['from']
57+
opts['subject'] = yamlconf['subject']
58+
opts['type'] = yamlconf['type']
59+
opts['msg_file'] = yamlconf['msg_file']
60+
opts['wait'] = yamlconf['wait']
61+
opts['add_name'] = yamlconf['add_name']
62+
opts['sig'] = yamlconf['sig']
63+
opts['sig_file'] = yamlconf['sig_file']
64+
opts['attachment'] = yamlconf['attachment']
65+
opts['attachment_file'] = yamlconf['attachment_file']
66+
opts['attachment_file_type'] = yamlconf['attachment_file_type']
67+
opts['attachment_file_name'] = yamlconf['attachment_file_name']
68+
69+
### payload options ###
70+
opts['make_payload'] = yamlconf['make_payload']
71+
opts['zip_payload'] = yamlconf['zip_payload']
72+
opts['msf_port'] = yamlconf['msf_port']
73+
opts['msf_ip'] = yamlconf['msf_ip']
74+
opts['msf_payload'] = yamlconf['msf_payload']
75+
opts['msf_filename'] = yamlconf['msf_filename']
76+
opts['msf_change_ext'] = yamlconf['msf_change_ext']
77+
opts['msf_payload_ext'] = yamlconf['msf_payload_ext']
78+
end
79+
80+
opts
81+
end
82+
83+
def load_file(fname)
84+
buf = ''
85+
File.open(fname, 'rb') do |f|
86+
buf = f.read
87+
end
88+
89+
buf
90+
end
91+
4992
def run
5093

51-
fileconf = File.open(datastore['YAML_CONFIG'], "rb")
52-
yamlconf = YAML::load(fileconf)
53-
54-
fileto = yamlconf['to']
55-
from = yamlconf['from']
56-
subject = yamlconf['subject']
57-
type = yamlconf['type']
58-
msg_file = yamlconf['msg_file']
59-
wait = yamlconf['wait']
60-
add_name = yamlconf['add_name']
61-
sig = yamlconf['sig']
62-
sig_file = yamlconf['sig_file']
63-
attachment = yamlconf['attachment']
64-
attachment_file = yamlconf['attachment_file']
94+
yamlconf = load_yaml_conf
95+
96+
fileto = yamlconf['to']
97+
from = yamlconf['from']
98+
subject = yamlconf['subject']
99+
type = yamlconf['type']
100+
msg_file = yamlconf['msg_file']
101+
wait = yamlconf['wait']
102+
add_name = yamlconf['add_name']
103+
sig = yamlconf['sig']
104+
sig_file = yamlconf['sig_file']
105+
attachment = yamlconf['attachment']
106+
attachment_file = yamlconf['attachment_file']
65107
attachment_file_type = yamlconf['attachment_file_type']
66108
attachment_file_name = yamlconf['attachment_file_name']
67109

68-
### payload options ###
69-
make_payload = yamlconf['make_payload']
70-
zip_payload = yamlconf['zip_payload']
71-
msf_port = yamlconf['msf_port']
72-
msf_ip = yamlconf['msf_ip']
73-
msf_payload = yamlconf['msf_payload']
74-
msf_filename = yamlconf['msf_filename']
75-
msf_change_ext = yamlconf['msf_change_ext']
76-
msf_payload_ext = yamlconf['msf_payload_ext']
77-
110+
make_payload = yamlconf['make_payload']
111+
zip_payload = yamlconf['zip_payload']
112+
msf_port = yamlconf['msf_port']
113+
msf_ip = yamlconf['msf_ip']
114+
msf_payload = yamlconf['msf_payload']
115+
msf_filename = yamlconf['msf_filename']
116+
msf_change_ext = yamlconf['msf_change_ext']
117+
msf_payload_ext = yamlconf['msf_payload_ext']
78118

79119
tmp = Dir.tmpdir
80120

81121
datastore['MAILFROM'] = from
82122

83-
msg = File.open(msg_file, 'rb').read
84-
email_sig = File.open(sig_file, 'rb').read
123+
msg = load_file(msg_file)
124+
email_sig = load_file(sig_file)
85125

86126
if (type !~ /text/i and type !~ /text\/html/i)
87127
print_error("YAML config: #{type}")
@@ -154,7 +194,7 @@ def run
154194
end
155195

156196
if sig
157-
data_sig = File.open(sig_file, 'rb').read
197+
data_sig = load_file(sig_file)
158198
email_msg_body = "#{email_msg_body}\n#{data_sig}"
159199
end
160200

@@ -172,7 +212,7 @@ def run
172212

173213
if attachment
174214
if attachment_file_name
175-
data_attachment = File.open(attachment_file, 'rb').read
215+
data_attachment = load_file(attachment_file)
176216
mime_msg.add_part(Rex::Text.encode_base64(data_attachment, "\r\n"), attachment_file_type, "base64", "attachment; filename=\"#{attachment_file_name}\"")
177217
end
178218
end

0 commit comments

Comments
 (0)