亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

linux利用CSF防火墻屏蔽惡意請求

 更新時間:2017年05月22日 10:00:55   作者:Myths  
本篇文章主要介紹了linux利用CSF防火墻屏蔽惡意請求,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

問題
最近不知道為什么,惡意代理的請求數(shù)越來越多,明明我返回的都是403Forbidden,但是由于數(shù)量實在龐大,還是消耗了我大量的帶寬和資源。之前的方法已經(jīng)沒有用了,想了半天還是研究研究防火墻吧,雖然僅僅靠Apache也能對某些IP進行黑名單設置,但是感覺還是有點麻煩的。比如最常見的用iptables,或者是ufw,雖然都能很好的做到管理,但是他們基本都需要一條一條的加,十分麻煩。

網(wǎng)上搜索了下,找到了一個挺方便的小工具–CSF(ConfigServer & Security Firewall),這個工具據(jù)說除了能夠方便的管理IP blacklist,而且也能稍加配置抵御一定量的DDOS攻擊。

安裝
工具本身可以在csf工具的官網(wǎng)上下載。

下載并解壓后可以參考其中的install.txt的說明進行安裝,講的簡潔而且詳細,注意給權限就行。需要說明的是,這個工具其實也是基于iptables,只是簡化了命令而已。

關于ddos的防護

根據(jù)readme.txt的描述,進行ddos防護的功能主要是靠/etc/csf/csf.conf中的配置進行控制的,尤其是當中的PORTFLOOD參數(shù),一般都進行如下設置:

#Syntax for the PORTFLOOD setting:
#PORTFLOOD is a comma separated list of:
port;protocol;hit count*;interval seconds
#So, a setting of PORTFLOOD = "22;tcp;5;300,80;tcp;20;5" means:
#1. If more than 5 connections to tcp port 22 within 300 seconds, then block
#that IP address from port 22 for at least 300 seconds after the last packet is
#seen, i.e. there must be a "quiet" period of 300 seconds before the block is
#lifted
#2. If more than 20 connections to tcp port 80 within 5 seconds, then block
#that IP address from port 80 for at least 5 seconds after the last packet is
#seen, i.e. there must be a "quiet" period of 5 seconds before the block is
#lifted

這個可以根據(jù)個人需要修改。

關于black list

blacklist 就在/etc/csf/csf.deny里,可以有多種書寫方式,在該文件的頂部描述的十分清楚:

###############################################################################
# Copyright 2006-2017, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
# The following IP addresses will be blocked in iptables
# One IP address per line
# CIDR addressing allowed with a quaded IP (e.g. 192.168.254.0/24)
# Only list IP addresses, not domain names (they will be ignored)
#
# Note: If you add the text "do not delete" to the comments of an entry then
# DENY_IP_LIMIT will ignore those entries and not remove them
#
# Advanced port+ip filtering allowed with the following format
# tcp/udp|in/out|s/d=port|s/d=ip
#
# See readme.txt for more information regarding advanced port filtering
#

簡要概括就是每一行代表一個ip,也可以代表一個ip段(CIDR),而且我們也可以加注釋,甚至可以指定端口和協(xié)議。
最后,在做出修改后想要生效記得用csf -r命令。

針對惡意代理請求的防護方案

當然,我用這個的目的是為了根本解決之前的惡意代理占用帶寬的問題。有了這個工具,就可以十分輕松的進行控制了,思路如下:

  1. 首先,搜索Apache的log(/var/log/apache2/access.log),查找所有應被屏蔽的log條目(我這里指的是所有被403的請求)。
  2. 然后,提取每條Log記錄對應的ip地址。
  3. 對結果進行排序去重,生成black list。
  4. blacklist 寫入csf.deny
  5. 重啟csf防護服務。

實現(xiàn)起來超級簡單:

復制代碼 代碼如下:

root@server:~# cat /var/log/apache2/access.log |grep \ 403\ |awk '{print $1}'|sort|uniq >> /etc/csf/csf.deny

可以手動查看下結果是否正確,確認之后既可以csf -r重啟服務了。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論