Manual マニュアル

Contents内容

Introduction前書き

The problem問題

Brute-force break-in attempts are quite frequent against an SSH server and other password protected internet-services (such as ftp,pop,...). Automated scripts try multiple combinations of username/password (brute-force, dictionary attack) and sometimes changing the port to something other than the default can't be done. Furthermore, scouring your log files yourself is not only time consuming, but can be difficult too.ブルートフォースの侵入は、SSHサーバやその他のパスワードで保護されたインターネットサービス(ftp、popなど)に対してかなり頻繁に行われます。自動化されたスクリプトは、ユーザー名/パスワードの複数の組み合わせ(ブルートフォース、辞書攻撃)を試み、時にはデフォルト以外のものにポートを変更することはできません。さらに、ログファイルを自分で調べるのは時間がかかるだけでなく、困難になる可能性もあります。

Fail2ban attempts to alleviate these issues by providing an automated way of not only identifying possible break-in attempts, but acting upon them quickly and easily in a user-definable manner.Fail2banは、侵入の可能性のある試みを特定するだけでなく、ユーザーが定義できる方法で迅速かつ容易に対処する自動化された方法を提供することによって、これらの問題を軽減しようとします。

The solutionソリューション

Log files contain interesting information, especially about failed logins. This information can be used to ban an offensive host. This is exactly what Fail2ban does. It scans log files and detects patterns which correspond to possible breakin attempts and then performs actions. Most of the time, it consists of adding a new rule in a firewall chain and sending an e-mail notification to the system administrator.ログファイルには、特に失敗したログインに関する興味深い情報が含まれています。この情報は、攻撃的なホストを禁止するために使用される可能性があります。これがまさにFail2banがすることです。ログファイルをスキャンし、侵入の可能性がある試行に対応するパターンを検出してからアクションを実行します。ほとんどの場合、ファイアウォールチェーンに新しいルールを追加し、システム管理者に電子メール通知を送信することで構成されています。

Here is a list of the most important features available in Fail2ban:以下はFail2banで利用可能な最も重要な機能のリストです:

  • client/serverクライアントサーバー
  • multithreadedマルチスレッド
  • Gamin supportガミンサポート
  • autodetection of the date/time format日付/時刻フォーマットの自動検出
  • wildcard support in logpath optionlogpathオプションでのワイルドカードのサポート
  • support for a lot of services (sshd, apache, qmail, proftpd, sasl, asterisk, etc)多くのサービス(sshd、apache、qmail、proftpd、sasl、アスタリスクなど)のサポート
  • support for several actions (iptables, tcp-wrapper, shorewall, mail notifications, etc)いくつかのアクション(iptables、tcp-wrapper、shorewall、メール通知など)のサポート

The code has been completely rewritten since 0.6.x. Fail2ban is entirely written in Python and thus should work on most of the *nix systems.コードは0.6.xから完全に書き直されました。Fail2banは完全にPythonで書かれているので、ほとんどの* nixシステムで動作するはずです。

Installationインストール

Requirements必要条件

In order to use Fail2ban, the following software are required:Fail2banを使用するには、以下のソフトウェアが必要です。

  • Python >= 2.4Python> = 2.4

Warning: Python 2.4 does not re-open the syslog socket when it encounters a failure. This is a Python bug. If you want to use "logtarget = SYSLOG", please use a newer version of Python like 2.5.警告:Python 2.4は、失敗したときにsyslogソケットを再オープンしません。これはPythonのバグです。"logtarget = SYSLOG"を使用したい場合は、2.5などの新しいバージョンのPythonを使用してください。

The following software are optional but recommended:次のソフトウェアはオプションですが推奨されています。


You will probably need at least one firewall software like iptables or shorewall. If you want a software which is not supported, please feel free to contact the author.
あなたはおそらくiptablesshorewallのような少なくとも1つのファイアウォールソフトウェアを必要とするでしょう。サポートされていないソフトウェアが必要な場合は、作者に連絡してください。

Gamin is a file alteration monitor. Gamin greatly benefits from a "inotify"-enabled kernel. Thus, active polling is no longer required to get the file modifications.Gaminはファイル変更モニターです。Gaminは "inotify"対応のカーネルから大きな恩恵を受けます。したがって、ファイルの変更を取得するためにアクティブポーリングは必要なくなりました。

Installing from sources on a GNU/Linux systemGNU / Linuxシステム上のソースからのインストール

You will need to obtain the latest version of the source code in order to compile Fail2ban yourself. Once you have done this, change to the directory where you downloaded the source code and execute the following:Fail2banを自分でコンパイルするには、最新版のソースコードを入手する必要があります。これが終わったら、ソースコードをダウンロードしたディレクトリに移動して以下を実行してください。

tar xvjf fail2ban-x.x.x.tar.bz2

