Nói về vấn đề DDos, có lẽ sẽ rất khó để chắc chắn rằng làm thế nào chúng ta có thể an toàn 100% trước vấn nạn này. Bởi có rất nhiều phương thức tấn công như dos,ddos, flood, Slowloris …cũng như đi kèm với nó là các cường độ khác nhau. Bởi vậy các giải pháp TechBlog trình bày bên dưới sẽ chỉ có thể giúp bạn trong một số trường hợp nhất định mà thôi. Tuy vậy nó cũng sẽ phần nào giúp bạn kiện toàn bảo mật cho webserver của bạn.

1. Hạn chế DDos: Dos Deflate
Tiến hành cài đặt Firewall Dos Deflate:
#cd download
#wget http://www.inetbase.com/scripts/ddos/install.sh
#chmod 0700 install.sh
#./install.sh
Sau khi cài đặt thành công, ta có thể cấu hình Firewall bằng cách dùng lệnh:
#nano /user/local/ddos/ddos.conf
Đây là file cấu hình của Firewall, nội dung cơ bản sẽ như sau:
FREQ=1 // tắt/ bật Firewall (0=tắt, 1=bật)
NO_OF_CONNECTIONS=150 // max connect từ 1 IP đến server
APF_BAN=1
KILL=1 // tắt/bật (0=tắt, 1= bật)
EMAIL_TO="administrator@techblog.vn"
BAN_PERIOD=600 // thời gian ban IP là 600 giây
Khởi động: Cấu hình khởi động cùng hệ thồng:
Mã:
## Edit /etc/rc.d/rc.local
## (or similar file depending on Linux version)
## Add the following lines at the bottom of the file
/usr/local/ddos/ddos.sh -c
2. Apache Antiddos Mod: mod_dosevasive
Refer to the following steps to install the Mod_evasive but make sure that you have logged in as a root user.
cd /usr/local/src
wget http://theperfectarts.com/software/m..._1.10.1.tar.gz
tar xvfz mod_ev*
cd mod_evasive*
Tiếp tục đánh lệnh sau:
apxs -cia mod_evasive20.c
Nếu xuất hiện lỗi như sau -bash: apxs: command not found thì do các bạn chưa cài apxs
yum install httpd-devel (yum install apache2-threaded-dev gcc)
Tìm và thêm vào file httpd.conf đoạn sau:
Add the following to httpd.conf
<IfModule mod_dosevasive20.c> DOSHashTableSize 3097
DOSPageCount 1
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
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 127.0.0.1
</IfModule>
hoặc
<IfModule mod_dosevasive20.c>
DOSHashTableSize 3097
DOSPageCount 6
DOSSiteCount 100
DOSPageInterval 2
DOSSiteInterval 2
DOSBlockingPeriod 600
DOSEmailNotify someuser@somedomain.com
</IfModule>
Descriptions:
- DOSHashTableSize: the size of the table of URL and IP combined
- DOSPageCount: the number of same page requests from the same IP during an interval that will cause that IP to be added to the block lt.
- DOSSiteCount: the number of pages requested of a site by the same IP during an interval which will cause the IP to be added to the block lt.
- DOSPageInterval: the interval that the hash table for IPs and URLs erased (in seconds)
- DOSSiteInterval: the intervale that the hash table of IPs erased (in seconds)
- DOSBlockingPeriod: the time the IP blacked (in seconds)
- DOSEmailNotify: can be used to notify by sending an email everytime an IP blocked
- DOSSystemCommand: the command used to execute a command when an IP blocked. It can be used to add a block the user from a firewall or router.
- DOSWhiteLt: can be used to whitelt IPs such as 127.0.0.1
Sau đó lưu lại và restart apache bằng lệnh:
#service httpd restart
hoặc
#/etc/init.d/httpd restart
3. Cài đặt và cấu hình Iptables:
iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j RETURN
Về thông tin giới thiệu, cài đặt, cách sử dụng TechBlog đã có trình bày cụ thể tại bài viết Cấu hình Firewall Iptables trên CentOS / Redhat. Trong trường hợp anti ddos, chúng ta chỉ quan tâm một số rules cơ bản như sau:
#Limit the number of incoming tcp connections
#Interface 0 incoming syn-flood protection
#iptables -N syn_flood
#iptables -A INPUT -p tcp --syn -j syn_flood
#iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
#iptables -A syn_flood -j DROP
4. Cài đặt mod_antiloris cho Apache:
How To Install Mod_Antiloris?
1) Download the installer from sourceforge and install
a) cd /usr/local/src
b) wget http://sourceforge.net/projects/mod-...r.bz2/download
c) tar -xvjf mod_antiloris-0.4.tar.bz2
d) cd mod_antiloris-*
e) apxs -a -i -c mod_antiloris.c
2) Now we have to restart apache
service httpd restart
3) How to check whether mod_antiloris loaded or not
httpd -M | grep antiloris
Note if you are using cpanel server then you have to run the below command to make sure new modification are updated into configuration system file
/usr/local/cpanel/bin/apache_conf_distiller –update
Now you can check if your Apache is protected from Slowloris Dos attack or not . Launch a slowloris attack and check Apache status page to see if its effecting it or not.
- Mod antiloris default giới hạn 20 connections cho một Ip, bạn có thể tùy chỉnh bằng cách add vào httpd.conf
vd:
<IfModule antiloris_module>
IPReadLimit 50
</IfModule>
Chúc bạn thành công.