Module: Msf::Exploit::Remote::HTTP::Zimbra
- Includes:
- Msf::Exploit::Remote::HttpClient
- Defined in:
- lib/msf/core/exploit/remote/http/zimbra.rb
Overview
Shared HTTP and SOAP operations for Zimbra Collaboration modules.
Network operations return a Hash whose :status is :success, :unreachable, :bad_config, :malformed, :soap_fault, :unexpected, :auth_failed, :authentication_incomplete, or :not_found. Failures contain :reason. :http_code is always an HTTP status and :fault_code is always a Zimbra error code. zimbra_soap_request success additionally contains :node; higher-level success returns only documented fields.
Constant Summary collapse
- SOAP_NAMESPACE =
'http://www.w3.org/2003/05/soap-envelope'- CONTEXT_NAMESPACE =
'urn:zimbra'- ACCOUNT_NAMESPACE =
'urn:zimbraAccount'- ADMIN_NAMESPACE =
'urn:zimbraAdmin'- ACCOUNT_SOAP_PATH =
%w[service soap].freeze
- ADMIN_SOAP_PATH =
%w[service admin soap].freeze
- ACCOUNT_AUTH_TOKEN_COOKIE =
'ZM_AUTH_TOKEN'- ACCOUNT_NOT_FOUND_CODE =
'account.NO_SUCH_ACCOUNT'- AUTHENTICATION_FAILURE_CODES =
%w[ account.AUTH_FAILED account.NO_SUCH_ACCOUNT service.PERM_DENIED ].freeze
- INCOMPLETE_AUTHENTICATION_CODES =
%w[ account.CHANGE_PASSWORD account.TWO_FACTOR_AUTH_REQUIRED account.TWO_FACTOR_SETUP_REQUIRED ].freeze
- XML_TRUE_VALUES =
%w[1 true].freeze
- XML_FALSE_VALUES =
%w[0 false].freeze
- XML_10_CHARACTER_PATTERN =
/\A[\u0009\u000a\u000d\u0020-\ud7ff\ue000-\ufffd\u{10000}-\u{10ffff}]*\z/- ACCOUNT_NAME_PATTERN =
/\A[^@\s]+@[^@\s]+\z/- LOGIN_NAME_PATTERN =
/\A[^@\s]+(?:@[^@\s]+)?\z/- HOST_LABEL_PATTERN =
/\A[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\z/- ACCOUNT_UUID_PATTERN =
/\A[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}\z/i- AUTH_TOKEN_PATTERN =
/\A[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]+\z/- VERSION_PATTERN =
/\A\d+\.\d+\.\d+(?=$|[\s._+~-])/
Instance Attribute Summary
Attributes included from Msf::Exploit::Remote::HttpClient
Instance Method Summary collapse
-
#initialize(info = {}) ⇒ void
Registers the common Zimbra application base path.
-
#zimbra_account_info(auth_token, account_name) ⇒ Hash
Resolves a local account by name.
-
#zimbra_account_name_error(value, label) ⇒ String?
Validates a Zimbra account name before another operation uses it.
-
#zimbra_authenticate(username, password, service: :account, port: nil, ssl: nil, timeout: nil) ⇒ Hash
Authenticates to the Zimbra account or administrator SOAP service.
-
#zimbra_get_info(auth_token) ⇒ Hash
Retrieves the authenticated account identity and server version.
-
#zimbra_login_name_error(value, label) ⇒ String?
Validates a Zimbra authentication name.
-
#zimbra_soap_envelope(auth_token: nil) {|xml| ... } ⇒ String
Builds a SOAP 1.2 envelope, adding a Zimbra authentication context when requested.
-
#zimbra_soap_request(document, expected_response:, namespace:, service: :account, port: nil, ssl: nil, timeout: nil, auth_token: nil) ⇒ Hash
Sends a Zimbra account or administrator SOAP request and validates its response.
-
#zimbra_xml_string(value) ⇒ String?
Normalizes strings permitted by XML 1.0 Fifth Edition section 2.2.
Methods included from Msf::Exploit::Remote::HttpClient
#basic_auth, #cleanup, #configure_http_login_scanner, #connect, #connect_ws, #deregister_http_client_options, #disconnect, #download, #full_uri, #handler, #http_fingerprint, #lookup_http_fingerprints, #normalize_uri, #path_from_uri, #peer, #proxies, #reconfig_redirect_opts!, #request_opts_from_url, #request_url, #rhost, #rport, #send_request_cgi, #send_request_cgi!, #send_request_raw, #service_details, #setup, #ssl, #ssl_version, #sslkeylogfile, #strip_tags, #target_uri, #validate_fingerprint, #vhost
Methods included from CertificateTrace
#certificate_csr_trace, #certificate_peer_cert_trace, #certificate_trace, #certificate_trace_enabled?
Methods included from Kerberos::ServiceAuthenticator::Options
#kerberos_auth_options, #kerberos_clock_skew_seconds
Methods included from Kerberos::Ticket::Storage
#kerberos_storage_options, #kerberos_ticket_storage, store_ccache
Methods included from Auxiliary::LoginScanner
Methods included from Auxiliary::Report
#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot
Methods included from Metasploit::Framework::Require
optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines
Instance Method Details
#initialize(info = {}) ⇒ void
Registers the common Zimbra application base path.
51 52 53 54 55 56 57 58 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 51 def initialize(info = {}) super ( [Msf::OptString.new('TARGETURI', [true, 'The base path of the Zimbra installation', '/'])], Msf::Exploit::Remote::HTTP::Zimbra ) end |
#zimbra_account_info(auth_token, account_name) ⇒ Hash
Resolves a local account by name.
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 298 def zimbra_account_info(auth_token, account_name) input_error = zimbra_auth_token_error(auth_token) || zimbra_account_name_error(account_name, 'account name') return { status: :bad_config, reason: input_error } if input_error auth_token = zimbra_xml_string(auth_token) account_name = zimbra_xml_string(account_name) document = zimbra_soap_envelope(auth_token: auth_token) do |xml| xml.GetAccountInfoRequest('xmlns' => ACCOUNT_NAMESPACE) do xml.account(account_name, 'by' => 'name') end end result = zimbra_soap_request(document, expected_response: 'GetAccountInfoResponse', namespace: ACCOUNT_NAMESPACE, auth_token: auth_token) if result[:status] == :soap_fault && result[:fault_code] == ACCOUNT_NOT_FOUND_CODE return result.merge(status: :not_found, reason: 'The requested Zimbra account could not be resolved') end return result unless result[:status] == :success id_nodes = result[:node].xpath('./zimbra:attr[@name="zimbraId"]', 'zimbra' => ACCOUNT_NAMESPACE) name_nodes = result[:node].xpath('./zimbra:name', 'zimbra' => ACCOUNT_NAMESPACE) id = id_nodes.first&.text name = name_nodes.first&.text unless id_nodes.one? && zimbra_account_uuid?(id) return zimbra_high_level_result(result, status: :malformed, reason: 'GetAccountInfoResponse omitted a valid account id') end unless name_nodes.one? && zimbra_account_name?(name) return zimbra_high_level_result(result, status: :malformed, reason: 'GetAccountInfoResponse omitted a valid account name') end host_nodes = result[:node].xpath('./zimbra:attr[@name="zimbraMailHost"]', 'zimbra' => ACCOUNT_NAMESPACE) mail_host = zimbra_mail_host(host_nodes.first&.text) if host_nodes.length > 1 || (host_nodes.one? && !mail_host) return zimbra_high_level_result(result, status: :malformed, reason: 'GetAccountInfoResponse contained an invalid mailbox host') end zimbra_high_level_result(result, status: :success, id: id, name: name, mail_host: mail_host) end |
#zimbra_account_name_error(value, label) ⇒ String?
Validates a Zimbra account name before another operation uses it.
341 342 343 344 345 346 347 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 341 def zimbra_account_name_error(value, label) reason = zimbra_xml_string_error(value, label) return reason if reason return "#{label} must be a single-line account address" unless zimbra_account_name?(value) nil end |
#zimbra_authenticate(username, password, service: :account, port: nil, ssl: nil, timeout: nil) ⇒ Hash
Authenticates to the Zimbra account or administrator SOAP service.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 196 def zimbra_authenticate(username, password, service: :account, port: nil, ssl: nil, timeout: nil) input_error = zimbra_login_name_error(username, 'username') || zimbra_xml_string_error(password, 'password') return { status: :bad_config, reason: input_error } if input_error username = zimbra_xml_string(username) password = zimbra_xml_string(password) endpoint = zimbra_soap_endpoint(service) document = zimbra_soap_envelope do |xml| attributes = { 'xmlns' => endpoint[:namespace] } attributes['persistAuthTokenCookie'] = '0' if service == :account xml.AuthRequest(attributes) do if service == :account xml.account(username, 'by' => 'name') else xml.name(username) end xml.password(password) end end result = zimbra_soap_request( document, expected_response: 'AuthResponse', namespace: endpoint[:namespace], service: service, port: port, ssl: ssl, timeout: timeout ) if result[:status] == :soap_fault return result.merge(status: :auth_failed) if AUTHENTICATION_FAILURE_CODES.include?(result[:fault_code]) if INCOMPLETE_AUTHENTICATION_CODES.include?(result[:fault_code]) return result.merge(status: :authentication_incomplete) end end return result unless result[:status] == :success token_nodes = result[:node].xpath('./zimbra:authToken', 'zimbra' => endpoint[:namespace]) token = token_nodes.first&.text unless token_nodes.one? && zimbra_auth_token?(token) return zimbra_high_level_result(result, status: :malformed, reason: 'AuthResponse omitted a valid authToken') end two_factor_required = zimbra_xml_boolean( result[:node].xpath('./zimbra:twoFactorAuthRequired', 'zimbra' => endpoint[:namespace]) ) password_reset_required = zimbra_xml_boolean( result[:node].xpath('./zimbra:resetPassword', 'zimbra' => endpoint[:namespace]) ) if two_factor_required == :invalid || password_reset_required == :invalid return zimbra_high_level_result(result, status: :malformed, reason: 'AuthResponse contained an invalid authentication requirement') end if two_factor_required return zimbra_high_level_result(result, status: :authentication_incomplete, reason: 'Zimbra requires a second authentication factor') end if password_reset_required return zimbra_high_level_result(result, status: :authentication_incomplete, reason: 'Zimbra requires a password reset before authentication completes') end zimbra_high_level_result(result, status: :success, token: token) end |
#zimbra_get_info(auth_token) ⇒ Hash
Retrieves the authenticated account identity and server version.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 262 def zimbra_get_info(auth_token) input_error = zimbra_auth_token_error(auth_token) return { status: :bad_config, reason: input_error } if input_error auth_token = zimbra_xml_string(auth_token) document = zimbra_soap_envelope(auth_token: auth_token) do |xml| xml.GetInfoRequest('xmlns' => ACCOUNT_NAMESPACE, 'sections' => 'mbox') end result = zimbra_soap_request(document, expected_response: 'GetInfoResponse', namespace: ACCOUNT_NAMESPACE, auth_token: auth_token) return result unless result[:status] == :success name_nodes = result[:node].xpath('./zimbra:name', 'zimbra' => ACCOUNT_NAMESPACE) name = name_nodes.first&.text unless name_nodes.one? && zimbra_account_name?(name) return zimbra_high_level_result(result, status: :malformed, reason: 'GetInfoResponse omitted a valid account name') end id_nodes = result[:node].xpath('./zimbra:id', 'zimbra' => ACCOUNT_NAMESPACE) id = id_nodes.first&.text if id_nodes.length > 1 || (id_nodes.one? && !zimbra_account_uuid?(id)) return zimbra_high_level_result(result, status: :malformed, reason: 'GetInfoResponse contained an invalid account id') end version_nodes = result[:node].xpath('./zimbra:version', 'zimbra' => ACCOUNT_NAMESPACE) version_text = version_nodes.one? ? version_nodes.first.text&.strip : nil version_match = version_text&.match(VERSION_PATTERN)&.[](0) version = Rex::Version.new(version_match) if version_match zimbra_high_level_result(result, status: :success, id: id, name: name, version: version) end |
#zimbra_login_name_error(value, label) ⇒ String?
Validates a Zimbra authentication name.
354 355 356 357 358 359 360 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 354 def zimbra_login_name_error(value, label) reason = zimbra_xml_string_error(value, label) return reason if reason return "#{label} must be a single-line login name or account address" unless zimbra_xml_string(value).match?(LOGIN_NAME_PATTERN) nil end |
#zimbra_soap_envelope(auth_token: nil) {|xml| ... } ⇒ String
Builds a SOAP 1.2 envelope, adding a Zimbra authentication context when requested.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 79 def zimbra_soap_envelope(auth_token: nil) if auth_token && (reason = zimbra_auth_token_error(auth_token)) raise ArgumentError, reason end auth_token = zimbra_xml_string(auth_token) if auth_token Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml['soap'].Envelope('xmlns:soap' => SOAP_NAMESPACE) do if auth_token.present? xml['soap'].Header do # Nokogiri::XML::Builder reserves context, so invoke its element fallback explicitly. xml.send(:method_missing, 'z:context', { 'xmlns:z' => CONTEXT_NAMESPACE }) do xml['z'].authToken(auth_token) end end end xml['soap'].Body { yield xml } end end.to_xml end |
#zimbra_soap_request(document, expected_response:, namespace:, service: :account, port: nil, ssl: nil, timeout: nil, auth_token: nil) ⇒ Hash
Sends a Zimbra account or administrator SOAP request and validates its response.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 113 def zimbra_soap_request(document, expected_response:, namespace:, service: :account, port: nil, ssl: nil, timeout: nil, auth_token: nil) endpoint = zimbra_soap_endpoint(service) token_error = zimbra_auth_token_error(auth_token) if auth_token return { status: :bad_config, reason: token_error } if token_error auth_token = zimbra_xml_string(auth_token) if auth_token request = { 'method' => 'POST', 'uri' => normalize_uri(target_uri.path, *endpoint[:path]), 'ctype' => 'application/soap+xml; charset=utf-8', 'data' => document } request['rport'] = port if port request['SSL'] = ssl unless ssl.nil? request['cookie'] = service == :account && auth_token ? "#{ACCOUNT_AUTH_TOKEN_COOKIE}=#{auth_token}" : '' response = timeout ? send_request_cgi(request, timeout) : send_request_cgi(request) return { status: :unreachable, reason: "No response from #{endpoint[:name]}" } unless response if [404, 405].include?(response.code) return { status: :bad_config, reason: "HTTP #{response.code} did not expose #{endpoint[:name]} at TARGETURI", http_code: response.code } end parsed = zimbra_xml_response(response, endpoint[:name]) return parsed unless parsed[:status] == :success faults = parsed[:document].xpath('/soap:Envelope/soap:Body/soap:Fault', 'soap' => SOAP_NAMESPACE) if faults.length > 1 return { status: :malformed, reason: "#{endpoint[:name]} returned multiple Fault elements", http_code: response.code } end fault = faults.first if fault fault_codes = fault.xpath('./soap:Detail/zimbra:Error/zimbra:Code', 'soap' => SOAP_NAMESPACE, 'zimbra' => CONTEXT_NAMESPACE) if fault_codes.length > 1 return { status: :malformed, reason: "#{endpoint[:name]} returned multiple Fault codes", http_code: response.code } end fault_code = fault_codes.first&.text&.strip reason = if fault_code.present? "#{endpoint[:name]} fault #{fault_code}" else "#{endpoint[:name]} returned a Fault without a Zimbra error code" end return { status: :soap_fault, reason: reason, http_code: response.code, fault_code: fault_code } end unless response.code == 200 return { status: :unexpected, reason: "#{endpoint[:name]} returned HTTP #{response.code} without a Fault", http_code: response.code } end nodes = parsed[:document].xpath( "/soap:Envelope/soap:Body/zimbra:#{expected_response}", 'soap' => SOAP_NAMESPACE, 'zimbra' => namespace ) if nodes.one? return { status: :success, node: nodes.first, http_code: response.code } end if nodes.length > 1 return { status: :malformed, reason: "HTTP #{response.code} returned multiple #{expected_response} elements", http_code: response.code } end { status: :unexpected, reason: "HTTP #{response.code} omitted #{expected_response}", http_code: response.code } end |
#zimbra_xml_string(value) ⇒ String?
Normalizes strings permitted by XML 1.0 Fifth Edition section 2.2.
64 65 66 67 68 69 70 71 |
# File 'lib/msf/core/exploit/remote/http/zimbra.rb', line 64 def zimbra_xml_string(value) return unless value.is_a?(String) && value.valid_encoding? value = value.encode(::Encoding::UTF_8) value if value.match?(XML_10_CHARACTER_PATTERN) rescue ::Encoding::ConverterNotFoundError, ::Encoding::InvalidByteSequenceError, ::Encoding::UndefinedConversionError nil end |