# Attacker sets up fake server with self-signed cert
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
# Start fake server
python -m http.server 443 --bind 0.0.0.0
# Application connects to attacker's server thinking it's real
# Traffic decrypted by attacker
Certificate issued for: evil.com
Request to: example.com
Check: Only verifies certificate validity, not hostname
Result: Connection accepted even though hostname doesn't match!
Attacker obtains certificate for attacker.com
User tries to connect to example.com
Attacker intercepts connection
Sends certificate for attacker.com
Application checks: "Is certificate valid?" → Yes
Application doesn't check: "Is this the right domain?" → No
Connection established to attacker's server
# Certificate is valid but for wrong domain
openssl x509 -in cert.pem -text -noout | grep "Subject:"
# Subject: CN = attacker.com
# But application connects to example.com
# Validation only checks expiration/signature, not CN
Certificate: *.evil.com (matches any subdomain of evil.com)
User connects to: example.com
Attacker claims to be: evil.com.example.com (wrong match)
Result: Connection fails correctly
But if: example.com.evil.com, connection might succeed
# Vulnerable code
context = ssl.create_default_context()
context.check_hostname = False # WRONG!
context.verify_mode = ssl.CERT_NONE # WRONG!
# Now accepts any certificate, self-signed or invalid