|
| 1 | +require 'metasploit/framework/login_scanner/http' |
| 2 | + |
| 3 | +module Metasploit |
| 4 | + module Framework |
| 5 | + module LoginScanner |
| 6 | + # Ivanti Login Scanner supporting |
| 7 | + # - User Login |
| 8 | + # - Admin Login |
| 9 | + class Ivanti < HTTP |
| 10 | + |
| 11 | + def initialize(scanner_config, admin) |
| 12 | + @admin = admin |
| 13 | + super(scanner_config) |
| 14 | + end |
| 15 | + |
| 16 | + def create_admin_request(username, password, token, protocol, peer) |
| 17 | + { |
| 18 | + 'method' => 'POST', |
| 19 | + 'uri' => normalize_uri('/dana-na/auth/url_admin/login.cgi'), |
| 20 | + 'ctype' => 'application/x-www-form-urlencoded', |
| 21 | + 'headers' => |
| 22 | + { |
| 23 | + 'Origin' => "#{protocol}://#{peer}", |
| 24 | + 'Referer' => "#{protocol}://#{peer}/dana-na/auth/url_admin/welcome.cgi" |
| 25 | + }, |
| 26 | + 'vars_post' => { |
| 27 | + tz_offset: '60', |
| 28 | + xsauth_token: token, |
| 29 | + username: username, |
| 30 | + password: password, |
| 31 | + realm: 'Admin+Users', |
| 32 | + btnSubmit: 'Sign+In' |
| 33 | + |
| 34 | + }, |
| 35 | + 'encode_params' => false |
| 36 | + } |
| 37 | + end |
| 38 | + |
| 39 | + def do_admin_logout(cookies) |
| 40 | + admin_page_res = send_request({ 'method' => 'GET', 'uri' => normalize_uri('/dana-admin/misc/admin.cgi?'), 'cookie' => cookies }) |
| 41 | + admin_page_s = admin_page_res.to_s |
| 42 | + re = /xsauth=[a-z0-9]{32}/ |
| 43 | + xsauth = re.match(admin_page_s) |
| 44 | + |
| 45 | + return nil if xsauth.nil? |
| 46 | + |
| 47 | + send_request({ 'method' => 'GET', 'uri' => normalize_uri('/dana-na/auth/logout.cgi?' + xsauth[0]), 'cookie' => cookies }) |
| 48 | + end |
| 49 | + |
| 50 | + def get_token |
| 51 | + res = send_request({ |
| 52 | + 'uri' => normalize_uri('/dana-na/auth/url_admin/welcome.cgi') |
| 53 | + }) |
| 54 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: 'Unable to connect to the Ivanti service' } if res.nil? |
| 55 | + |
| 56 | + html_document = res.get_html_document |
| 57 | + html_document.xpath('//input[@id="xsauth_token"]/@value')&.text |
| 58 | + end |
| 59 | + |
| 60 | + def do_admin_login(username, password) |
| 61 | + token = get_token |
| 62 | + |
| 63 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: 'Unable to connect to the Ivanti service' } if token.blank? |
| 64 | + |
| 65 | + protocol = ssl ? 'https' : 'http' |
| 66 | + peer = "#{host}:#{port}" |
| 67 | + admin_req = create_admin_request(username, password, token, protocol, peer) |
| 68 | + begin |
| 69 | + res = send_request(admin_req) |
| 70 | + rescue ::Rex::ConnectionError, ::Rex::ConnectionProxyError, ::Errno::ECONNRESET, ::Errno::EINTR, ::Rex::TimeoutError, ::Timeout::Error, ::EOFError => e |
| 71 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: e } |
| 72 | + end |
| 73 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: 'Unable to connect to the Ivanti service' } if res.nil? |
| 74 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: "Received an unexpected status code: #{res.code}" } if res.code != 302 |
| 75 | + |
| 76 | + return { status: ::Metasploit::Model::Login::Status::SUCCESSFUL, proof: res.to_s } if res.headers['location'] == '/dana-na/auth/url_admin/welcome.cgi?p=admin%2Dconfirm' |
| 77 | + |
| 78 | + if res.headers['location'] == '/dana-admin/misc/admin.cgi' |
| 79 | + do_admin_logout(res.get_cookies) |
| 80 | + return { status: ::Metasploit::Model::Login::Status::SUCCESSFUL, proof: res.to_s } |
| 81 | + end |
| 82 | + |
| 83 | + return { status: ::Metasploit::Model::Login::Status::INCORRECT, proof: res.to_s } |
| 84 | + end |
| 85 | + |
| 86 | + def create_user_request(username, password, protocol, peer) |
| 87 | + { |
| 88 | + 'method' => 'POST', |
| 89 | + 'uri' => normalize_uri('/dana-na/auth/url_default/login.cgi'), |
| 90 | + 'ctype' => 'application/x-www-form-urlencoded', |
| 91 | + 'headers' => |
| 92 | + { |
| 93 | + 'Origin' => "#{protocol}://#{peer}", |
| 94 | + 'Referer' => "#{protocol}://#{peer}/dana-na/auth/url_default/welcome.cgi" |
| 95 | + }, |
| 96 | + 'vars_post' => |
| 97 | + { |
| 98 | + tz_offset: '', |
| 99 | + win11: '', |
| 100 | + clientMAC: '', |
| 101 | + username: username, |
| 102 | + password: password, |
| 103 | + realm: 'Users', |
| 104 | + btnSubmit: 'Sign+In' |
| 105 | + }, |
| 106 | + 'encode_params' => false |
| 107 | + } |
| 108 | + end |
| 109 | + |
| 110 | + def do_logout(cookies) |
| 111 | + send_request({ 'uri' => normalize_uri('/dana-na/auth/logout.cgi?delivery=psal'), 'cookie' => cookies }) |
| 112 | + end |
| 113 | + |
| 114 | + def do_login(username, password) |
| 115 | + protocol = ssl ? 'https' : 'http' |
| 116 | + peer = "#{host}:#{port}" |
| 117 | + user_req = create_user_request(username, password, protocol, peer) |
| 118 | + begin |
| 119 | + res = send_request(user_req) |
| 120 | + rescue ::Rex::ConnectionError, ::Rex::ConnectionProxyError, ::Errno::ECONNRESET, ::Errno::EINTR, ::Rex::TimeoutError, ::Timeout::Error, ::EOFError => e |
| 121 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: e } |
| 122 | + end |
| 123 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: 'Unable to connect to the Ivanti service' } if res.nil? |
| 124 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: "Received an unexpected status code: #{res.code}" } if res.code != 302 |
| 125 | + return { status: ::Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: 'Unexpected response' } if res.blank? |
| 126 | + |
| 127 | + if res.headers['location'] == '/dana-na/auth/url_default/welcome.cgi?p=ip%2Dblocked' |
| 128 | + sleep(2 * 60) # 2 minutes |
| 129 | + res = send_request(user_req) |
| 130 | + end |
| 131 | + |
| 132 | + return { status: ::Metasploit::Model::Login::Status::SUCCESSFUL, proof: res.to_s } if res.headers['location'] == '/dana-na/auth/url_default/welcome.cgi?p=user%2Dconfirm' |
| 133 | + |
| 134 | + if res.headers['location'] == '/dana/home/starter0.cgi?check=yes' |
| 135 | + do_logout(res.get_cookies) |
| 136 | + return { status: ::Metasploit::Model::Login::Status::SUCCESSFUL, proof: res.to_s } |
| 137 | + else |
| 138 | + return { status: ::Metasploit::Model::Login::Status::INCORRECT, proof: res.to_s } |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + # Attempts to login to the server. |
| 143 | + # |
| 144 | + # @param [Metasploit::Framework::Credential] credential The credential information. |
| 145 | + # @return [Result] A Result object indicating success or failure |
| 146 | + def attempt_login(credential) |
| 147 | + # focus on creating Result object, pass it to #login routine and return Result object |
| 148 | + result_options = { |
| 149 | + credential: credential, |
| 150 | + host: @host, |
| 151 | + port: @port, |
| 152 | + protocol: 'tcp', |
| 153 | + service_name: 'ivanti' |
| 154 | + } |
| 155 | + |
| 156 | + if @admin |
| 157 | + login_result = do_admin_login(credential.public, credential.private) |
| 158 | + else |
| 159 | + login_result = do_login(credential.public, credential.private) |
| 160 | + end |
| 161 | + |
| 162 | + result_options.merge!(login_result) |
| 163 | + Result.new(result_options) |
| 164 | + end |
| 165 | + |
| 166 | + end |
| 167 | + end |
| 168 | + end |
| 169 | +end |
0 commit comments