代码改变世界

一起谈.NET技术,ASP.NET 安全漏洞临时解决方案

  狼人:-)  阅读(263)  评论(0编辑  收藏  举报

  在上周五一个安全会议上披露了微软ASP.NET的一个安全漏洞,利用该漏洞攻击者可以请求并下载一些ASP.NET Web.config文件,攻击者可以发送密文并根据默认错误页信息来得到Machine Key。微软目前并没有新的补丁下载,但ScottGu在自己的博客中给出了一个临时解决方案,这里简单翻译一下,大家可做参考。

  在ASP.NET 1.1 到 ASP.NET 3.5中,可以通过在Web.config中创建<customErrors>节点来解决,注意,ErrorMode必须设置为On,且对于所有的错误都转向同一个错误页,主要是防止攻击者根据不同的错误也跳转来猜测服务器发生了什么错误:

<configuration>
<
system.web>
<
customErrors mode="On" defaultRedirect="~/error.html" />
</
system.web>
</
configuration>

  在ASP.NET 3.5 SP1到ASP.NET 4.0中,在Web.config中创建<customErrors>节点,设置ErrorMode为On,设置RedirectMode模式为ResponseRewrite,对于所有的错误跳转到同一个错误页:

<configuration>
<
system.web>
<
customErrors mode="On" redirectMode="ResponseRewrite"
defaultRedirect="~/error.aspx" />
</
system.web>
</
configuration>

  并且ScottGu还建议在错误页的Page_Load()事件中加上如下代码:

<%@ Page Language="C#" AutoEventWireup="true" %>
<%
@ Import Namespace="System.Security.Cryptography" %>
<%
@ Import Namespace="System.Threading" %><script runat="server">
void
Page_Load(){
byte[] delay = new byte[1];
RandomNumberGenerator prng = new RNGCryptoServiceProvider();

prng.GetBytes(delay);
Thread.Sleep((int)delay[0]);

IDisposable disposable = prng as IDisposable;
if (disposable != null){ disposable.Dispose(); }
}
</script>

<html>
<
head id="Head1" runat="server">
<
title>Error</title>
</
head>
<
body>
<
div>
An error occurred while processing your request.
</div>
</
body>
</
html>

  另外ScottGu也提供了一个vbs脚本,可以用来测试服务器上ASP.NET 应用程序的<customErrors>节点配置,大家可以到这里下载。

  参考信息:

  1. Important: ASP.NET Security Vulnerability
  2. Microsoft Security Advisory 2416728
  3. Understanding the ASP.NET Vulnerability

  4. Microsoft Security Response Center Blog Post

编辑推荐:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
点击右上角即可分享
微信分享提示