GHSL-2020-026: Person in the middle attacks with lua-openssl
The lua-openssl library incorrectly converted the integer return values of X509 certificate validation functions (check_host, check_email, check_ip_asc) to booleans, so negative error codes like -1 were treated as true. An attacker could supply a malformed certificate that fails to decode, and the application would accept it as valid, enabling person-in-the-middle attacks.
Originally disclosed on GitHub Security Lab
Several security issues have been found in the way X509 certificate validation functions are exposed to LUA via the checkhost function and others. Clients using said functions in lua-openssl are exposed to person-in-the-middle attacks.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The library passed the integer return value of X509_check_host, X509_check_email, and X509_check_ip_asc directly to a boolean conversion, so negative error codes were interpreted as true.
Impact
These issues may lead to person-in-the-middle attacks in which an attacker can supplant the identity of the endpoint to which the client is connecting.
What the attacker needed
Attacker can supply a malformed certificate; application uses lua-openssl check functions
The fix
The three affected functions should be rewritten to return true only when the corresponding OpenSSL function returns 1, and false otherwise; the text states a patch was provided and verified.
How it was found
- Generate a specially crafted X509 certificate with an invalid hostname using the provided C++ program.
- Use the LUA proof of concept to read the invalid certificate and call check_host against github.com.
- Observe that the check returns true despite the certificate being invalid.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program checks if a certificate matches a hostname, the underlying function returns a number: 1 for a match, 0 for no match, and negative numbers for errors. The lua-openssl library turned that number into a true/false value, but in many programming languages any non-zero number (including negative ones) becomes true. So an error (-1) was treated as a successful match, letting an attacker use a broken certificate to impersonate a website.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.