IIS8中最佳的“动态IP限制设置”是什么

时间:2013-02-11 02:15:35

标签: asp.net-mvc azure-web-roles iis-8

所以我在我的Azure云服务网站上启用了此功能,以尝试减轻蜘蛛和机器人对我们造成荒谬的次数。

有没有人有这些设置的经验?

根据并发请求数拒绝IP地址: 最大并发请求数?

根据一段时间内的请求数拒绝IP地址: 最大请求数量? 时间段(以毫秒为单位)?

2 个答案:

答案 0 :(得分:18)

找到合理设置的实验方法

我最近一直在尝试使用这些设置来决定生产网站的价值。

我们确定了单个(请求密集型)页面生成的最大请求数,并将其与2.5相乘以获得一段时间内的最大请求数。对于时间值,我选择了200ms。

手动测试表明这些设置适用于“正常”使用。当我们同时在浏览器中的5个或更多选项卡中重新加载页面时,我们设法获得403 Forbidden。

您必须记住的是,您网站的许多用户可能位于同一代理后面,因此动态IP限制将这些用户视为仅一个用户。凭借200ms的相当短的窗口,我预计这不会成为问题,同时仍然会在某种程度上阻止攻击性的DoS攻击。

此外,我们不限制同时连接的数量。在这里找到一个合理的数字几乎是不可能的,因为不同的客户的数量可能是无限的。

请注意,单个页面(请求具有大多数请求的页面)的请求与获取有用设置高度相关。例如。如果首页的页面加载会向服务器生成10个请求,则这些请求的时间跨度非常短,因此您的限制必须具有更高的阈值。

2015年4月更新

我们的服务已经使用这些设置运行了一年多,到目前为止我们一直很开心。

答案 1 :(得分:0)

有些人没有访问服务器的权限,或者像我一样,他们对动态IP限制不满意,因此我为asp classic编写了脚本。

您可以将其放置在所需的网页上(主页和/或内部)。它使用一个Mysql DB。在示例中,我在3秒内为每个ip加载3网页设置了一个禁令(这不是正常活动)。我只是想阻止每一个洪水,愿望脚本,ddos,机器人或烦人的网站访问。

  1. 您需要创建一个MySQL数据库:
    CREATE TABLE `banip` (
      `id` int(11) NOT NULL auto_increment,
      `IP` char(15) default NULL,
      `dtime` time default NULL,
      PRIMARY KEY  (`id`),
      KEY `IP` (`IP`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  1. 您需要在需要的地方输入ASP代码

  2. 再加上一个微小的管理网页mybanipadm.asp(可以更改文件名)

ASP CLASSIC CODE:

<%
' ***PUT THIS CODE AT THE TOP OF YOUR WEBPAGE YOU WANT TO PROTECT***
' COULD BE HOME PAGE AND/OR INTERNAL PAGE
' THE BAN IS PERSISTANT UNTIL THE SERVER RESTART

response.buffer = true
IP = Request.ServerVariables("REMOTE_ADDR")

'IP WHITELIST - SEPARATE EACH IP WITH A |
IPWL = "127.0.0.1|"

if instr(IPWL,IP) then
'do nothing the ip is whitelisted
else

'CHECK IF THERE IS A BAN THAT MATCH THE CURRENT IP
if Application("mybanip") <> "" then
if instr(Application("mybanip"),IP) then

' RESPONSE EXAMPLE WHEN ACCESS DENIED (CHOOSE ONE OR MAKE YOUR)
'Response.Status = "403 Forbidden"
'Response.Status = "404 Not Found"
'response.redirect "banned.html"
response.write "You are going too fast !"

session.abandon
response.end
end if
end if


' THE TIME NOW
dtime = FormatDateTime(now(),3)

'we can decide to run it at speficied time
'if dtime >= "00:00:00" and dtime < "05:00:00" then


' PREPARE TO CHECK DATABASE FOR THE LAST 3 SECONDS ACTIVITY
secfrom = DateAdd("s",-3,now()) 'value you can change is -3 (seconds)
secfrom = FormatDateTime(secfrom,3)

' ***OPEN THE CONNEXION STRING (USE YOUR ONE OR MODIFY THIS)***
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={MySQL ODBC 3.51 Driver};server=127.0.0.1;uid=LOGIN;pwd=PSW;Database=DBNAME;"

' ***EVERYTHING BELOW MUST BE PUT AFTER THE CONNEXION STRING OPENED***

' POPULATE DATABASE WHIS THE CURRENT IP AND TIME
SQL = "INSERT INTO BANIP (IP,DTIME) values('" & IP & "','" & dtime & "')"
conn.execute(SQL)

' CHECK IF THERE IS A SPAM ACTIVITY FOR THE CURRENT IP
SQL = "SELECT COUNT(IP) as nbfound FROM BANIP WHERE IP='" & IP & "' AND dtime BETWEEN '" & secfrom & "' AND '" & dtime & "'"
set rsIPCount = conn.Execute(SQL)
if not rsIPCount.Eof then
ipcount = clng(rsIPCount("nbfound"))
else
ipcount = "0"
end if
rsIPCount.Close
set rsIPCount = nothing

' IF THERE IS AT LEAST 3 WEBPAGE LOADED IN 3 SECONDS ACTIVITY THEN SET A BAN
if ipcount >= 3 then 'value you can change is 3 (webpage)
application.lock
Application("mybanip") = Application("mybanip") & IP & "|"
application.unlock
end if


' DELETE ALL ENTRY EVERY 2 MINUTES FOR PERFORMANCE
if Application("mybanipdel") = "" then
Application("mybanipdel") = dtime
elseif datediff("n", Application("mybanipdel"), dtime) >= 2 or datediff("n", Application("mybanipdel"), dtime) < 0 then 'value you can change is 2 (minutes)
conn.execute "DELETE FROM BANIP"
Application("mybanipdel") = FormatDateTime(now(),3)
end if

SQL = ""
IP = ""
end if

%>

管理页面mybanipadm.asp

<html>
<head>
<title>My admin</title>
</head>
<body><%

if request.querystring("disconnect")="yes" then
session("adm") =""
elseif request.querystring("clear")="yes" then
Application("mybanip") = ""
end if

' ***CHANGE THIS VALUES***
login = "login"
passw = "pass"

if request.form("LogMe")<>"" and (request.form("login")=login and request.form("passw")=passw) then
session("adm") = "loggued"
elseif session("adm") = "" then
response.write "<p>Please log-in :</p> <form method=""post""><input type=""text"" size=""15"" name=""login"" placeholder=""login""> <input type=""password"" size=""15"" name=""passw"" placeholder=""password""><input type=""submit"" name=""LogMe""></form>"
response.end
end if

response.write "<p><a href=""?disconnect=yes"">Disconnect from the admin</a> - <a href=""?clear=yes"">Clear all ip</a></p>"

if request.form("unban")<>"" and request.form("ipban")<>"" then
application.lock
Application("mybanip") = replace(Application("mybanip"),request.form("ipban") & "|","")
application.unlock
response.write "<p>IP : <b>" & request.form("ipban") & "</b> has been unbanned !</p>"
end if

response.write "Unban this IP : <form method=""post""><input type=""text"" size=""15"" maxlenght=""15"" name=""ipban"" placeholder=""000.000.000.000""> <input type=""submit"" name=""Unban"" value=""Unban""></form>" 
response.write "<p>IP CURRENTLY BANNED</p>" & replace(Application("mybanip"),"|","<br>")

%>
</body>
</html>