CVE-2026-103600 Bouncy Castle bc-csharp ASN.1 解析器递归拒绝服务漏洞
影响远程未认证攻击者可触发栈溢出导致进程崩溃,造成拒绝服务
Bouncy Castle bc-csharp 的 ASN.1 解析器(Asn1InputStream、Asn1StreamParser)在解析深度嵌套的构造类型元素时采用无深度限制的递归调用。攻击者只需构造约 2000 层嵌套(约 8KB DER)的 ASN.1 数据,即可耗尽线程栈并触发 .NET 无法捕获的 StackOverflowException,导致整个进程终止。
影响范围
Legion of the Bouncy Castle Inc. bc-csharp 2.7.0 之前的版本。
漏洞详情
该漏洞属于不受控递归导致的拒绝服务(CWE-674)。解析器对 SEQUENCE 嵌套 SEQUENCE 等构造元素逐层递归解析,未设置最大嵌套深度限制,定长 DER 或不定长 BER 编码均可触发。在默认 1.5MB 栈的 .NET 主线程上约 2000 层即崩溃;栈更大时解析时间随深度呈平方级增长,64KB 输入可消耗约 9 秒 CPU。
利用条件与风险
利用无需认证,任何解析不可信 ASN.1 数据的路径均受影响,包括 X.509 证书与 CRL、CMS/PKCS#7、PKCS#8/PKCS#12、OCSP 及 TLS Certificate 消息。实战中可被用于远程拒绝服务,风险取决于暴露面。
修复建议
升级至 bc-csharp 2.7.0 或更高版本。临时缓解措施包括在解析前限制输入大小与嵌套深度、避免在主线程解析不可信 ASN.1 数据,具体官方方案请以厂商公告为准。
Uncontrolled recursion in the ASN.1 parser (Asn1InputStream, Asn1StreamParser) in Legion of the Bouncy Castle Inc. bc-csharp before 2.7.0 allows a remote unauthenticated attacker to cause a denial of service via a crafted ASN.1 encoding of deeply nested constructed elements (for example SEQUENCE inside SEQUENCE, in definite-length DER or indefinite-length BER form), because each nesting level is parsed by a further recursive call with no bound on depth. About 2,000 levels (8 KB of DER) are enough to exhaust a 1.5 MB thread stack, the .NET main-thread default on Windows, and raise a StackOverflowException, which .NET cannot catch and which terminates the whole process; on threads with larger stacks, parse time instead grows quadratically with depth (about 9 seconds of CPU for a 64 KB input). Any path that parses untrusted ASN.1 is exposed, including X.509 certificates and CRLs, CMS/PKCS#7, PKCS#8/PKCS#12, OCSP and TLS Certificate messages.