LoginSignup
0
0

More than 1 year has passed since last update.

postfixのログから”SASL LOGIN authentication failed”が多いIPアドレスをはじくiptablesエントリを自動作成するシェルスクリプトを作ってみた。

Posted at

つまりどういうことだってばよ?

postfixのログ/var/log/mail.warnに大量に記録されたスパム業者
と思われるIPを片っ端からiptablesで弾く為に、
SASL LOGIN authentication failedの回数上位10件のIPアドレスを
対象としたiptablesエントリを自動作成するスクリプトを組んでみた。

環境

  • debian 11 bullseye
  • iptables-persistentがインストール済み
  • postfix

参考サイト

SMTP Authを何度も試みててくるIPアドレスをブロックする【postfix】 | ex1-lab

スクリプト

mkiplist
#!/bin/bash

sudo grep "SASL LOGIN authentication failed" /var/log/mail.warn | grep -o "\([0-9]\+\.\)\{3\}" | sort | uniq -c | sort -nr | awk '{print "-A INPUT -s " $2 "0/24 -j DROP"}' | head -10

実行結果

-A INPUT -s xxx.xxx.xxx.0/24 -j DROP
-A INPUT -s yyy.yyy.yyy.0/24 -j DROP
-A INPUT -s zzz.zzz.zzz.0/24 -j DROP
...

あとはこれをrules.v4のfilterに貼り付けて、
iptables-restoreすればOK。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0