24

因此,我在我的 Azure 云服务站点中打开了此功能,以尝试减轻蜘蛛和机器人对我们的攻击次数荒谬的次数。

有没有人对这些设置有任何经验?

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

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

4

2 回答 2

21

一种寻找合理设置的实验方法

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

我们确定了单个(请求繁重的)页面生成的最大请求数,并将其乘以 2.5 以获得随时间推移的最大请求数。对于时间值,我选择了 200 毫秒。

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

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

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

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

2015 年 4 月更新

我们的服务在这些设置下已经运行了一年多,到目前为止我们很高兴。

于 2014-01-29T15:05:14.223 回答
1

有些人无法访问服务器,或者像我一样对动态 IP 限制不满意,所以我为 asp classic 制作了一个脚本。

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

  1. 您需要创建一个 MYSQL 数据库:
    创建表`banip`(
      `id` int(11) NOT NULL auto_increment,
      `IP` char(15) 默认为 NULL,
      `dtime` 时间默认为 NULL,
      主键(`id`),
      KEY `IP`(`IP`)
    ) 引擎=MyISAM 默认字符集=latin1;
  1. 您需要将 ASP 代码放在需要的地方

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

ASP 经典代码:

<%
' ***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>
于 2019-07-09T21:06:47.630 回答