
私は新しいサーバーを設定してFail2banをインストールしましたが、間違ったパスワードで接続を試みてもブロックされません。
失敗2ban.log:
2018-03-23 12:46:29,363 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:46:30,747 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:46:33,346 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:46:35,515 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:46:36,372 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:47:45,471 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:47:46,820 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:47:49,503 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:47:50,458 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:47:51,893 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:48:49,699 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:48:51,835 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:48:52,531 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:48:54,477 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:48:57,056 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:50:53,240 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:50:53,677 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:50:55,065 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:50:58,253 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:51:00,494 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:51:00,685 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:52:06,119 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:52:08,300 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:52:11,583 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:52:11,773 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:52:13,498 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:53:07,823 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:53:09,712 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:53:09,842 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:53:11,718 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:53:13,696 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:54:37,181 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:54:37,949 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:54:39,092 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:54:40,906 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:54:42,616 fail2ban.filter [9756]: INFO [sshd] Found [my ip]
2018-03-23 12:54:42,955 fail2ban.actions [9756]: NOTICE [sshd] [my ip] already banned
2018-03-23 12:54:52,074 fail2ban.action [9756]: ERROR iptables -w -n -L INPUT | grep -q 'f2b-sshd[ \t]' -- stdout: ''
2018-03-23 12:54:52,075 fail2ban.action [9756]: ERROR iptables -w -n -L INPUT | grep -q 'f2b-sshd[ \t]' -- stderr: ''
2018-03-23 12:54:52,075 fail2ban.action [9756]: ERROR iptables -w -n -L INPUT | grep -q 'f2b-sshd[ \t]' -- returned 1
2018-03-23 12:54:52,075 fail2ban.CommandAction [9756]: ERROR Invariant check failed. Trying to restore a sane environment
2018-03-23 12:54:52,180 fail2ban.action [9756]: ERROR iptables -w -D INPUT -p tcp -m multiport --dports ssh -j f2b-sshd
iptables -w -F f2b-sshd
iptables -w -X f2b-sshd -- stdout: ''
2018-03-23 12:54:52,181 fail2ban.action [9756]: ERROR iptables -w -D INPUT -p tcp -m multiport --dports ssh -j f2b-sshd
iptables -w -F f2b-sshd
iptables -w -X f2b-sshd -- stderr: "iptables v1.4.21: Couldn't load target `f2b-sshd':No such file or directory\n\nTry `iptables -h' or 'iptables --help' for more information.\niptables: No chain/target/match by that name.\niptables: No chain/target/match by that name.\n"
2018-03-23 12:54:52,181 fail2ban.action [9756]: ERROR iptables -w -D INPUT -p tcp -m multiport --dports ssh -j f2b-sshd
iptables -w -F f2b-sshd
iptables -w -X f2b-sshd -- returned 1
2018-03-23 12:54:52,181 fail2ban.actions [9756]: ERROR Failed to execute unban jail 'sshd' action 'iptables-multiport' info '{'matches': '2018-03-23T11:53:46.707058149-210-194-176.colo.transip.net sshd[27676]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=ip-[my ip].ip.prioritytelecom.net user=root2018-03-23T11:53:48.733188149-210-194-176.colo.transip.net sshd[27676]: Failed password for root from [my ip] port 31224 ssh22018-03-23T11:54:51.709842149-210-194-176.colo.transip.net sshd[27676]: Failed password for root from [my ip] port 31224 ssh2', 'ip': '[my ip]', 'time': 1521802491.930057, 'failures': 3}': Error stopping action
ログファイルを追跡すると、sshログイン試行が記録されていることがわかりますが、3回目の試行の後に続行できます。たとえば、10回目の試行後に正しいパスワードを使用するとログインできます。
また、ログファイルの最後にエラーが表示されることもあります。
私の地域の刑務所:
[DEFAULT]
#ban n hosts for one hour:
bantime = 3600
#maxtrys
maxretry = 3
# Override /etc/fail2ban/jail.d/00-firewalld.conf:
banaction = iptables-multiport
[sshd]
enabled = true
なぜこれが起こるのか知っている人がいますか?
答え1
iptables
設定に名前のあるフィルタチェーンがないようですf2b-sshd
。
まずは簡単な紹介ですiptables
。
iptables
Linux ファイアウォールサブシステムのコマンドと名前です。このコマンドは、RAMにファイアウォールルールを設定するために使用されます。ファイアウォールiptables
ルールは最初にテーブルでソートされます。基本テーブルがありますが、さまざまな目的のために、およびテーブルもfilter
あります。はトラフィックフィルタリングを実行するため、テーブルを使用します。nat
mangle
raw
security
fail2ban
filter
その後、これらのテーブルはフィルタチェーンに分けられます。各テーブルには特定の標準チェーンがあります。filter
テーブルの場合、標準チェーンは、INPUT
およびFORWARD
ですOUTPUT
。FORWARD
このチェーンは、システムが他のシステムへのトラフィックをルーティングするように構成されている場合にのみ使用されます。このINPUT
チェーンはシステムに着信トラフィックを処理します。
fail2ban
ルールがチェーンに直接追加され、すべてのINPUT
禁止が期限切れになった場合、チェーンが完全にクリアされた場合は、ファイアウォール入力ルールに対するすべての制御を渡す必要があります。fail2ban
カスタムファイアウォールルールを簡単に持つことはできません。またfail2ban
効果は何ですか?これは明らかに望ましくないのでfail2ban
実行されない。
代わりに、fail2ban
完全に自己管理可能な独自のフィルタチェーンを作成し、起動時にチェーンに単一のルールを追加して、処理のためにチェーンを介してINPUT
一致するトラフィックを送信します。fail2ban
たとえば、protectedとして設定した場合は、sshd
起動時fail2ban
に次のコマンドを実行する必要があります。
iptables -N f2b-sshd
iptables -A f2b-sshd -j RETURN
iptables -I INPUT -p tcp -m multiport --dports <TCP ports configured for sshd protection> -j f2b-sshd
これらのコマンドはf2b-sshd
フィルタチェーンを作成し、最後のルールに設定されますRETURN
。したがって、fail2ban
ルールが処理されると、INPUTルールの通常の処理は不完全なように続き、fail2ban
最後にテーブルの先頭にルールを追加してINPUT
キャプチャします。すべてのSSHトラフィックを処理し、まずf2b-sshd
チェーンに送信します。
fail2ban
SSHのIPアドレスを禁止する必要がある場合は、f2b-sshd
チェーンに新しいルールを挿入するだけです。
iptables またはファイアウォールルールを管理する他のシステムを使用するfirewalld
場合、またはすべてのルールを手動でクリアすると、これらのiptables
初期ルールとフィルタチェーン全体がf2b-sshd
消去される可能性があります。使用するすべてのファイアウォール管理ツールがINPUTチェーンの初期ルールを維持し、このチェーンにf2b-sshd
全く触れないようにする必要があります。
コードスニペットの最後にあるエラーメッセージは、fail2ban
初期ルールがまだ存在していることを確認している(「不変性チェック」)が存在しないことが確認されたことを示しています。
答え2
問題は、ブロックは機能していますが、攻撃者が継続的な接続を使用しているため、ブロックがまだ接続されており、新しい接続がないため、ブロックがすぐに適用されないことです。これが起こる唯一の方法は、メールサーバーを再起動することです。
答え3
私はこの問題を処理する必要がありました。この問題は exim4 failure2ban チュートリアルに従うことに関連しています。 Jail.d/exim4.conf ファイルには、次の内容が含まれています。
[exim-spam]
port = smtp,ssmtp
exim4がポート25、464で実行されているため、実際に必要な場合そして587は次のとおりです。
[exim-spam]
port = smtp,ssmtp,587
それはすべてです。
デフォルトでは、すべてのフィルタが正しく設定され、すべてがうまく機能します。しかし、次のようになります。
- 攻撃はポート587で発生します。
- 構成ファイルは、Fail2banにポート25と465のみをブロックするように指示します。
もちろん攻撃は続くでしょう!したがって、使用しているプロトコル(この場合はsshd)に合わせて調整してください。
"netstat -an | more"、"iptables -L -n"、"lsof -i:587"は友達です。