
DOS – Denial Of Service là một hình thức tấn công làm cho máy chủ website không thể đáp ứng được truy cập của người dùng bình thường. bằng cách sử dụng iptables hay CSF chúng ta có thể chống lại một cuộc tấn công DOS . Để cấu hình iptables chống lại DOS bạn cần hiểu biết tốt về iptables nhưng với CSF thì rất đơn giản. Trong bài viết này sẽ nêu hai cách để bạn lựa chọn.
Sử dụng iptables để chống lại DOS
-A : Append -p : Protocol --dport : For ports -m limit : To limit iptables extension --limit 25/minute : Defines maximum of 25 connection per minute. --limit-burst 100 : The limit/minute will be enforced only after the total number of connection have reached the limit-burst level, ie 100 here. -j : Target
IPTable rule:
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
Lệnh trên nghĩa là khi IP silent đạt tới 100 kết nối tới Server thì bắt đầu hạn chế cho phép 25 kết nối trong 1 phút. Nếu kết nối nhiều hơn sẽ bị block.
ví dụ:
root@test [~]# iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination acctboth all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 limit: avg 25/min burst 100
Bảo vệ Server/VPS bằng CSF
Ta edit file csf.conf trong etc/csf.conf . ta có thể dùng trình soạn thảo vi hoặc dùng winscp hay filezilla vào trực tiếp chỉnh sửa csf.conf
vi /etc/csf/csf.conf
ta sẽ chỉnh giá trị CT_LIMIT
# To disable this feature, set this to 0
CT_LIMIT = "50"
50 là giá trị tối đa mà một IP có thể kết nối tới server. bạn cũng cần chỉnh cả các cổng cho CSF theo dõi
# Leave this option empty to count all ports against CT_LIMIT CT_PORTS = "80,53,22"
Khởi động lại CSF
csf -r
Tham khảo một số giá trị CT trong CSF mà ta có thể chỉnh sửa:
# Connection Tracking interval. Set this to the the number of seconds between # connection tracking scans CT_INTERVAL = "30" # Send an email alert if an IP address is blocked due to connection tracking CT_EMAIL_ALERT = "1" # If you want to make IP blocks permanent then set this to 1, otherwise blocks # will be temporary and will be cleared after CT_BLOCK_TIME seconds CT_PERMANENT = "0" # If you opt for temporary IP blocks for CT, then the following is the interval # in seconds that the IP will remained blocked for (e.g. 1800 = 30 mins) CT_BLOCK_TIME = "1800" # If you don't want to count the TIME_WAIT state against the connection count # then set the following to "1" CT_SKIP_TIME_WAIT = "0" # If you only want to count specific states (e.g. SYN_RECV) then add the states # to the following as a comma separated list. E.g. "SYN_RECV,TIME_WAIT" # # Leave this option empty to count all states against CT_LIMIT CT_STATES = ""
Okie…
Chúc bạn thành công.