Fail2banとアップストリームサーバーのアクションの無効なログイン試行を記録する

I was hoping Discourse could log invalid login attempts to file, even if it is something you have to configure to do so. Then I could create a custom filter and jail for discourse

I use a centralized fail2ban server. the way it works is all my Containers, Docker images, VMs have a custom ban action:

in fail2ban you specify the action to take in your jail, such as:
action = iptables-allports

then all you have to do is edit that action:
sudo nano /etc/fail2ban/action.d/iptables-allports.conf

actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
      curl -s "https://fail2ban.YourDomain.com:35553/fail2ban.php?token=D2f3Ydy45f6y5FRTfyeFrtYErt&action=add&source=TEST_HOST&reason=TEST_FILTER&ip=111.222.333.444"

With this setup your container/docker/vm will fail2ban them locally, but it will also relay this information to your central fail2ban server. The central server can also take all collected IPs and make them available as txt banlist such as: https://fail2ban.YourDomain.com/banned.txt

Then you can have your pfsense firewall subscribe to this banlist, and you can even share the list with other pfsense routers. This way if they try breaking in on one application, they get banned from everything. This has worked great for me for years.

And all that I need to implement this for discourse is for discourse to write an entry to a log file when there is an invalid login attempt :slight_smile:

「いいね!」 1

did you figure out how to hook or log this?

Thanks

「いいね!」 1

Bump. This seems like a very good idea!

Where does Discourse store and show logs?

The NGINX logs
Occasionally NGINX logs may contain some extra tips, they are located at:

cd /var/discourse
./launcher enter app
cd /var/log/nginx
The files access.log and error.log will be there as well as a bunch of rotated compressed files. Running less access.log.2.gz will automatically decompress and display the logfile for you.

This directory is also available on the host at /var/discourse/shared/standalone/log/var-log/nginx .

Unfortunately, the nginx error.log and access.log files do not log any invalid login attempts.

Can anyone suggest another avenue?

Thank you.

「いいね!」 1

Agree. It would be great to hook into a fail2ban kind of automated exponential backoff.

「いいね!」 1

curious - この機能リクエストはまだ追跡または計画されていますか?セキュリティ機能として役立つでしょう。

IPアドレスによるログイン失敗のログ(またはフック)

ありがとうございます!

「いいね!」 1

nginx の access.log ファイルには、このために必要なログイン ルートへの 403 レスポンスを含む行があるはずです。ログを確認しましたか?

「いいね!」 1

ああ、ありがとうございます!Dockerイメージ/コンテナの外部からそれにアクセスするにはどうすればよいのでしょうか?

こんにちは @Falco 返信ありがとうございます。すぐにログを確認しましたが、正しいパスワードの試行と間違ったパスワードの試行は、私には同じように見えます(200応答):

(IPアドレスとドメインはサニタイズしましたが、残りはそのままです)

パスワード間違い:

[20/Dec/2021:08:07:31 -0800] "community.example.com" 10.111.222.33 "GET /session/csrf HTTP/1.1" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0" "session/csrf" 200 1185 "https://community.example.com/" 0.016 0.017 "-"
[20/Dec/2021:08:07:32 -0800] "community.example.com" 10.111.222.33 "POST /session HTTP/1.1" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0" "session/create" 200 1111 "https://community.example.com/" 0.552 0.550 "-"

パスワード正解:

[20/Dec/2021:08:24:50 -0800] "community.example.com" 10.111.222.33 "GET /session/csrf HTTP/1.1" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0" "session/csrf" 200 1185 "https://community.example.com/" 0.020 0.020 "-"
[20/Dec/2021:08:24:51 -0800] "community.example.com" 10.111.222.33 "POST /session HTTP/1.1" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0" "session/create" 200 2251 "https://community.example.com/" 1.216 1.216 "-"

したがって、どちらも200応答を返しているため、fail2banには使用できません。正しいパスワードと間違ったパスワードの両方のユーザーをBANすることになります。

「いいね!」 2

Twitter はパスワード間違いで 400 を返しますが、Facebook、LinkedIn、Google、Amazon は 200 を返します。IMO では 200 は間違っているように聞こえますが、「普通」のことのようです。

もしかしたら、ここのメソッドにフックするプラグインから始めることができるかもしれません。

そして、必要なことを行うのですか?

「いいね!」 3

素晴らしい、返信ありがとうございます!少しでも時間があれば、この情報を生成するプラグインを作成してみます!(必要なのは、パスワードを間違えてログインしようとしたときにIPアドレスがファイルに記録されることだけです。例:「無効なログイン試行、IP 10.111.222.33」)

「いいね!」 3

ありがとうございます!このプラグインを使用できることを願っています。利用可能にできるかどうか教えてください。

これが機能したことはありますか?私も Discourse インスタンスで fail2ban を使用することに非常に興味があります。

自己作成ウェブマスターと純粋なエンドユーザーの役割について書いていますが…

定義上、無効なログインはエラー200です。もちろん、アプリの内部エラーである可能性があり、またそうあるべきであり、ある時点でエラー403や回復リンクの送信のような別のものを生成するかもしれませんが、それはすぐに起こるべきではありませんし、起こることもできません。

Fail2banは良いツールですが、過大評価されています。Dockerはすべてを難しくするので忘れるとして、VPSのiptablesをバイパスできるという事実だけで、私にとっては非常に曖昧なことです。しかし、ボットは3回目の試行ごとにIPを変更する傾向があり、これにより、ログインによる純粋な総当たり攻撃に対してFail2banはかなり無力になります。

もちろん、スクリプトキディは別の話です。彼らは見つけたものをすべてコピー&ペーストし、少し変更してIPを操作しません。その場合、Fail2banはそれらを停止できます。彼らが害をなすことはめったにありませんが、負荷は増加します。本当の問題は、即座の洪水が発生した場合のスクリプトキディの数です。

しかし、VPSがそのような状況を処理できる限り、それは問題ではありません。今は2023年であり、ほとんどのこれらのアホは、ディスコースサイトのWordPressの古い脆弱性を攻撃しています :wink:

しかし、それが日常的な脅威ではないとしても、絶え間ないログインを停止するための何らかのロジックを持つべきだと思います。