Board logo

標題: [轉貼]設定暴力破解阻絕 dovecot / bind 方式 [打印本頁]

作者: chun    時間: 2014-4-22 18:12     標題: [轉貼]設定暴力破解阻絕 dovecot / bind 方式

http://www.ichiayi.com/wiki/tech/dovecot_fail2ban

前幾天查看 maillog 發現一堆來自特定 ip 使用 pop3/imap 的登入掃描帳號攻擊, 看到後手動加入 iptable 阻絕掉這個 ip 的來源, 但是過幾天, 又看到相同的行為來自不同的 ip , 所以上網找一下是否有人已經寫好這樣的自動阻絕工具.

- 安裝 Fail2Ban

[root@xen-mail ~]# yum install fail2ban
:
================================================================================
 Package          Arch           Version                 Repository        Size
================================================================================
Installing:
 fail2ban         noarch         0.8.2-3.el5.rf          rpmforge         125 k

:

- 設定 Fail2Ban 參數檔案

vi /etc/fail2ban/fail2ban.conf
:
logtarget = /var/log/fail2ban.log
:

- 設定 Fail2Ban 對 dovecot 的參數檔案

vi /etc/fail2ban/filter.d/dovecot-pop3imap.conf
[Definition]
failregex =  (?: Authentication failure|Aborted login|Disconnected).*rip=(?:::f{4,6}?(?P<host>\S*),.*
ignoreregex = (?: Disconnected: Logged out).*
vi /etc/fail2ban/jail.conf
:
:
[dovecot-pop3imap]
enabled  = true
filter   = dovecot-pop3imap
action   = iptables-multiport[name=dovecot-pop3imap, port="pop3,pop3s,imap,imaps", protocol=tcp]
           sendmail-whois[name=dovecot-pop3imap, dest=root, sender=tryweb@ichiayi.com]
logpath  = /var/log/maillog
maxretry = 20
findtime = 1200
bantime  = 1200

- 設定 Fail2Ban 對 bind 的參數檔案

vi /etc/named.conf
:
logging {
        channel Named_log {
                file "/var/log/named/named.log" versions unlimited;
                severity info;
                print-severity  yes;
                print-time yes; };
        category default {Named_log; };
        category xfer-out {Named_log; };
        category queries {Named_log; };
:
:

- 開始啟動 Fail2Ban 服務

[root@xen-mail ~]# service fail2ban start
Starting fail2ban:                                         [  確定  ]

[root@xen-mail ~]# chkconfig fail2ban on
[root@xen-mail ~]# chkconfig --list | grep fail2ban
fail2ban        0:關閉  1:關閉  2:開啟  3:開啟  4:開啟  5:開啟  6:關閉

- 查看 Fail2Ban 服務狀況

[root@xen-mail ~]# service fail2ban status
Fail2ban (pid 19813) is running...
Status
|- Number of jail:      1
`- Jail list:           dovecot-pop3imap

- 實際 Ban 的案例

參考資料網址







歡迎光臨 百利工頭 (http://bb.pc104.tw/) Powered by Discuz! 6.0.0