相続、親が弱ってきたら銀行の預金は親の面倒を見ているものが全て解約して管理すべきである、銀行は解約させない!!

Raspberry pi fail2ban for asterisk

Asterisk

 

# apt-get install fail2ban
# cd /etc/fail2ban
# cp jail.conf jail.local
# vi jail.local
ignoreip = 127.0.0.1
bantime = 3600    防御する時間
findtime = 600 この期間中に
maxretry = 3  3回以上
destemail = ckenko25@lgmail.com
sender = fail2ban@localhost
action = %(action_mw)s
[asterisk-tcp]
enabled = true
[asterisk-udp]
enabled = true
[aterisk-brute-force]   追記
enabled = true
filter = asterisk-brute-force
logpath = /var/log/asterisk/messages
action = iptables-asterisk[name=ASTERISK, protocol=all]
sendmail-whois[name=ASTERISK, dest=ckenko25@gmail.com, sender=fail2ban@localhost]
bantime = 604800 ; 1 week
#findtime = 86400 ; 1 day
maxretry = 3
vi /etc/fail2ban/action.d/iptables-asterisk
# Fail2Ban configuration file
#
#
# $Revision: 250 $
#
[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
#before = common.conf
[Definition]
#_daemon = asterisk
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag "<HOST>" can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>\S+)
# Values: TEXT
#
failregex = Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Wrong password
Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - No matching peer found
Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Username/auth name mismatch
Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Device does not match ACL
Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Peer is not supposed to register
Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Not a local domain
NOTICE.* .*: Failed to authenticate device .* \(<HOST>:.*\)
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
# vi /etc/fail2ban/jail.local

[asterisk-udp]の下に追記

[aterisk-brute-force]
enabled = true
filter = asterisk-brute-force
logpath = /var/log/asterisk/messages
action = iptables-asterisk[name=ASTERISK, protocol=all]
sendmail-whois[name=ASTERISK, dest=ckenko25@gmail.com, sender=fail2ban@localhost]
bantime = 604800 ; 1 week
#findtime = 86400 ; 1 day
maxretry = 3

action

BAN処理のアクションを定義します。この例ではiptables-sipを実行します。その後、sendmail-whois で BANしたIPアドレスのwhois情報を dest= で指定された宛先に送ります。このとき使用されるメールのFrom:はfail2ban@exampleになりますので、適切なものに書き換えます。
アクションの所で iptables-allports を指定するとSIPだけでなく、すべてのポートからの接続を蹴るように iptables に設定されます。『怪しい攻撃元』をブロックするという意味では、こちらのアクションの方がより安全と言えます。

logpath

Asteriskのログファイルへのパスを記述します。

maxretry

何回以上失敗したらBANするかの指定です。

findtime

この時間内にmaxretryで指定した回数以上失敗するとBANします。上の例では600秒(10分)の間に、5回以上の失敗があった場合にはBANされます。

bantime

ここで指定された期間がBAN期間になります。指定は秒数です。上の例では 60x60x24x7=604800、つまり1週間になります。

fail2banを起動する

# /etc/init.d/fail2ban start
AsteriskRaspberry Pi
スポンサーリンク
シェアする
ふじやんをフォローする
スポンサーリンク
なんでもDIY

コメント