加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET MVC3 – 您如何处理探测请求?

发布时间:2020-12-16 04:38:17 所属栏目:asp.Net 来源:网络整理
导读:我们的网站上线了,当然,我们开始收到大量的探测请求, 喜欢 ‘/blog/wp-login.php’ ‘/admin/admin.php’ 等等 所以问题是,你用它们做什么? 现在在每种情况下都会抛出404错误并且elmah会发送有关它的电子邮件,但我认为最好至少忽略所有的php请求. 如何做到
我们的网站上线了,当然,我们开始收到大量的探测请求,
喜欢

‘/blog/wp-login.php’
‘/admin/admin.php’

等等
所以问题是,你用它们做什么?

现在在每种情况下都会抛出404错误并且elmah会发送有关它的电子邮件,但我认为最好至少忽略所有的php请求.

如何做到这一点,这样的请求将最低限度地加载服务器,可能是这样,asp.net管道将不参与此类请求?
或者重定向或返回空结果更好?

如果需要简单地添加IgnoreRoutes,可能有人有一套好的路由,这会忽略大多数探测请求?

解决方法

我知道你已经声明你不想在IIS中使用重写模块,因为它“在IIS上增加了额外的负载”,但事实上,使用IIS来处理这些将不会比传入你的应用程序那样密集.同样的事情(即使两者都是非常小的资源方面).如果您想在IIS和带宽上以最小的负载量忽略请求,我建议如下
<rewrite>
  <rules>
    <rule name="Fail PHP requests">
      <match url=".*"/>
      <conditions>
        <add input="{URL}" pattern="*.php*" />
      </conditions>
      <action type="AbortRequest" />
    </rule>
   </rules>
</rewrite>

使用设置为AbortRequest的操作类型进行的重写完全切断HTTP连接并删除请求,不返回404或403错误.摘自“创建访问块”部分中的Learn IIS.

编辑 – 由于OP对使用重写模块和性能存在担忧,我将提交第二个选项,它仍然可以在不使用重写模块的情况下捕获.php请求. IIS7及更高版本也支持请求过滤,根据Learn IIS,请求过滤是……

The request filtering module runs at the beginning of the request
processing pipeline by handling the BeginRequest event. The module
evaluates the request metadata,such as headers,the query string,
content length,etc,in order to determine whether the request
metadata matches any existing filter. If there is a match,the module
generates a 404 (File Not Found) response and then shortcuts the
remainder of the IIS pipeline

要实现,请将以下部分添加到web.config:

<configuration>
 <system.webServer>
  <security>
   <requestFiltering>
    <fileExtensions allowUnlisted="true" >
     <add fileExtension=".php" allowed="false"/>
    </fileExtensions>
   </requestFiltering>
  </security>
 </system.webServer>
</configuration>

信息来自URL Rewrite vs Request Filtering和Using Request Filtering

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读