|
هناك الكثير من طرق الحماية من هجمات حجب الخدمة كاستخدام جدار ناري و غيرها من الطرق المختلفة ولكن اليوم سأتكلم عن تجربتي للبرنامج الرائع HAProxy الذي استعمله لموازنة الحمل Load balancing و Reverse proxy.

بالامكان استخدام اداة haproxy للقيام بالكثير من الامور و لكن اليوم سنشرح كيفية استخدام الاداة للحماية من هجمات حجب الخدمة او Denial of Service Attacks. فكرة عمل الاداة هي تحديد عدد الاتصالات الى السيرفر في الثانية و مدة كل اتصال.
تنصيب البرنامج:
في البداية قم بتحميل اخر نسخة من الأداة من الموقع الرسمي للأداة. بعد التحميل نقوم بعمل ملف خاص بالبرنامج ثم فك ضغط الأداة فيه و تنصيبها.
mkdir /usr/local/haproxy cd /usr/local/haproxy tar -xzvf haproxy-*.tar.gz make TARGET=OS
مع تغيير OS الى نظام التشغيل الذي نستخدمه, مثلا للتريكب على نظام لينكس 32bit ننفذ:
make TARGET=linux26 ARCH=i386 make install mv haproxy-*.tar.gz haproxy
اعدادات البرنامج:
اعدادات البرنامج بسيطة فبامكاننا تعديل اي خيار في ملف haproxy.cfg حسب حاجتنا ولكن هذه الاعدادات هي الأنسب لمحاربة برامج حجب الخدمة و ستوفر لنا الحماية من أشهر البرامج مثل SlowLoris و nkiller2. في البداية نقوم بادخول الى مجلد البرنامج و فتح ملف الاعدادات.
cd haproxy vi haproxy.cfg
الان نضع فيه الاعدادات التالية.
global daemon maxconn 20000 # count about 1 GB per 20000 connections pidfile /var/run/haproxy.pid stats socket /var/run/haproxy.stat mode 600
defaults mode http maxconn 19500 # Should be slightly smaller than global.maxconn. timeout client 60s # Client and server timeout must match the longest timeout server 60s # time we may wait for a response from the server. timeout queue 60s # Don't queue requests too long if saturated. timeout connect 4s # There's no reason to change this one. timeout http-request 5s # A complete request may never take that long. # Uncomment the following one to protect against nkiller2. But warning! # some slow clients might sometimes receive truncated data if last # segment is lost and never retransmitted : # option nolinger option httpclose option abortonclose balance roundrobin option forwardfor # set the client's IP in X-Forwarded-For. retries 2
frontend public bind :80 # or any other IP:port combination we listen to. default_backend apache
backend apache # set the maxconn parameter below to match Apache's MaxClients minus # one or two connections so that you can still directly connect to it. server srv 127.0.0.1:8080 maxconn 254
# Enable the stats page on a dedicated port (8888). Monitoring request errors # on the frontend will tell us how many potential attacks were blocked. listen stats # Uncomment "disabeled" below to disable the stats page : # disabled bind :8888 stats uri /
تأكد من تغيير 127.0.0.1 الى IP الخاص بك و 8080 الى المنفذ الخاص بخادم الويب الخاص بك.
للتأكد من صحة الاعدادات ننفذ الامر:
./haproxy -f haproxy.cfg -c
الناتج يجب ان يكون كالتالي:
Configuration file is valid
تشغيل haproxy:
./haproxy -f haproxy.cfg
الخيار f- لاختيار ملف الاعدادات الذي قمنا باعداده في الخطوة السابقة.
للدخول على الواجهة الرسومية للاداة نذهب الى:
http://haprxyip:8888
قم بتغيير haproxyip الى عنوان السيرفر المنصبة عليه الاداة.
مثال عن ملف اعدادت البرنامج للحماية من هجمات حجب الخدمة: antidos.cfg
الموقع الرسمي للأداة: haproxy
عن الكاتب:
أحمد عبدو, مدير نظم تشغيل لينكس ويونكس في شركة NileWeb. سفير من سفراء فيدورا في مصر مهتم باللينكس والمصادر المفتوحة, تطبيقات الويب والزيادة من سرعتها واختبار اختراقها.
 |