You will have the Fail2ban source code extracted to a directory under the current working directory. You must now move to the new directory.あなたは持っていますfail2banの現在の作業ディレクトリの下のディレクトリに抽出されたソースコードを。今すぐ新しいディレクトリに移動する必要があります。

Now run the installation script as root:今すぐrootとしてインストールスクリプトを実行します。

./setup.py install

Fail2ban should now be installed into /usr/share/fail2ban/ and /usr/bin/. You will also have to copy the content of config/ into /etc/fail2ban/ (not so in version 0.8.1). You are now ready to use the application.Fail2ban / usr / share / fail2ban / / usr / bin /にインストールされているはずです。また、 config /の内容を / etc / fail2ban /にコピーする必要があります(バージョン0.8.1ではそうではありません)。これでアプリケーションを使用する準備が整いました。

Integrate fail2ban into your INIT-Process:fail2banをあなたのINITプロセスに統合します。

Go into the files-folder where you extracted the sources:あなたがソースを抽出したfiles-folderに行きます:

# cd /usr/local/src/fail2ban-0.8.1/files

and copy the init-script fitting your distribution to /etc/init.d.そしてあなたのディストリビューションに合ったinitスクリプトを/etc/init.dにコピーしてください。

# cp suse-initd /etc/init.d/fail2ban
# chmod 755 /etc/init.d/fail2ban

Finally after copying/editing the init file, and adjusting the paths to fail2ban-client and fail2ban-server run chkconfig or update-rc.d or create the symbolic links manually...initファイルをコピー/編集し、fail2ban-clientとfail2ban-serverへのパスを調整した後、chkconfigまたはupdate-rc.dを実行するか、手動でシンボリックリンクを作成します。

chkconfig -a fail2ban

orまたは

update-rc.d fail2ban defaults

orまたは

ln -s /etc/init.d/fail2ban /etc/rc2.d/S20fail2ban ...

Integrate fail2ban into logrotate:fail2banをlogrotateに統合します。

create file "/etc/logrotate.d/fail2ban":ファイル "/etc/logrotate.d/fail2ban"を作成します。

/var/log/fail2ban.log {
    weekly
    rotate 7
    missingok
    compress
    postrotate
      /usr/local/bin/fail2ban-client set logtarget /var/log/fail2ban.log >/dev/null
    endscript
}

