共享主机和简单的DoS攻击
本文关键字:DoS 攻击 简单 主机 共享 | 更新日期: 2023-09-27 17:51:12
我的网站托管在共享主机上,如果你花费25%的CPU超过90秒托管公司自动禁用应用程序池。我想知道如果这个代码可以卸载服务器从一个简单的DoS攻击
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = base.Context;
string ip = context.Request.UserHostAddress;
int activeRequests = (int)(context.Cache[ip] ?? 0);
activeRequests++;
if (activeRequests == 1)
{
context.Cache.Add(ip, activeRequests, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
}
if (activeRequests > 10)
{
log4net.Config.XmlConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
log.WarnFormat("Blocked IP: {0}, ActiveRequests: {1}", ip, activeRequests);
Response.Clear();
Response.Redirect("~/Error500.html");
}
}
void Application_EndRequest(object sender, EventArgs e)
{
HttpContext context = base.Context;
string ip = context.Request.UserHostAddress;
int activeRequests = (int)(context.Cache[ip] ?? 0);
activeRequests--;
}
我指的是简单的DoS攻击。
for (int i = 0; i < 100000; i++)
{
WebClient client = new WebClient();
client.DownloadString("http://example.com");
}
不行,这段代码没用。此外,对于代理服务器后面的用户来说,这可能是一个真正的问题:HTTP请求将由代理服务器发出,因此客户端IP对于它后面的每台PC来说都是相同的。
DoS预防是在基础设施上完成的,在应用程序代码之外。请将本文作为IIS的示例:http://m.windowsitpro.com/windows/q-does-microsoft-iis-70-include-feature-protect-iis-web-server-denial-service-dos-attacks-do
所以,简而言之,DoS预防通常是由主机提供商完成的。