ViewState EnableViewStateMAC

时间:2010-08-09 05:44:45

标签: c# asp.net security

如果EnableViewStateMAC设置为true,ASP.NET将为ViewState数据生成哈希码,并将其与存储在已发布值中的哈希码进行比较。什么阻止攻击者根据更改的表单值设置哈希?

1 个答案:

答案 0 :(得分:3)

生成的哈希值基于表单值和服务器已知的私钥(请参阅Salt on wikipedia)。因此,如果没有salt字符串,则无法生成有效的哈希值。

您可以从单声道实现查看ASP.NET源代码,并在课程System.Web.UI.ObjectStateFormatter查看,方法反序列化()

if (EnableMac) {
    data = MachineKeySectionUtils.VerifyDecrypt (Section, data);
else {
    data = MachineKeySectionUtils.Decrypt (Section, data);
}

在课程System.Web.Util.MachineKeySectionUtils,方法 VerifyDecrypt()

using (KeyedHashAlgorithm kha = GetValidationAlgorithm (section)) {
    kha.Key = GetValidationKey (section);
    // ...
}

其中 GetValidationKey()返回签名盐并验证哈希...