Improper Validation of Certificate with Host Mismatch

Incomplete Variant
Structure: Simple
Description

The product communicates with a host that provides a certificate, but the product does not properly ensure that the certificate is actually associated with that host.

Extended Description

Even if a certificate is well-formed, signed, and follows the chain of trust, it may simply be a valid certificate for a different site than the site that the product is interacting with. If the certificate's host-specific data is not properly checked - such as the Common Name (CN) in the Subject or the Subject Alternative Name (SAN) extension of an X.509 certificate - it may be possible for a redirection or spoofing attack to allow a malicious host with a valid certificate to provide data, impersonating a trusted host. In order to ensure data integrity, the certificate must be valid and it must pertain to the site that is being accessed. Even if the product attempts to check the hostname, it is still possible to incorrectly check the hostname. For example, attackers could create a certificate with a name that begins with a trusted name followed by a NUL byte, which could cause some string-based comparisons to only examine the portion that contains the trusted name. This weakness can occur even when the product uses Certificate Pinning, if the product does not verify the hostname at the time a certificate is pinned.

Common Consequences 2
Scope: Access Control

Impact: Gain Privileges or Assume Identity

The data read from the system vouched for by the certificate may not be from the expected system.

Scope: AuthenticationOther

Impact: Other

Trust afforded to the system in question - based on the malicious certificate - may allow for spoofing or redirection attacks.

Detection Methods 3
Automated Static AnalysisHigh
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Dynamic Analysis with Manual Results Interpretation
Set up an untrusted endpoint (e.g. a server) with which the product will connect. Create a test certificate that uses an invalid hostname but is signed by a trusted CA and provide this certificate from the untrusted endpoint. If the product performs any operations instead of disconnecting and reporting an error, then this indicates that the hostname is not being checked and the test certificate has been accepted.
Black Box
When Certificate Pinning is being used in a mobile application, consider using a tool such as Spinner [REF-955]. This methodology might be extensible to other technologies.
Potential Mitigations 2
Phase: Architecture and Design
Fully check the hostname of the certificate and provide the user with adequate information about the nature of the problem and how to proceed.
Phase: Implementation
If certificate pinning is being used, ensure that all relevant properties of the certificate are fully validated before the certificate is pinned, including the hostname.
Demonstrative Examples 1

ID : DX-122

The following OpenSSL code obtains a certificate and verifies it.

Code Example:

Bad
C
c

// do secret things* }

Even though the "verify" step returns X509_V_OK, this step does not include checking the Common Name against the name of the host. That is, there is no guarantee that the certificate is for the desired host. The SSL connection could have been established with a malicious host that provided a valid certificate.
Observed Examples 20
CVE-2012-5810Mobile banking application does not verify hostname, leading to financial loss.
CVE-2012-5811Mobile application for printing documents does not verify hostname, allowing attackers to read sensitive documents.
CVE-2012-5807Software for electronic checking does not verify hostname, leading to financial loss.
CVE-2012-3446Cloud-support library written in Python uses incorrect regular expression when matching hostname.
CVE-2009-2408Web browser does not correctly handle '\0' character (NUL) in Common Name, allowing spoofing of https sites.
CVE-2012-0867Database program truncates the Common Name during hostname verification, allowing spoofing.
CVE-2010-2074Incorrect handling of '\0' character (NUL) in hostname verification allows spoofing.
CVE-2009-4565Mail server's incorrect handling of '\0' character (NUL) in hostname verification allows spoofing.
CVE-2009-3767LDAP server's incorrect handling of '\0' character (NUL) in hostname verification allows spoofing.
CVE-2012-5806Payment processing module does not verify hostname when connecting to PayPal using PHP fsockopen function.
CVE-2012-2993Smartphone device does not verify hostname, allowing spoofing of mail services.
CVE-2012-5804E-commerce module does not verify hostname when connecting to payment site.
CVE-2012-5824Chat application does not validate hostname, leading to loss of privacy.
CVE-2012-5822Application uses third-party library that does not validate hostname.
CVE-2012-5819Cloud storage management application does not validate hostname.
CVE-2012-5817Java library uses JSSE SSLSocket and SSLEngine classes, which do not verify the hostname.
CVE-2012-5784SOAP platform does not verify the hostname.
CVE-2012-5782PHP library for payments does not verify the hostname.
CVE-2012-5780Merchant SDK for payments does not verify the hostname.
CVE-2003-0355Web browser does not validate Common Name, allowing spoofing of https sites.
References 7
The CLASP Application Security Process
Secure Software, Inc.
2005
ID: REF-18
The Most Dangerous Code in the World: Validating SSL Certificates in Non-Browser Software
Martin Georgiev, Subodh Iyengar, Suman Jana, Rishita Anubhai, Dan Boneh, and Vitaly Shmatikov
25-10-2012
ID: REF-245
Why Eve and Mallory Love Android: An Analysis of Android SSL (In)Security
Sascha Fahl, Marian Harbach, Thomas Muders, Matthew Smith and Lars Baumgärtner, Bernd Freisleben
16-10-2012
ID: REF-243
Secure programming with the OpenSSL API, Part 2: Secure handshake
Kenneth Ballard
03-05-2005
ID: REF-249
An Introduction to OpenSSL Programming (Part I)
Eric Rescorla
05-10-2001
ID: REF-250
24 Deadly Sins of Software Security
Michael Howard, David LeBlanc, and John Viega
McGraw-Hill
2010
ID: REF-44
Spinner: Semi-Automatic Detection of Pinning without Hostname Verification
Chris McMahon Stone, Tom Chothia, and Flavio D. Garcia
ID: REF-955
Likelihood of Exploit

High

Applicable Platforms
Languages:
Not Language-Specific : Undetermined
Technologies:
Mobile : UndeterminedNot Technology-Specific : Undetermined
Modes of Introduction
Implementation
Implementation
Taxonomy Mapping
  • CLASP