4

我正在研究限制 Django 管理员登录以防止字典攻击的各种速率方法。

这里解释了一种解决方案:http: //simonwillison.net/2009/Jan/7/ratelimitcache/

但是,我更喜欢使用 Nginx 在 Web 服务器端进行速率限制。

Nginx 的limit_req模块就是这样做的 - 允许您指定每分钟的最大请求数,并在用户过去时发送 503:http ://wiki.nginx.org/NginxHttpLimitReqModule

完美的!我以为我已经破解了它,直到我意识到 Django 管理员的登录页面不在一个一致的位置,例如 /admin/blah/ 为您提供了该 URL 的登录页面,而不是跳转到标准登录页面。

所以我无法匹配 URL。谁能想到另一种方法来知道正在显示管理页面(正则表达式响应 HTML?)

4

2 回答 2

3

首先:为了稍微保护 django 管理员,我总是为管理员使用与 /admin/ 不同的 url 一个好主意是将管理员部署为另一个域或子域上的第二个应用程序

您可以通过 IPTABLES/NETFILTER 限制每分钟对整个 webapp 的请求。可以在debian 管理员处找到如何完成此操作的教程。这是一个如何保护 ssh 端口的示例,但您可以对 http 使用相同的技术。

您可以使用 NginxHttpLimitZone 模块来限制分配会话的同时连接数,或者作为一种特殊情况,从一个 IP 地址开始。编辑 nginx.conf:

来自www.cyberciti.biz

### Directive describes the zone, in which the session states are stored i.e. store in slimits. ###
### 1m can handle 32000 sessions with 32 bytes/session, set to 5m x 32000 session ###
       limit_zone slimits $binary_remote_addr 5m;

### Control maximum number of simultaneous connections for one session i.e. ###
### restricts the amount of connections from a single ip address ###
        limit_conn slimits 5;

The above will limits remote clients to no more than 5 concurrently "open" connections per remote ip address.

于 2010-03-31T13:22:55.310 回答
1

bmaeser is right, you should run admin in a separate instance (ie separate domain/subdomain/port).

You might also be interested in django-sentinel, which does dynamic greylisting of suspicious ip addresses/networks using memcached and auto-blacklists repeat offenders.

于 2011-05-24T04:20:32.873 回答