溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

用fail2ban給centos系統(tǒng)做防御

發(fā)布時(shí)間:2020-10-07 02:43:12 來(lái)源:網(wǎng)絡(luò) 閱讀:2113 作者:bbotte 欄目:安全技術(shù)

系統(tǒng)為centos 6.4 64位

fail2ban http://www.fail2ban.org/wiki/index.php/Main_Page 

Fail2Ban is able to reduce the rate of incorrect authentications attempts however it cannot eliminate the risk that weak authentication presents. Configure services to use only two factor or public/private authentication mechanisms if you really want to protect services.

http://www.onerussian.com/tmp/fail2ban-pycon2014.pdf 這個(gè)是pdf的說(shuō)明文檔,不過(guò)較簡(jiǎn)單

fail2ban可以監(jiān)視你的系統(tǒng)日志,然后匹配日志的錯(cuò)誤信息(正則式匹配)執(zhí)行相應(yīng)的屏蔽動(dòng)作(一般情況下是調(diào)用防火墻屏蔽),如:當(dāng)有人在試探你的SSH、SMTP、FTP密碼,只要達(dá)到你預(yù)設(shè)的次數(shù),fail2ban就會(huì)調(diào)用防火墻屏蔽這個(gè)IP,而且可以發(fā)送e-mail通知系統(tǒng)管理員


我們需要對(duì)ssh的非法登陸有一定的機(jī)制,fail2ban就可以做到

下載:https://codeload.github.com/fail2ban/fail2ban/tar.gz/0.8.13 

安裝:

tar -xzf fail2ban-0.8.13.tar.gz
cd fail2ban-0.8.13
python setup.py install 
cd files/
cp ./redhat-initd /etc/init.d/fail2ban
chkconfig --add fail2ban


配置目錄:/etc/fail2ban

/etc/fail2ban/action.d #firewall、iptables、mail、sendmail等配置文件

/etc/fail2ban/filter.d   #apache、nagios、nginx-http-auth、php-url-fopen、selinux-ssh等防護(hù)策略

/etc/fail2ban/jail.conf #主要配置文件


編輯配置文件:

vim /etc/fail2ban/jail.conf  #在#[ssh-iptables]  #enabled = true 兩行的下面添加

[ssh-iptables]
enabled = true
filter = sshd
action  = iptables[name=SSH, port=ssh, protocol=tcp]
       sendmail-whois[name=SSH,dest=your_mail@163.com,sender=root@localhost,sendername="Fail2Ban"]
logpath  = /var/log/secure   #提供分析的日志,centos默認(rèn)是這個(gè)路徑
axretry = 5               #嘗試次數(shù)
bantime = 172800          #拒絕時(shí)間/秒
  
  
[DEFAULT]                 #以下是約束下面的全局配置,不要添加
ignoreip = 127.0.0.1/8    #忽略的ip
bantime  = 600            #屏蔽時(shí)間
findtime  = 600           #在這個(gè)時(shí)間段內(nèi)
maxretry = 3              #錯(cuò)誤次數(shù)
backend = auto
usedns = warn

如果修改上面的[ssh-iptables]選項(xiàng),那么將下面的[ssh-iptables]選項(xiàng)注釋或刪除,要不兩個(gè)相同的選項(xiàng)設(shè)置,服務(wù)會(huì)不起作用


下面還有好多選項(xiàng),enabled  = false 改為enabled  = true 就會(huì)生效

相應(yīng)的配置文件路徑:  /etc/fail2ban/filter.d/  也需要修改一下


啟動(dòng)服務(wù):

service fail2ban restart

fail2ban的進(jìn)程

/usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock -p /var/run/fail2ban/fail2ban.pid -x

查看狀態(tài):

fail2ban-client status

查看被阻止的ip

iptables -L

REJECT     all  --  192.168.22.236       anywhere            reject-with icmp-port-unreachable


如果重起iptables 記的一定還要重起fail2ban,不然不能生效,fail2ban的過(guò)濾表是在iptables 啟動(dòng)后在加入的


用fail2ban給centos系統(tǒng)做防御

如果有這個(gè)錯(cuò)誤提示,把[ssh-iptables]前面的空格去掉

Starting fail2ban: ERROR  Failed during configuration: File contains no section headers.

file: /etc/fail2ban/jail.conf, line: 17

' [ssh-iptables]\n'

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI