如何验证参考组件以检查其是否被篡改?
这个问题是关于验证程序集以检查它是否被恶意活动篡改。 创建程序集时,会生成元数据。元数据包括类型定义表、类型引用表和清单表等表。引用表包含每个程序集引用的条目,并且该条目包括引用的程序集、其公钥和散列值。清单包含每个程序集引用的程序集的详细信息,其中包括程序集名称、其公钥和哈希算法。我还了解到,在运行时加载程序集时,它会使用嵌入在清单中的公钥生成程序集的数字签名,并将其与已嵌入程序集中的数字签名进行比较。如果数字签名匹配,则加载。 我的问题如下。
- 程序集引用元数据表包括哈希。还提到它没有被使用。那么它的目的是什么呢?
- 每次加载程序集时都会进行程序集验证吗?
- 如果不是强类型会发生什么?
This question is about verifying the assembly to check whether it is tampered for malicious activity.
When an assembly is created, metadata is generated. Metadata includes tables like type definition tables, type reference tables and manifest tables. Reference tables contain an entry for each assembly reference and the entry includes referenced assembly, its public key and a hash value. The manifest includes details of assembly referenced for each assembly and it includes the assembly name, its public key and Hashing algorithm. I also understand that during runtime when the assembly is loaded, it generates digital signature of the assembly with the public key embedded in the manifest and compares it with the digital signature already embedded in the assembly. If the digital signature matches then it loads.
My questions are below.
- The Assembly Reference metadata table include a HASH. It is also mentioned that it is not used. Then what is its purpose?
- Does this assembly verification happen every time the assembly loads?
- What happens if it is not strongly typed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,
但是...
根据我对 .Net 4.0 程序集的私人调查 - 哈希和在程序集绑定阶段确实被忽略,即使程序集是由加密密钥签名的,因此具有强名称。
一段时间后,我意识到 强名称绕过功能会导致此行为。
因此,您需要“在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework 项下创建一个值为 0、名为 AllowStrongNameBypass”的 DWORD 条目”,以启用强名称 (+hashsum) 验证。
Actually,
but...
And per my private investigations on .Net 4.0 assemblies - hash sums are really ignored on Assembly Binding stage, even if assembly was signed by crypto-key and so has a strong name.
After a while I've realized that strong-name bypass feature causes this behavior.
So you need to "create a DWORD entry with a value of 0 named AllowStrongNameBypass under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework key" in order to enable strong name (+hashsum) validation.
1:没有,已经用过了。 Ecma-335,分区 II,第 6.2.3 章有关 .file 指令:
.hash 后面的字节指定为文件计算的哈希值。 VES 应在访问此文件之前重新计算此哈希值,如果不匹配,则应生成异常。用于计算此哈希值的算法由 .hash 算法指定(请参阅第 6.2.1.1 节)。
2:仅当启用强名称验证时。请注意,自 .NET 3.5 SP1 起,此功能在完全信任场景中默认处于关闭状态。您必须使用 caspol.exe
3 显式启用它:假设“强命名”,则无法进行验证。
1: No, it's used. Ecma-335, partition II, chapter 6.2.3 on the .file directive:
The bytes after the .hash specify a hash value computed for the file. The VES shall recompute this hash value prior to accessing this file and shall generate an exception if it does not match. The algorithm used to calculate this hash value is specified with .hash algorithm (see clause 6.2.1.1).
2: Only if strong name validation is enabled. Note that this is off by default since .NET 3.5 SP1 in full trust scenarios. You'd have to explicitly enable it with caspol.exe
3: assuming "strongly named", then no validation is possible.