web-dev-qa-db-ja.com

Fail2banが機能しないraspbian(ssh)

Raspberry Pi(Raspbian)に新規インストールを実行しましたが、fail2banで何も実行できません。失敗したsshログインはブロックされません。正しいログファイルを指していることを確認しました(/var/log/auth.log)つまり、iptablesがアクティブで、fail2banが開始され、sshd jailがオンになっていて、サービスがポート22で実行されていることを確認しました。この時点で、どうすればよいかわかりません。これまでsshで動作させるのにこれほど問題があったことはありません。通常、箱から出してすぐに機能します。これが私のログフィルターと認証ログです:

ログ:

Jan 22 21:11:25 PI2 sshd[22700]: pam_unix(sshd:auth): authentication failure; lo gname= uid=0 euid=0 tty=ssh ruser= rhost=216.4.56.163 user=pi
Jan 22 21:11:27 PI2 sshd[22700]: Failed password for pi from 216.4.56.163 port 1 6290 ssh2
Jan 22 21:11:27 PI2 sshd[22700]: error: Received disconnect from 216.4.56.163: 3 : com.jcraft.jsch.JSchException: Auth cancel [preauth]
Jan 22 21:17:01 PI2 CRON[22783]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 22 21:17:01 PI2 CRON[22783]: pam_unix(cron:session): session closed for user root
Jan 22 21:17:30 PI2 sshd[22809]: pam_unix(sshd:auth): authentication failure; lo gname= uid=0 euid=0 tty=ssh ruser= rhost=183.3.202.106 user=root
Jan 22 21:17:33 PI2 sshd[22809]: Failed password for root from 183.3.202.106 por t 16766 ssh2
Jan 22 21:17:36 PI2 sshd[22809]: Failed password for root from 183.3.202.106 por t 16766 ssh2
Jan 22 21:17:38 PI2 sshd[22809]: Failed password for root from 183.3.202.106 por t 16766 ssh2
Jan 22 21:17:39 PI2 sshd[22809]: Received disconnect from 183.3.202.106: 11: [p reauth]
Jan 22 21:17:39 PI2 sshd[22809]: PAM 2 more authentication failures; logname= ui d=0 euid=0 tty=ssh ruser= rhost=183.3.202.106 user=root`

フィルタ:

sshd.conf          [----]  0 L:[ 17+21  38/ 38] *(1772/1772b) <EOF>       [*][X]
    ^%(__prefix_line)sFailed \S+ for .*? from <Host>(?: port \d*)?(?: ssh\d*
    ^%(__prefix_line)sROOT LOGIN REFUSED.* FROM <Host>\s*$
    ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from <Host>\s*$
    ^%(__prefix_line)sUser .+ from <Host> not allowed because not listed in
    ^%(__prefix_line)sUser .+ from <Host> not allowed because listed in Deny
    ^%(__prefix_line)sUser .+ from <Host> not allowed because not in any gro
    ^%(__prefix_line)srefused connect from \S+ \(<Host>\)\s*$
    ^%(__prefix_line)sReceived disconnect from <Host>: 3: \S+: Auth fail$
    ^%(__prefix_line)sUser .+ from <Host> not allowed because a group is lis
    ^%(__prefix_line)sUser .+ from <Host> not allowed because none of user's
ignoreregex =.

ログフィルターだと確信していますが、修正方法がわかりません。

2
TheStarvingGeek

理解した、

問題は、別のサービス用にカスタムjailセットアップがあり、それが正しく構成されておらず、fail2banが正しく開始されないことでした。

したがって、「service fail2ban status」を実行すると、他の刑務所を修正する前にこれを取得します。

 ● fail2ban.service - LSB: Start/stop fail2ban
   Loaded: loaded (/etc/init.d/fail2ban)
   Active: active (exited) since Mon 2016-01-25 18:41:50 EST; 3s ago
  Process: 11673 ExecStop=/etc/init.d/fail2ban stop (code=exited, status=0/SUCCESS)
  Process: 11683 ExecStart=/etc/init.d/fail2ban start (code=exited, status=0/SUCCESS)

Jan 25 18:41:50 PI2 fail2ban[11683]: Starting authentication failure monitor: fail2banERROR  No file(s) found for glob /wrong/way/service.log #edit to your needs
Jan 25 18:41:50 PI2 fail2ban[11683]: ERROR  Failed during configuration: Have not found any log file for service jail
Jan 25 18:41:50 PI2 fail2ban[11683]: failed!
Jan 25 18:41:50 PI2 systemd[1]: Started LSB: Start/stop fail2ban.

私がそれを修正した後:

 ● fail2ban.service - LSB: Start/stop fail2ban
   Loaded: loaded (/etc/init.d/fail2ban)
   Active: active (running) since Mon 2016-01-25 18:43:03 EST; 3s ago
  Process: 11774 ExecStop=/etc/init.d/fail2ban stop (code=exited, status=0/SUCCESS)
  Process: 11784 ExecStart=/etc/init.d/fail2ban start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/fail2ban.service
           └─11795 /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock -p /var/run/fail2ban/fail2ban.pid

Jan 25 18:43:03 PI2 fail2ban[11784]: Starting authentication failure monitor: fail2ban.
Jan 25 18:43:03 PI2 systemd[1]: Started LSB: Start/stop fail2ban.
0
TheStarvingGeek