درود
وقت بخیر
یکی از راه های مبارزه با حملات DDost استفاده از مد evasive است.این مد درخواست های مربوط به اپاچی را کنترل کرده و ای پی های مشکوم و مهاجم را برای ۱۰ دقیقه مسدود مینمایید . البته مقدار حساسیت برای مانیتورینگ قابل تنظیم و کنترول است .
آموزش نصب
در ابتدا پکیج مربوط به httpd-devel را نصب مینماییم :
[LEFT]
[/LEFT]سپس فایل مربوط به نصب (mod_evasive_1.10.1.tar.gz ) را دانلود مینماییم :
[LEFT]
کد: انتخاب همه
#wget http://pkgs.fedoraproject.org/repo/p..._1.10.1.tar.gz
[/LEFT]
فایل را از حالت فشرده خارج میکنیم :
[LEFT]
کد: انتخاب همه
# tar xvzf mod_evasive_1.10.1.tar.gz mod_evasive/
[/LEFT]به دایرکتوری مورد نظر میرویم :
[LEFT]
[/LEFT]فایل های زیر باید در این دایرکتوری مشاهده شوند :
[LEFT]
کد: انتخاب همه
mod_evasive/.cvsignore ; mod_evasive/LICENSE ; mod_evasive/Makefile.tmpl ; mod_evasive/README ; mod_evasive/mod_evasive.c ; mod_evasive/mod_evasive20.c ; mod_evasive/mod_evasiveNSAPI.c ; mod_evasive/test.pl ; mod_evasive/CHANGELOG
[/LEFT]از قرار داشتن ۲ فایل ReadMe و Changelog اطمینان حاسل نمایید . ( وجود این ۲ فایل بی دلیل نیست . . .)
برای کامپایل و نصب دستور زیر را وارد نمایید :
[LEFT]
کد: انتخاب همه
/usr/sbin/apxs -cia /usr/src/mod_evasive/mod_evasive20.c
[/LEFT]بعد از وارد کردن دستور بالا خروجی زیر را مشاهده مینمایید :
[LEFT]
کد: انتخاب همه
/usr/lib/apr-1/build/libtool –silent –mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -fno-strict-aliasing -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o mod_evasive20.lo mod_evasive20.c && touch mod_evasive20.slo
mod_evasive20.c: In function ‘access_checker’: mod_evasive20.c:212: warning: implicit declaration of function ‘getpid’ mod_evasive20.c:212: warning: format ‘%ld’ expects type ‘long int’, but argument 4 has type ‘int’ mod_evasive20.c:229: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result mod_evasive20.c: In function ‘destroy_hit_list’: mod_evasive20.c:301: warning: control reaches end of non-void function mod_evasive20.c: In function ‘create_hit_list’: mod_evasive20.c:118: warning: control reaches end of non-void function
/usr/lib/apr-1/build/libtool –silent –mode=link gcc -o mod_evasive20.la -rpath /usr/lib/httpd/modules -module -avoid-version mod_evasive20.lo /usr/lib/httpd/build/instdso.sh SH_LIBTOOL=’/usr/lib/apr-1/build/libtool’ mod_evasive20.la /usr/lib/httpd/modules /usr/lib/apr-1/build/libtool –mode=install cp mod_evasive20.la /usr/lib/httpd/modules/
cp .libs/mod_evasive20.so /usr/lib/httpd/modules/mod_evasive20.so
cp .libs/mod_evasive20.lai /usr/lib/httpd/modules/mod_evasive20.la
cp .libs/mod_evasive20.a /usr/lib/httpd/modules/mod_evasive20.a
chmod 644 /usr/lib/httpd/modules/mod_evasive20.a
ranlib /usr/lib/httpd/modules/mod_evasive20.a
PATH=”$PATH:/sbin” ldconfig -n /usr/lib/httpd/modules
[/LEFT]حق دسترسی را برای این فایل تنظیم مینماییم :
[LEFT]
کد: انتخاب همه
chmod 755 /usr/lib/httpd/modules/mod_evasive20.so
[/LEFT]و در آخر سرویس آپاچی را ریستارت میکنیم :
[LEFT]
[/LEFT]برای اطمینان از نصب و پیکربندی صحیح این مد دستور زیر را وارد نمایید :
[LEFT]
کد: انتخاب همه
grep -i evasive /etc/httpd/conf/httpd.conf
[/LEFT]خروجی :
[LEFT]
کد: انتخاب همه
LoadModule evasive20_module /usr/lib/httpd/modules/mod_evasive20.so
[/LEFT]با دستور زیر از لود شدن این مد اطمینان حاصل کنید :
[LEFT]
کد: انتخاب همه
php -r ‘phpinfo();’ | grep -i evasive
[/LEFT]خروجی :
[LEFT]
کد: انتخاب همه
Loaded Modules | core prefork http_core mod_so mod_auth_basic mod_auth_digest mod_authn_file mod_authn_alias mod_authn_anon mod_authn_dbm mod_authn_default mod_authz_host mod_authz_user mod_authz_owner mod_authz_groupfile mod_authz_dbm mod_authz_default util_ldap mod_authnz_ldap mod_include mod_log_config mod_logio mod_env mod_ext_filter mod_mime_magic mod_expires mod_deflate mod_headers mod_usertrack mod_setenvif mod_mime mod_dav mod_status mod_autoindex mod_info mod_dav_fs mod_vhost_alias mod_negotiation mod_dir mod_actions mod_speling mod_userdir mod_alias mod_rewrite mod_***** mod_*****_balancer mod_*****_ftp mod_*****_http mod_*****_connect mod_cache mod_suexec mod_disk_cache mod_file_cache mod_mem_cache mod_cgi mod_version **mod_evasive20** mod_perl mod_php5 mod_*****_ajp mod_python mod_ssl |
[/LEFT]خب مراحل نصب با موفقیت به پایان رسید و حالا نوبت پیکربندی این مد برای مانیتورینگ و جلوگیری از دسترسی های غیر مجاز است .
برای پیکربندی یکی از متغیر های زیر را در فایل مربوط به کانفیگ اپاچی (httpd.conf) وارد نمایید :
[LEFT]
کد: انتخاب همه
<IfModule mod_dosevasive20.c>
DOSHashTableSize ۳۰۹۷
DOSPageCount ۶
DOSSiteCount ۱۰۰
DOSPageInterval ۲
DOSSiteInterval ۲
DOSBlockingPeriod ۶۰۰
</IfModule>
[/LEFT]
یا
[LEFT]
کد: انتخاب همه
<IfModule mod_dosevasive20.c>
DOSHashTableSize ۳۰۹۷
DOSPageCount ۱
DOSSiteCount ۵۰
DOSPageInterval ۱
DOSSiteInterval ۱
DOSBlockingPeriod ۱۰
DOSEmailNotify root
# DOSSystemCommand “su – someuser -c ‘/sbin/… %s …’”
# DOSLogDir “/var/tmp/doslog”
#Leave this commented while testing, then uncomment once you are sure the module works
# DOSWhitelist ۱۲۷٫۰٫۰٫۱
</IfModule>
[/LEFT]و دوباره اپاچی را ریستارت کنید :
[LEFT]
[/LEFT]جدول آموزش متغییر های این مد :
[LEFT]Key
Description
DOSHashTableSize The hash table size defines the number of top-level nodes for each child’s hash table. Increasing this number will provide faster performance by decreasing the number of iterations required to get to the record, but consume more memory for table space
DOSPageCount This is the threshold for the number of requests for the same page (or URI) per page interval. Once the threshold for that interval has been exceeded, the IP address of the client will be added to the blocking list.
DOSSiteCount This is the threshold for the total number of requests for any object by the same client on the same listener per site interval.
DOSPageInterval The interval for the page count threshold; defaults to 1 second intervals.
DOSSiteInterval The interval for the site count threshold; defaults to 1 second intervals.
DOSBlockingPeriod The blocking period is the amount of time (in seconds) that a client will be blocked for if they are added to the blocking list. During this time, all subsequent requests from the client will result in a 403 (Forbidden) and the timer being reset (e.g. another 10 seconds).
DOSEmailNotify If this value is set, an email will be sent to the address specified whenever an IP address becomes blacklisted. A locking mechanism using /tmp prevents continuous emails from being sent.
DOSSystemCommand If this value is set, the system command specified will be executed whenever an IP address becomes blacklisted. This is designed to enable system calls to ip filter or other tools.
DOSLogDir Choose an alternative temp directory, default is /tmp.[/LEFT]
تشکر
[LEFT]منبع:
http://ponap.com/[/LEFT]