nginx testcookie

bagas nginx-forum на nginx.us
Сб Окт 3 18:18:18 UTC 2015


Народ добрый вечер.
Кто использует для отсечения ддос атака моудль нгинс testcookie?
есть некторые непонятки, не пойму логики.
настраиваю по этой инструкции
http://habrahabr.ru/post/139931/

# uname -rms
FreeBSD 10.2-RELEASE-p4 amd64

Нгинс собран с модулем testcookie

# nginx -V
nginx version: nginx/1.8.0
built by clang 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
built with OpenSSL 1.0.1p-freebsd 9 Jul 2015
TLS SNI support enabled
configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt='-I
/usr/local/include' --with-ld-opt='-L /usr/local/lib'
--conf-path=/usr/local/etc/nginx/nginx.conf
--sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid
--error-log-path=/mnt/log/nginx/nginx-error.log --user=www --group=www
--http-client-body-temp-path=/var/tmp/nginx/client_body_temp
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp
--http-proxy-temp-path=/var/tmp/nginx/proxy_temp
--http-scgi-temp-path=/var/tmp/nginx/scgi_temp
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp
--http-log-path=/mnt/log/nginx/nginx-access.log
--with-http_gzip_static_module --with-http_stub_status_module --with-pcre
--add-module=/usr/sources/kyprizel-testcookie-nginx-module-fa546e2


конфиг nginx.conf
http {
    testcookie off;
    testcookie_name ddos;
    testcookie_secret a1bes8r0f7bj228r2e16f4b2djslfka39ds5962;
    testcookie_session $remote_addr;
    testcookie_arg attempt;
    testcookie_max_attempts 3;
    testcookie_fallback /cookies.html?backurl=http://$host$request_uri;
    testcookie_get_only on;
    testcookie_redirect_via_refresh on;
    testcookie_refresh_encrypt_cookie on;
    testcookie_refresh_encrypt_cookie_key random;
    testcookie_refresh_encrypt_cookie_iv random;
    include /usr/local/etc/nginx/testcookie_whitelist.conf;
    testcookie_refresh_template '<html><body>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
Для нашего сервиса нужно включить куки в вашем браузере.<br />
При выключенных куках браузера, у вас есть несколько попыток, после вы
будите заблокированы.<br />
    <br />
For our service you need to enable cookies in your browser.<br />
If you turn off cookies the browser, you have a few attempts before you\'ll
blocked.<br />
<script type=\"text/javascript\" src=\"/aes.min.js\"
></script><script>function toNumbers(d){var
e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return
e}function toHex(){for(var
d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return
e.toLowerCase()}var
a=toNumbers("$testcookie_enc_key"),b=toNumbers("$testcookie_enc_iv"),c=toNumbers("$testcookie_enc_set");document.cookie="ddos="+toHex(slowAES.decrypt(c,2,a,b))+";
expires=Thu, 31-Dec-37 23:55:55 GMT;
path=/";document.location.href="$testcookie_nexturl";</script></body></html>';
....


виртуал хост . 
пока на тестовом сервере тестирую.


location = /cookies.html {
        root /usr/local/www/def;
}

location = /aes.min.js {
       gzip  on;
       gzip_min_length 1000;
       gzip_types      text/plain;
       root /usr/local/www/def;
}

location / {
        testcookie on;
        root  /usr/local/www/munin;
...


Лог.

2.2.2.2 - [03/Oct/2015:20:39:29 +0300] "GET
/cookies.html?backurl=http://9.0.9.0/?attempt=3 HTTP/1.1" 200 "Opera/9.80
(X11; Linux x86_64) Presto/2.12.388 Version/12.16"
2.2.2.2 - [03/Oct/2015:20:39:29 +0300] "GET /favicon.ico HTTP/1.1" 200
"Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16"
2.2.2.2 - [03/Oct/2015:20:39:29 +0300] "GET
/cookies.html?backurl=http://9.0.9.0/?attempt=3 HTTP/1.1" 200 "Opera/9.80
(X11; Linux x86_64) Presto/2.12.388 Version/12.16"
2.2.2.2 - [03/Oct/2015:20:39:29 +0300] "GET /favicon.ico HTTP/1.1" 200
"Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16"
2.2.2.2 - [03/Oct/2015:20:39:30 +0300] "GET
/cookies.html?backurl=http://9.0.9.0/?attempt=3 HTTP/1.1" 200 "Opera/9.80
(X11; Linux x86_64) Presto/2.12.388 Version/12.16"
2.2.2.2 - [03/Oct/2015:20:39:30 +0300] "GET /favicon.ico HTTP/1.1" 200
"Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16"
2.2.2.2 - [03/Oct/2015:20:39:30 +0300] "GET
/cookies.html?backurl=http://9.0.9.0/?attempt=3 HTTP/1.1" 200 "Opera/9.80
(X11; Linux x86_64) Presto/2.12.388 Version/12.16"
2.2.2.2 - [03/Oct/2015:20:39:30 +0300] "GET /favicon.ico HTTP/1.1" 200
"Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16"


Я логики не пойму этого модуля, как мне отслеживать ботов при этом?
Если включить куки, то сайт конечно грузится, либо если добавить себя в
исключения.
Если же с отключенными куками как видно в логах опера, то сразу без
предупреждения вылетает cookies.html, и код ответа 200.
Подскажите пожалуйста что я делаю не так в настройке этого модуля?

Posted at Nginx Forum: http://forum.nginx.org/read.php?21,261991,261991#msg-261991



Подробная информация о списке рассылки nginx-ru