The path to your fail2ban-client might need to be adjusted (# whereis fail2ban-client)fail2ban-clientへのパスを調整する必要があるかもしれません(#whereis fail2ban-client)

Debian

Installing Fail2ban on a Debian based system is very straightforward, just install the package through Synaptic orDebianベースのシステムにFail2banをインストールするのは非常に簡単です。単にSynapticまたは

apt-get install fail2ban

Gentoo

Fail2ban is available in Portage. To install it, just run:Fail2ban Portageで利用可能です。インストールするには、単に実行してください:

emerge fail2ban

The FAQ has a more detailed explanation of installing using distributions such as Debian, Red Hat and GentooFAQは、等分布使用したインストールの詳細な説明有しのDebianレッドハットGentooを

Fedora

Installing Fail2ban on a Fedora 9+ based system is usually straightforward. Execute the following code as the root user:Fedora 9+ベースのシステムにFail2banをインストールするのは、通常簡単です。rootユーザーとして次のコードを実行します。

yum install fail2ban

There is a bug with the current (0.8.4-27) Fedora and RedHat distros [1] which will prevent jails from starting unless SELinux is disabled. Symptoms are that a server with no configuration changes will fail to start and the fail2ban log file (search for 'logtarget' in fail2ban.conf) will have an error message like:現在の(0.8.4-27)FedoraおよびRedHatディストリビューション[1]にはバグがありますこれはSELinuxが無効にされていない限り、jailの起動を妨げます。症状は、設定が変更されていないサーバーは起動に失敗し、fail2banログファイル(fail2ban.confで 'logtarget'を検索)に次のようなエラーメッセージが表示されることです。

fail2ban.jail   : INFO   Creating new jail 'ssh-iptables'
fail2ban.comm   : WARNING Invalid command: ['add', 'ssh-iptables', 'auto'] 

when starting the SSH jail. If this happens to you, edit jail.conf and change the line that saysSSH刑務所を開始するとき。これが起きた場合は、jail.confを編集して次の行を変更してください。

backend = auto

to

backend = gamin

This requires gamin to be installed. If it isn't, install it via:これにはGaminのインストールが必要です。そうでない場合は、次のようにインストールしてください。

yum install gamin

Alternatively you can disable SELinux, but that is not recommended.あるいはSELinuxを無効にすることもできますが、これはお勧めできません。

Mac OS X

See HOWTO Mac OS X Server (10.4)
or HOWTO Mac OS X Server (10.5)HOWTO Mac OS X Server(10.4)
またはHOWTO Mac OS X Server(10.5)を参照してください。

Usage使用法

Definitions定義

Before we begin, it is important to clarify some terms used in the following sections.始める前に、次のセクションで使用されているいくつかの用語を明確にすることが重要です。

filterフィルタ  : a filter defines a regular expression which must match a pattern corresponding to a log-in failure or any other expressionフィルタは、ログイン失敗または他の表現に対応するパターンにマッチしなければならない正規表現を定義します
actionアクション  : an action defines several commands which are executed at different momentsアクションは異なる瞬間に実行されるいくつかのコマンドを定義します
jail刑務所  : a jail is a combination of one filter and one or several actions. Fail2ban can handle several jails at the same time刑務所は、1つのフィルタと1つまたは複数のアクションの組み合わせです。Fail2banは複数の刑務所を同時に処理できます
clientクライアント  : refers to the script fail2ban-clientスクリプトfail2ban-clientを参照する
serverサーバ  : refers to the script fail2ban-serverスクリプトfail2ban-serverを参照する

Serverサーバ

Fail2ban is composed of 2 parts: a client and a server. The server is multi-threaded and listens on a Unix socket for commands. The server itself knows nothing about the configuration files. Thus, at start-up, the server is in a "default" state in which no jails are defined. The following options are available for fail2ban-server:Fail2banは、クライアントとサーバーの2つの部分で構成されています。サーバーはマルチスレッドであり、コマンドをUnixソケットで待機します。サーバー自体は構成ファイルについては何も知りません。したがって、起動時には、サーバーはjailが定義されていない「デフォルト」状態になります。fail2ban-serverには以下のオプションがあります

-b                   start in background
-f                   start in foreground
-s <FILE>            socket path
-x                   force execution of the server
-h, --help           display this help message
-V, --version        print the version

fail2ban-server should not be used directly except in case of debugging. The option -s <FILE> is probably the most important one and is used to set the socket path. Thus, it is possible to run several instances of Fail2ban on different sockets. However, this should be not required because Fail2ban can run several jails concurrently.fail2ban-serverはデバッグの場合を除いて直接使われるべきではありません。オプション-s <FILE>はおそらく最も重要なものであり、ソケットパスを設定するために使用されます。したがって、Fail2banのいくつかのインスタンスを異なるソケットで実行することが可能です。ただし、Fail2banは複数のjailを同時に実行できるため、これは必須ではありません。

If fail2ban-server crashes (does it?), it is possible that the socket file has not been removed correctly. The -x option tells the server to delete the socket file before start-up. If the socket file of a running server is removed, it is not possible to communicate with this server anymore.fail2ban-serverがクラッシュした場合(そうですか?)、ソケットファイルが正しく削除されていない可能性があります。-xオプションは、起動前にソケットファイルを削除するには、サーバーに指示します。実行中のサーバーのソケットファイルを削除すると、このサーバーと通信できなくなります。

The server handles the signals SIGTERM and SIGINT. When receiving one of these signals, fail2ban-server will quit nicely.サーバーはシグナルSIGTERMSIGINTを処理します。これらのシグナルの1つを受け取るとき、fail2ban-serverはうまく終了します

Clientクライアント

fail2ban-client is the frontend of Fail2ban. It connects to the server socket file and sends commands in order to configure and operate the server. The client can read the configuration files or can simply be used to send a single command to the server using either the command line or the interactive mode (which is activated with the -i option). fail2ban-client can also start the server. The following options are available for fail2ban-client:fail2banのクライアントは、のフロントエンドですfail2banの。それはサーバソケットファイルに接続し、サーバを設定し、操作するためにコマンドを送ります。クライアントは設定ファイルを読み込むことも、コマンドラインまたは対話モード(-iオプションで有効になるモード)を使用してサーバーに単一のコマンドを送信することもできます。fail2ban-clientはサーバを起動することもできます。fail2ban-clientでは、以下のオプションが利用可能です

-c <DIR>                configuration directory
-s <FILE>               socket path
-d                      dump configuration. For debugging
-i                      interactive mode
-v                      increase verbosity
-q                      decrease verbosity
-x                      force execution of the server
-h, --help              display this help message
-V, --version           print the version

As for fail2ban-server, the option -s <FILE> can be used to set the socket path. Notice that this command line option overrides the socket option set in fail2ban.conf. The default configuration directory is /etc/fail2ban but can be override with the -c <DIR> option. The -x option is simply forwarded to fail2ban-server when starting the server.fail2banのサーバー、オプション-s <FILE>はソケットのパスを設定するために使用することができます。このコマンドラインオプションは、fail2ban.confで設定されたソケットオプションを上書きすることに注意してください。デフォルトの設定ディレクトリは/ etc / fail2banですが、-c <DIR>オプションで上書きできます。-xオプションは、単純に転送され、サーバーをfail2banのサーバーを起動するとき。

A useful option for debugging is -d. This prints the configuration parsed by fail2ban-client. The output corresponds to the stream sent to the server. If the output of -d shows:デバッグに役立つオプションは-dです。これはfail2ban-clientによって解析された設定を表示します。出力はサーバーに送信されたストリームに対応します。-dの出力が次のようになっているとします。

['set', 'loglevel', 1]
['set', 'logtarget', 'STDERR']

It is possible to achieve the same with:次のようにしても同じことが可能です。

$ fail2ban-client set loglevel 1
$ fail2ban-client set logtarget STDERR

Everything set in the configuration files can be configured manually. The configuration is just a simple and efficient way to configure the server. fail2ban-client only translates the configuration into a suite of commands. However, fail2ban-client has 2 more commands for its internal use. The first one is start. When typing:設定ファイルに設定されているものはすべて手動で設定できます。設定は、サーバを設定するための単純で効率的な方法です。fail2ban-clientは設定を一連のコマンドに変換するだけです。ただし、fail2ban-clientには、内部使用のためのコマンドがさらに2つあります。最初のものはスタートです。入力時:

$ fail2ban-client start

the client will first try to fork a server instance. The client then waits for the server to start-up by sending ping requests to it. Once the server responds to these requests, fail2ban-client parses the configuration and sends the corresponding commands to the server. The second one is reload. When typing:クライアントは最初にサーバーインスタンスをforkしようとします。その後、クライアントはping要求を送信してサーバーが起動するのを待ちます。サーバがこれらの要求に応答すると、fail2ban-clientは設定を解析して対応するコマンドをサーバに送信します。二つ目はリロードです。入力時:

$ fail2ban-client reload

the client will tell the server to stop all jails, parses the configuration files again and send the commands to the server. This is useful when a new configuration must be loaded without shutting down the server. This is also very useful when debugging the server. It is possible to start the server with fail2ban-server -f in one terminal and to load the configuration by typing fail2ban-client reload in an other one. Thus, client and server output will not be mixed up.クライアントは、すべてのjailを停止するようにサーバーに指示し、設定ファイルを再度解析してサーバーにコマンドを送信します。これは、サーバーをシャットダウンせずに新しい構成をロードする必要がある場合に役立ちます。これはサーバーをデバッグするときにも非常に便利です。一方の端末でfail2ban-server -fを使用してサーバーを起動し、もう一方の端末でfail2ban-client reloadと入力して設定を読み込むことができます。したがって、クライアントとサーバーの出力は混同されません。

Any other commands are simply sent to the server without any specific treatment. However, most of the time, only the 2 above commands and stop will be used.他のコマンドは、特別な処理なしにサーバーに送信されます。ただし、ほとんどの場合、上記の2つのコマンドとstopだけが使用されます。

There is probably one last useful command: status [jail]. Without a jail name, the global status of the server is returned. If jail corresponds to an existing jail, the status of this jail is displayed.おそらく最後に便利なコマンドがもうひとつありますstatus [jail]。jail名がないと、サーバーのグローバルステータスが返されます。jailが既存のjailに対応している場合は、このjailのステータスが表示されます。

A list with all commands is available here.すべてのコマンドのリストはここにあります

Configuration設定

The standard path for the configuration is in /etc/fail2ban. This can be set with the -c option of fail2ban-client. A typical configuration looks like this:設定の標準パスは/ etc / fail2banです。これはfail2ban-clientの-cオプションで設定できます。一般的な構成は次のようになります。

/etc/fail2ban/
├── action.d
│   ├── dummy.conf
│   ├── hostsdeny.conf
│   ├── iptables.conf
│   ├── mail-whois.conf
│   ├── mail.conf
│   └── shorewall.conf
├── fail2ban.conf
├── fail2ban.local
├── filter.d
│   ├── apache-auth.conf
│   ├── apache-noscript.conf
│   ├── couriersmtp.conf
│   ├── postfix.conf
│   ├── proftpd.conf
│   ├── qmail.conf
│   ├── sasl.conf
│   ├── sshd.conf
│   └── vsftpd.conf
├── jail.conf
└── jail.local

Every .conf file can be overridden with a file named .local. The .conf file is read first, then .local, with later settings overriding earlier ones. Thus, a .local file doesn't have to include everything in the corresponding .conf file, only those settings that you wish to override.すべての.confファイルは、.localという名前のファイルでオーバーライドできます。.confののファイルは、最初に読み込まれる.localという以前のものを上書きし、後で設定で、。したがって、.localファイルは、対応する.confファイルにすべてを含める必要はなく、上書きしたい設定のみを含めます。

Modifications should take place in the .local and not in the .conf. This avoids merging problem when upgrading. These files are well documented and detailed information should be available there.変更は.locではなく.localで行う必要があります。これにより、アップグレード時のマージ問題が回避されます。これらのファイルは十分に文書化されており、詳細な情報がそこにあります。

General settings一般設定

The file fail2ban.conf contains general settings for the fail2ban-server daemon, such as the logging level and target. You can also specify here the socket path used for communication between the client and the server.ファイルfail2ban.confには、ロギングレベルやターゲットなど、fail2ban-serverデーモンの一般設定が含まれています。クライアントとサーバー間の通信に使用されるソケットパスもここで指定できます。

Jails刑務所

The most important file is probably jail.conf, which contains the declaration of your jails. By default, some sections are inserted as templates. You must enable the sections of interest and adapt to your local configuration. Here is an example of the ssh-iptables section:最も重要なファイルはおそらくjail.confです。これにはあなたのjailの宣言が含まれています。デフォルトでは、一部のセクションはテンプレートとして挿入されています。あなたは興味のあるセクションを有効にしてあなたのローカルな設定に適応する必要があります。これはssh-iptablesセクションの例です。

[ssh-iptables]
#enabled  = false
enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
#          mail-whois[name=SSH, dest=yourmail@mail.com]
#logpath  = /var/log/sshd.log
logpath  = /var/log/auth.log
maxretry = 5
With these settings a few things will happen:
  1. the section ssh-iptables is enabled;セクションssh-iptablesが有効になっています。
  2. the filter sshd.conf in sub-directory filter.d will be processed;サブディレクトリfilter.d内のフィルタsshd .confが処理されます。
  3. the action(s) described in iptables.conf (sub-directory action.d) will be executed if the outcome of the filter process is true. In this example, the additional action mail-whois.conf is commented out.フィルタ処理の結果が真の場合、iptables .conf(サブディレクトリaction.d)に記述されているアクションが実行されます。この例では、追加アクションmail-whois .confがコメントアウトされています。
  4. the log file to be scanned by the filter is auth.log.フィルタによってスキャンされるログファイルはauth.logです。

Filter and actions are combined to create jails. Only one filter is allowed per jail, but it is possible to specify several actions, on separate lines. For example, you can react to a SSH break-in attempt by first adding a new firewall rule, then retrieving some information about the offending host using whois and finally sending an e-mail notification. Or maybe you just want to received a notification on your Jabber account when someone accesses the page /donotaccess.html on your web server.フィルタとアクションを組み合わせて刑務所を作成します。1つのjailに許可されるフィルタは1つだけですが、別々の行に複数のアクションを指定することは可能です。たとえば、最初に新しいファイアウォールルールを追加し、次にwhoisを使用して問題のあるホストに関する情報を取得し、最後に電子メール通知を送信することで、SSHの侵入に対処することができます。または、Webサーバーの/donotaccess.htmlページにアクセスしたときに、Jabberアカウントで通知を受け取りたい場合もあります。

Fail2ban is not limited to SSH. It contains default filters and actions for many daemons and services. You can easily modify them or create new ones. If you take a look in the filter.d you will notice a few default filters that don't occur in the standard jail.conf that come with the sources. In this example we take the "sshd-ddos.conf". To integrate the filter into fail2ban edit your jail.conf:Fail2banはSSHに限定されません。多くのデーモンやサービスに対するデフォルトのフィルタやアクションが含まれています。あなたはそれらを簡単に修正したり新しいものを作成することができます。filter.dを見てみると、標準のjail.confには含まれていない、ソースに付属しているデフォルトのフィルタがいくつかあります。この例では "sshd-ddos.conf"を取ります。フィルタをfail2banに統合するには、jail.confを編集してください。

[ssh-ddos]
enabled = true
port    = ssh,sftp
filter  = sshd-ddos
logpath  = /var/log/messages
maxretry = 2

Always remember to adjust $logpath to your log-file as mentioned above.上記のように、常に$ logpathをあなたのログファイルに調整することを忘れないでください。

Jail Options刑務所のオプション

Every jail can be customized by tuning following options:以下のオプションを調整することで、すべての刑務所をカスタマイズできます。

Jail Options
Name Defaultデフォルト Description説明
filterフィルタ Name of the filter to be used by the jail to detect matches. Each single match by a filter increments the counter within the jail一致を検出するためにjailによって使用されるフィルタの名前。フィルタによる各一致は、jail内のカウンタをインクリメントします
logpathログパス /var/log/messages/ var / log / messages Path to the log file which is provided to the filterフィルタに提供されるログファイルへのパス
maxretry 3 Number of matches (i.e. value of the counter) which triggers ban action on the IP.IPに対する禁止措置を引き起こす一致の数(つまりカウンタの値)。
findtime 600 sec600秒 The counter is set to zero if no match is found within "findtime" seconds.「findtime」秒以内に一致が見つからない場合、カウンタはゼロに設定されます。
bantime辛い 600 sec600秒 Duration (in seconds) for IP to be banned for. Negative number for "permanent" ban.IPが禁止される期間(秒単位)。「恒久的な」禁止の負の数

Filtersフィルター

The directory filter.d contains mainly regular expressions which are used to detect break-in attempts, password failures, etc. Here is an example for filter.d/sshd.conf with 3 possible regular expressions to match the lines of the logfile:ディレクトリfilter.dには、侵入の試み、パスワードの失敗などを検出するために使用される主に正規表現が含まれています。これは、logfileの行に一致する3つの可能な正規表現を含むfilter.d / sshd.confの例です。

failregex = Authentication failure for .* from <HOST>
            Failed [-/\w]+ for .* from <HOST>
            ROOT LOGIN REFUSED .* FROM <HOST>
            [iI](?:llegal|nvalid) user .* from <HOST>

In the above example the default regex has been changed to allow the absence of user in a line such as:上記の例では、デフォルトの正規表現は次のような行にユーザーがいないように変更されています。

Jan 10 07:02:37 homebrou sshd[18419]: Failed password for root from 222.76.213.151 port 55236 ssh2

If you're creating your own failregex expressions, here are some things you should know:独自のfailregex式を作成しているのなら、知っておくべきことがいくつかあります。

  • A failregex can have multiple lines, any one of which may match a line of the log file.failregexは複数の行を持つことができ、そのうちの1つがログファイルの1行と一致する可能性があります。
  • In every line of failregex, the part that matches the host name or IP address must be wrapped in a (?P<host> ... ) sandwich. This is a Python-specific regex extension that assigns the contents of the match to the name <host>. The <host> tag is how you tell fail2ban which host was connecting, so it has to be present in every line of failregex. If it's not, fail2ban will issue an error message about "No 'host' group".failregexのすべての行で、ホスト名またはIPアドレスと一致する部分はサンドイッチで囲む必要があります(?P<host> ... )。これはPython固有の正規表現の拡張で、一致の内容を名前<host>に割り当てます。<host>タグは、どのホストが接続していたかをfail2banに指示する方法です。そのため、failregexのすべての行に存在する必要があります。そうでない場合、fail2banは "No 'host' group"に関するエラーメッセージを出します。
  • As a convenience, you can use the predefined entity <HOST> in your regexes. <HOST> is an alias for (?:::f{4,6}:)?(?P<host>\S+), which matches either a hostname or an IPv4 address (possibly embedded in an IPv6 address).便宜上、<HOST>正規表現で事前定義済みのエンティティを使用できます。<HOST>のエイリアスで(?:::f{4,6}:)?(?P<host>\S+)、ホスト名またはIPv4アドレス(おそらくIPv6アドレスに埋め込まれている)に一致します。
  • In the action scripts, the tag <ip> will be replaced by the IP address of the host that was matched in the <host> tag.アクションスクリプトでは、タグ<ip><host>タグ内で一致したホストのIPアドレスに置き換えられます。
  • In order for a log line to match your failregex, it actually has to match in two parts: the beginning of the line has to match a timestamp pattern or regex, and the remainder of the line has to match your failregex. If the failregex is anchored with a leading ^, then the anchor refers to the start of the remainder of the line, after the timestamp and intervening whitespace.ログ行があなたのfailregexにマッチするためには、実際には2つの部分でマッチしなければなりません:行の始めはタイムスタンプパターンまたはregexとマッチし、行の残りはあなたのfailregexとマッチしなければなりません。failregexが先行文字で固定されている^場合、アンカーはタイムスタンプとそれ続く空白のの行の残りの部分の開始を表します。
  • The pattern or regex to match the time stamp is currently not documented, and not available for users to read or set. See Debian bug #491253. This is a problem if your log has a timestamp format that fail2ban doesn't expect, since it will then fail to match any lines. Because of this, you should test any new failregex against a sample log line, as in the examples below, to be sure that it will match. If fail2ban doesn't recognize your log timestamp, then you have two options: either reconfigure your daemon to log with a timestamp in a more common format, such as in the example log line above; or file a bug report asking to have your timestamp format included.タイムスタンプと一致するパターンまたは正規表現は現在文書化されておらず、ユーザーが読んだり設定したりすることはできません。Debianバグ#491253を見てください。あなたのログがfail2banが期待していないタイムスタンプフォーマットを持っているなら、これは問題になります。このため、以下の例に示すように、サンプルのログ行に対して新しいfailregexをテストして、一致することを確認する必要があります。fail2banがあなたのログのタイムスタンプを認識しない場合は、二つの選択肢があります:上記のログ行の例のように、もっと一般的なフォーマットでタイムスタンプを記録するようにデーモンを再設定します。タイムスタンプのフォーマットを含めるように依頼するバグレポートを提出する。

As an example of the above points, run the following commands in your console and compare the results:上記の例として、コンソールで次のコマンドを実行して結果を比較します。

fail2ban-regex 'Jul 18 12:13:01 [1.2.3.4] authentication failed'     'authentication failed'
fail2ban-regex 'Jul 18 12:13:01 [1.2.3.4] authentication failed'     '\[<HOST>\] authentication failed'
fail2ban-regex '18-07-2008 12:13:01 [1.2.3.4] authentication failed' '\[<HOST>\] authentication failed'
fail2ban-regex '18-7-2008 12:13:01 [1.2.3.4] authentication failed'  '\[<HOST>\] authentication failed'

The 1st command fails, with a "No 'host' group" error message. The 2nd command succeeds, and finds the host address 1.2.3.4. The 3rd command succeeds, and finds the host address 1.2.3.4 (at least with v0.8.4). The 4th command fails. It does tell you why---it says "...no valid date/time found for..."---and clearly it's not able to match the unusual timestamp format---which is not part of your failregex.1番目のコマンドが失敗し、 "No 'host' group"エラーメッセージが表示されます。2番目のコマンドは成功し、ホストアドレス1.2.3.4を見つけます。3番目のコマンドは成功し、ホストアドレス1.2.3.4を見つけます(少なくともv0.8.4の場合)。4番目のコマンドは失敗します。理由はわかりません---「...に有効な日付/時刻が見つかりません...」と表示されます---そして、異常なタイムスタンプ形式と一致させることはできません ---これはfailregexの一部ではありません

Actions行動

The directory action.d contains different scripts defining actions. The actions are executed at well-defined moments during the execution of Fail2ban: when starting/stopping a jail, banning/unbanning a host, etc.ディレクトリaction.dには、アクションを定義するさまざまなスクリプトが含まれています。アクションはFail2banの実行中に明確に定義された瞬間に実行されます。刑務所の開始/停止、ホストの禁止/禁止解除など。

Testingテスト

Many things can be tested after configuration but the following commands can help to verify your settings:設定後に多くのことをテストできますが、次のコマンドを使用して設定を確認できます。

# fail2ban-client -d

will dump the current configuration.現在の設定をダンプします。

# fail2ban-regex "line" "failregex"

will test a single regular expression failregex (such as given in sshd.conf) with a single line of your logfile. Don't forget the double quotes around your line and failregex definitions.テストする単一の正規表現failregexを(に与えられたようなsshd.confで)単一あなたのログファイルの行。行の前後の二重引用符とfailregexの定義を忘れないでください。

fail2ban-regex accepts files too. Thus, it is easier to test and debug your own regular expressions.fail2ban-regexもファイルを受け付けます。したがって、独自の正規表現をテストしてデバッグする方が簡単です。

# fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf

You can use a combination of both:両方を組み合わせて使用??できます。

# fail2ban-regex /var/log/auth.log "Failed [-/\w]+ for .* from <HOST>"

Limitations制限事項

Reaction time反応時間

First of all, remember that Fail2ban is a log parser. It cannot do anything before something is written in the log files. Lots of syslog daemons buffer their outputs. This can impact performance of Fail2ban. Thus, it could be good to disable buffering of your syslog daemon.まず第一に、Fail2banはログパーサーであることを忘れないでください。ログファイルに何かが書き込まれるまでは、何もできません。たくさんのsyslogデーモンがそれらの出力をバッファします。これはFail2banのパフォーマンスに影響を与える可能性があります。したがって、syslogデーモンのバッファリングを無効にすることをお勧めします。

It is quite difficult to evaluate the reaction time. Fail2ban waits 1 second before checking for new logs to be scanned. This should be fine in most cases. However, it is possible to get more login failures than specified by maxretry.反応時間を評価することは非常に困難です。Fail2banは新しいログがスキャンされるのを確認する前に1秒待ちます。ほとんどの場合、これで問題ありません。ただし、maxretryで指定されているよりも多くのログイン失敗が発生する可能性があります。

Here is an excerpt of a /var/log/auth.log:これは/var/log/auth.logの抜粋です。

Jan 15 15:28:46 homebrou sshd[29778]: Invalid user recruit from 81.74.87.66
Jan 15 15:28:46 homebrou sshd[29778]: error: Could not get shadow information for NOUSER
Jan 15 15:28:46 homebrou sshd[29778]: Failed password for invalid user recruit from 81.74.87.66 port 47672 ssh2
Jan 15 18:33:27 homebrou sshd[2156]: Did not receive identification string from 88.191.23.27
Jan 15 19:23:37 homebrou sshd[3418]: Invalid user test from 88.191.23.27
Jan 15 19:23:37 homebrou sshd[3418]: error: Could not get shadow information for NOUSER
Jan 15 19:23:37 homebrou sshd[3418]: Failed password for invalid user test from 88.191.23.27 port 41017 ssh2
Jan 15 19:23:38 homebrou sshd[3420]: Invalid user test from 88.191.23.27
Jan 15 19:23:38 homebrou sshd[3420]: error: Could not get shadow information for NOUSER
Jan 15 19:23:38 homebrou sshd[3420]: Failed password for invalid user test from 88.191.23.27 port 41096 ssh2
Jan 15 19:23:38 homebrou sshd[3422]: Invalid user test from 88.191.23.27
Jan 15 19:23:38 homebrou sshd[3422]: error: Could not get shadow information for NOUSER
Jan 15 19:23:38 homebrou sshd[3422]: Failed password for invalid user test from 88.191.23.27 port 41162 ssh2
Jan 15 19:23:38 homebrou sshd[3424]: Invalid user test from 88.191.23.27
Jan 15 19:23:38 homebrou sshd[3424]: error: Could not get shadow information for NOUSER
Jan 15 19:23:38 homebrou sshd[3424]: Failed password for invalid user test from 88.191.23.27 port 41209 ssh2
Jan 15 19:23:39 homebrou sshd[3426]: Invalid user test from 88.191.23.27
Jan 15 19:23:39 homebrou sshd[3426]: error: Could not get shadow information for NOUSER
Jan 15 19:23:39 homebrou sshd[3426]: Failed password for invalid user test from 88.191.23.27 port 41267 ssh2
Jan 15 19:23:39 homebrou sshd[3428]: Invalid user test from 88.191.23.27
Jan 15 19:23:39 homebrou sshd[3428]: error: Could not get shadow information for NOUSER
Jan 15 19:23:39 homebrou sshd[3428]: Failed password for invalid user test from 88.191.23.27 port 41323 ssh2
Jan 15 19:23:40 homebrou sshd[3430]: Invalid user test from 88.191.23.27
Jan 15 19:23:40 homebrou sshd[3430]: error: Could not get shadow information for NOUSER
Jan 15 19:23:40 homebrou sshd[3430]: Failed password for invalid user test from 88.191.23.27 port 41376 ssh2
Jan 15 19:23:40 homebrou sshd[3433]: Invalid user test from 88.191.23.27
Jan 15 19:23:40 homebrou sshd[3433]: error: Could not get shadow information for NOUSER
Jan 15 19:23:40 homebrou sshd[3433]: Failed password for invalid user test from 88.191.23.27 port 41433 ssh2
Jan 15 19:23:41 homebrou sshd[3435]: Invalid user test from 88.191.23.27
Jan 15 19:23:41 homebrou sshd[3435]: error: Could not get shadow information for NOUSER
Jan 15 19:23:41 homebrou sshd[3435]: Failed password for invalid user test from 88.191.23.27 port 41484 ssh2
Jan 16 12:13:43 homebrou sshd[32249]: Did not receive identification string from 209.126.131.150

Looking at /var/log/fail2ban.log around the corresponding period of time:対応する期間の/var/log/fail2ban.logを見てください。

2007-01-15 15:38:47,142 fail2ban.actions: WARNING [ssh-iptables] Unban 81.74.87.66
2007-01-15 19:23:41,175 fail2ban.actions: WARNING [ssh-iptables] Ban 88.191.23.27
2007-01-15 19:23:42,373 fail2ban.actions: WARNING [ssh-iptables] 88.191.23.27 already banned
2007-01-15 19:33:41,508 fail2ban.actions: WARNING [ssh-iptables] Unban 88.191.23.27
2007-01-16 12:29:50,496 fail2ban.actions: WARNING [ssh-iptables] Ban 209.126.131.150

Thus, you can see that between 19:23:37 and 19:23:41, i.e. within 4 seconds, 9 login (ssh) attempts (instead of only 3) from 88.191.23.27 have been recorded in auth.log before it has been banned by Fail2ban.したがって、19:23:37と19:23:41の間、つまり4秒以内に、88.191.23.27から9回(3回ではなく)のログイン(ssh)試行がauth.logに記録される前に記録されていることがわかります。Fail2banによって禁止されています

Possibility of DOS attack by a local userローカルユーザーによるDOS攻撃の可能性

Because syslog entries can be 'forged' by a regular user, e.g.:syslogエントリは通常のユーザによって偽造される可能性があるためです。

logger -p auth.warning -t 'sshd[123]' 'Illegal user user1 from 1.2.3.4'

Fail2Ban should not be run on systems which provide ssh/CGI/PHP services to unknown users without any level of trust. They might be able to block other users from ssh and probably other access with a call to logger. A malicious user may also write via PHP's openlog()/syslog() to syslog.Fail2Banは、未知のユーザーにssh / CGI / PHPサービスを提供するシステムでは、いかなる信頼レベルでも実行するべきではありません。他のユーザがsshからアクセスできないようにし、おそらく他のユーザがloggerを呼び出してアクセスできないようにします。悪意のあるユーザーは、PHPのopenlog()/ syslog()を使ってsyslogに書き込むこともできます。

N.B. chmod o-x /usr/bin/logger might provide at least obfuscation solution.NB chmod ox / usr / bin / loggerは少なくとも難読化ソリューションを提供するかもしれません。

Logging systems supporting authentication (e.g. journal) might provide adequate resolution for this in the future.認証をサポートするロギングシステム(例:ジャーナル)は将来的にこれに対する適切な解決策を提供するかもしれません。

スポンサーリンク

location.hash

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る