我接管了一个运行旧版本社区服务器的域。不用说,机器人正在向我发送垃圾邮件以寻找漏洞。
我想在System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
被解雇之前阻止整个 IP 块。我有一个IHttpModule
我尝试过的,但我认为它会被调用,因为 HealthMonitoring 正在捕获异常。这是模块:
public class IpBlockerModule : IHttpModule
{
private static readonly string[] Hacks = new[]
{
"60.169.73.",
"60.169.75.",
"61.160.232.",
"61.160.207.",
"92.85.161."
};
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += (Application_BeginRequest);
}
private void Application_BeginRequest(object source, EventArgs e)
{
var context = ((HttpApplication) source).Context;
var ipAddress = context.Request.UserHostAddress;
if (!IsHackIpAddress(ipAddress))
{
context.Response.StatusCode = 403; // (Forbidden)
}
}
private static bool IsHackIpAddress(string ip)
{
if (ip == null) return true;
return Hacks.Any(x => x.StartsWith(ip));
}
}
以及相关的 web.config 部分:
<system.web>
<httpModules>
<add name="IpBlockerModule" type="MyNameSpace.IpBlockerModule" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" >
<add name="IpBlockerModule" type="MyNameSpace.IpBlockerModule" preCondition="" />
</modules>
</system.webServer>
这背后的原因是我的收件箱被所有的垃圾邮件
A potentially dangerous Request.Path value was detected from the
client
和
A potentially dangerous Request.Form value was detected from the client
通知。我的模块有问题,还是我假设模块在事后才被解雇是正确的?