memo.xight.org

日々のメモ

阻止率99%のスパム対策方式の研究報告

Summary

  Posftix以外の不可ソフトウェアを使用することなく,
  spamメールとVirusメールを合わせた不正メールの約99%を阻止する方法.
  不正メールを阻止するための Postfix の設定も記載.

従来のspam対策

  送信者ドメインの検査
  内容の検査
  オープンリレーの禁止
  クライアントのIP,ドメイン名の検査

新しいspam対策方式のコンセプト

  メール中継サーバからのSMTPアクセスを受け入れ,直接のSMTPアクセスは拒絶する.
  FQDN (Fully Qualified Domain Name - 完全修飾ドメイン名)の特徴を見ることで実現する.

クライアント制限の規則

  - 一般規則
    逆引き失敗
    [ルール1] 逆引きFQDNの最下位(左端)の名前が,数字以外の文字列で分断された二つの数字列を含む
    [ルール2] 逆引きFQDNの最下位の名前が,5個以上連続する数字を含む
    [ルール3] 逆引きFQDNの上位3階層を除き,最下位または下位から2番目の名前が数字で始まる
    [ルール4] 逆引きFQDNの最下位の名前が数字で終わり,かつ下位から2番目の名前が,1個のハイフンで分断された二つの数字列を含む
    [ルール5] 逆引きFQDNが5階層以上で,下位2階層の名前がともに数字で終わる
    [ルール6] 逆引きFQDNの最下位の名前が「dhcp」,「dialup」,「ppp」,または「adsl」で始まり,かつ数字を含む
  - ブラックリスト
    末端ホスト名が十六進番号を含む
    末端ホスト名が、番号を表す英字を含む
    メール中継サーバであるかのようなFQDNである
    ドメインを代表するメールサーバがスパムを送信する
  - ホワイトリスト
    逆引き失敗
    逆引きFQDNが複数のIPアドレスに対応している
    ホスト名が一般規則に引っかかる
    エンドユーザー用回線を利用している

その他のフィルタ

  HELOコマンドの検査
  送信者ドメインの検査
  内容の検査

統計

拒絶条件 阻止率増分 阻止率累計
逆引き失敗 38.4 38.4
[ルール1] 44.5 82.9
[ルール2] 7.6 90.5
[ルール3] 6.5 97.0
[ルール4] 0.9 97.9
[ルール5] 0.3 98.2
[ルール6] 0.0 98.2
ブラックリスト 0.5 98.7
HELOコマンド 0.4 99.1
送信者ドメイン 0.0 99.1
内容 0.0 99.1

  一般規則のみで98.2%の効果.

Posftix での設定

  - /etc/postfix/main.cf に以下を追加

smtpd_client_restrictions =
  permit_mynetworks,
  check_client_access regexp:/etc/postfix/client_restrictions,
  reject_unknown_client

  - /etc/postfix/client_restrictions に以下を記述

