web-dev-qa-db-ja.com

fail2ban複数行正規表現の記述

私が実行しているSSHサーバーでそれを試してみる厄介なホストがいくつかあり、fail2banを使用してそれらを禁止しようとしています。問題は、正規表現ではあまり作業を行っておらず、Python正規表現ではさらに少ない作業です。

これが私のauth.logの厄介な行です:

Nov 19 18:58:17 myhost sshd[48272]: Connection from xxx.xxx.xxx.xxx port 3284 on my.Host.ip.address port 22
Nov 19 18:58:21 myhost sshd[48272]: fatal: Read from socket failed: Connection reset by peer [preauth]

正規表現の両方の行を取得したいのですが、他の投稿で複数行の処理方法について見てきましたが、現時点では最初の行に一致させることすらできません。これが私の* .confファイルからの抜粋です:

[INCLUDES]

# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf

[Init]

maxlines = 2

[Definition]

_daemon = sshd

failregex = ^%(__prefix_line)s^Connection from <Host>*$

「__prefix_line」は最初の「myhostsshd [PID]」ビットをキャッチするように設計されていることを理解していますが、「fail2ban-regex」を実行すると次のようになります。

Results
=======

Failregex: 0 total

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [115124] MONTH Day Hour:Minute:Second
`-

Lines: 115124 lines, 0 ignored, 0 matched, 115124 missed

誰かアイデアはありますか?

前もって感謝します!

3
ticktockhouse

私はUbuntuで長い間マルチライン正規表現と戦いました。それを機能させるには、v 0.9.1に更新する必要があり、fail2ban自体から最新のtar.gzをダウンロードする必要がありました。 Ubuntu 14.04の場合、LTSバージョンの上限は0.8.11でした。

その後、期待どおりに機能しました。

1

fail2ban 0.9.5 on buntu Server LTS 14.04を使用しており、Nicewronguser.conf私のsshとsquirrelmail(「dovecot」を使用)のすべての「間違った/許可されていない」ユーザーを禁止し、/ var/log/authを調べるルール次のマルチラインの.log:

Aug 15 10:15:25 server auth: pam_unix(dovecot:auth): check pass; user unknown
Aug 15 10:15:25 server auth: pam_unix(dovecot:auth): authentication failure; logname= uid=0 euid=0 tty=dovecot ruser=alumni rhost=14.141.17.167

そして

Aug 15 12:39:10 server sshd[5851]: pam_unix(sshd:auth): check pass; user unknown
Aug 15 12:39:10 server sshd[5851]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=91.224.160.106

sshrootユーザー禁止の1行と一緒に:

Aug 15 05:50:20 server sshd[20677]: Failed password for root from 62.147.227.164 port 55253 ssh2

ルールは次のとおりです。

[INCLUDES]

before = common.conf

[Definition]

_daemon = (?:sshd|postfix/smptd)

failregex = ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from <Host>\s*$
            ^%(__prefix_line)sFailed (?:password|publickey) for root from <Host>(?: port \d*)?(?: ssh\d*)?$
            dovecot.*user unknown\n.*dovecot.*authentication failure.*rhost\=<Host>

ingoreregex =

[Init]

maxlines = 2

これはjail.localに次のように含まれています。

[wronguser]

enabled  = true
port     = 1:65535
filter   = wronguser
logpath  = /var/log/auth.log
maxretry = 1
bantime  = -1

buntu LTS 14.04のデフォルトのapt-getfail2banは0.8.11であり、複数行の正規表現では機能しません。したがって、最新の安定したfail2banを手動でインストールする必要があります。私は彼らのgitリポジトリから直接それをしました。

1
ataraxic