Top Page
tarpit checks English Page

tarpit checks

Postfix用 tarpit 重複発動避け filter daemon

ダウンロード
ソースアーカイブ


2011/06/21 作成

Postfix で(spam避けとして)tarpit は掛けたいが、tarpit から(1~N回以上)脱出したホストは(次回以降の)tarpit対象から除外したい、という用途に。
Python製 Postfix用 filter daemon として作成。

RCPT毎に SLEEP が掛からないように、smtpd_data_restrictions に tarpit check を入れる(& smtpd_end_of_data_restrictions に tarpit 除外登録を入れる)か、smtpd_delay_reject=noにした上で smtpd_client_restrictions に入れると良い。

usage: tarpit_checks.py

[--sleep=N(default:65(sec))] tarpit time
[--check_port=N(default:60001)] check for smtpd_recipient_restrictions(or etc)
[--store_port=N(default:60002)] store for smtpd_data_restrictions(or etc)
[--cmd_port=N(default:60003)] del=entry/check=entry/all/info (N == 0 means disabled)
[--bind_host=host(default:localhost)] for check_port, store_port, cmd_port
[--addr_mask=nbits(default:24)] IP address grouping for DB key
[--threshold=N(default:1(times))] threshold count for untarpit
[--db=path(default:"/etc/postfix/tarpit_checks.db")]

起動すると、locahost:60001(SLEEPするかどうかの問い合わせ用)、60002(DBへの除外エントリ登録用)、60003(DBメンテナンス用)を開いて daemon化。各種情報は syslog に出力。

データは(現状では)BerkeleyDB に格納。デフォルトでは接続元アドレスを 24bitに丸めるため、DBは肥大化しづらいはずながら、要望があれば定期 cleanup を追加しても良いかも。

(その場合、データ構造を変えたほうが良さそうだけれども)


以下、tarpit_checks.py のヘッダより、使い方コメントを引用
# example)
# =================================================================
#  main.cf
# -----------------------------------------------------------------
#  smtpd_restriction_classes = tarpit_checks (, other_classes...)
#  tarpit_checks = check_policy_service inet:127.0.0.1:60001
#
#  # you can use smtpd_client_restrictions instead of
#  #  smtpd_data_restrictions, if smtpd_delay_reject = no.
#  #
#  smtpd_data_restrictions = permit_mynetworks
#    # permit and reject lines (permit_sasl_authenticated, or etc...)
#             :
#    check_client_access regexp:/etc/postfix/tarpit_checks
#
#  smtpd_end_of_data_restrictions = permit_mynetworks
#    # permit and reject lines (permit_sasl_authenticated, or etc...)
#             :
#    check_policy_service  inet:60002
#
#
# =================================================================
#  /etc/postfix/tarpit_checks
# -----------------------------------------------------------------
#  *** WHITE LIST ***
#  /a\.example\.com$/    DUNNO
#      :
#  *** BLACK LIST ***
#  /b\.example\.com$/    DUNNO
#      :
#  *** tarpit (all host) ***
#  /.*$/                 tarpit_checks
#      :
#
#
# =================================================================
#  /etc/rc.local
# -----------------------------------------------------------------
#      :
#  /usr/bin/python /etc/postfix/tarpit_checks.py
#
#
# =================================================================
#  maintenance commands (check='ipaddr', del='ipaddr', info, all)
# -----------------------------------------------------------------
# % telnet 60003
# Trying 127.0.0.1...
# Connected to localhost.
# Escape character is '^]'.
# check=10.10.10.10
# 10 objs
# 

..up menu