# Client restriction specifications for Postfix aiming at anti-UCE
# Contributed by ASAMI Hideo (Japan), Jun. 2004
# Refer to: http://www.gabacho-net.jp/en/anti-spam/
#
# To use this file, add following lines into the /etc/postfix/main.cf file:
#
# smtpd_client_restrictions =
#   permit_mynetworks,
#   check_client_access regexp:/etc/postfix/client_restrictions,
#   reject_unknown_client
#
# where "client_restrictions" is the name of this file.
#
# *** WHITE LIST ***
#
# When you find a proper mail relay server which is rejected by the rules
# specified below, insert here a permission specification taking a leaf from
# the following examples. Note that the dotted decimal notation of an IP
# address is available only when reverse lookup fails.
#
#/^223\.123\.45\.67$/                           OK
#/^223-123-45-67\.example\.net$/                OK
#
# *** BLACK LIST ***
#
# When you find a UCE sender's FQDN which is not rejected by the generic
# protection rules specified below, insert here a denial specification taking
# a leaf from the following practical examples. You should specify a subdomain
# name or a substring together with the domain name if possible so that you can
# avoid rejecting proper mail relay servers in the same domain.
#
# pD9E799A1.dip.t-dialin.net (hexadecimal used)
/\.dip\.t-dialin\.net$/                         450 domain UCE-blacklisted
#
# ool-43511bdc.dyn.optonline.net (hexadecimal used)
/\.dyn\.optonline\.net$/                        450 domain UCE-blacklisted
#
# zaq3d7d6ded.zaq.ne.jp (hexadecimal used)
/^zaq.+\.zaq\.ne\.jp$/                          450 domain UCE-blacklisted
#
# user-0cetcbr.cable.mindspring.com
# user-vc8fldi.biz.mindspring.com
/^user.+\.mindspring\.com$/                     450 domain UCE-blacklisted
#
# rt-dkz-1699.adsl.wanadoo.nl
# c3eea5738.cable.wanadoo.nl (hexadecimal used)
/\.(adsl|cable)\.wanadoo\.nl$/                  450 domain UCE-blacklisted
#
# pr86.internetdsl.tpnet.pl
# fq217.neoplus.adsl.tpnet.pl
# pa148.braniewo.sdi.tpnet.pl
/\.(internetdsl|adsl|sdi)\.tpnet\.pl$/          450 domain UCE-blacklisted
#
# ACBBD419.ipt.aol.com (hexadecimal used)
/\.ipt\.aol\.com$/                              450 domain UCE-blacklisted
#
# *** GENERIC PROTECTION ***
#
# [rule 1]
# ex: evrtwa1-ar3-4-65-157-048.evrtwa1.dsl-verizon.net
# ex: a12a190.neo.rr.com
/^[^\.]*[0-9][^0-9\.]+[0-9]/                    450 may not be mail exchanger
#
# [rule 2]
# ex: pcp04083532pcs.levtwn01.pa.comcast.net
/^[^\.]*[0-9]{5}/                               450 may not be mail exchanger
#
# [rule 3]
# ex: 398pkj.cm.chello.no
# ex: host.101.169.23.62.rev.coltfrance.com
/^([^\.]+\.)?[0-9][^\.]*\.[^\.]+\..+\.[a-z]/    450 may not be mail exchanger
#
# [rule 4]
# ex: wbar9.chi1-4-11-085-222.dsl-verizon.net
/^[^\.]*[0-9]\.[^\.]*[0-9]-[0-9]/               450 may not be mail exchanger
#
# [rule 5]
# ex: d5.GtokyoFL27.vectant.ne.jp
/^[^\.]*[0-9]\.[^\.]*[0-9]\.[^\.]+\..+\./       450 may not be mail exchanger
#
# [rule 6]
# ex: dhcp0339.vpm.resnet.group.upenn.edu
# ex: dialupM107.ptld.uswest.net
# ex: PPPbf708.tokyo-ip.dti.ne.jp
# ex: adsl-1415.camtel.net
/^(dhcp|dialup|ppp|adsl)[^\.]*[0-9]/            450 may not be mail exchanger

拒絶記録抽出用シェルスクリプト

#!/bin/sh
echo "Content-Type: text/plain"
echo
echo "Mail reject log"
echo
cat /var/log/maillog.4 /var/log/maillog.3 /var/log/maillog.2 /var/log/maillog.1 /var/log/maillog \
    | grep 'reject:' \
    | gawk '
BEGIN {
  count=0
}
{
  printf "[%s %2d %s] %s\n", $1, $2, $3, substr($0,
  match($0, /reject:/))
  ++count
}
END {
  print "\ncount =", count
}
'


Reference

  阻止率99%のスパム対策方式の研究報告
  http://www.gabacho-net.jp/anti-spam/anti-spam-system.html

via

  cl.pocari.org - 2004-09-06
  http://cl.pocari.org/2004-09.php#2004-09-06-3