スパム対策 · 3 min read · Nov 18, 2025
FuzzyOCRとSpamAssassinでFedora 12の画像スパムと戦う
FuzzyOCRとSpamAssassinでFedora 12の画像スパムと戦う
バージョン 1.0
著者: Falko Timme
私をTwitterでフォローしてください
このチュートリアルでは、Fedora 12サーバーでFuzzyOCRを使用してメールの画像スパムをスキャンする方法を説明します。FuzzyOCRは、画像を主なコンテンツキャリアとする無 solicited bulk mailを対象としたSpamAssassinのプラグインです。さまざまな方法を使用して、画像の内容と特性を分析し、通常のメール(ham)とスパムメールを区別します。FuzzyOCRは、SpamAssassinによってすでにスパムとして分類されていないメールのみをスキャンすることで、システムの負荷を低く保とうとし、不要な作業を回避します。
私はこれがあなたにとって機能するという保証はしません!
1 前提条件
この記事では、ベースシステムとしてFedora 12を使用します。
SpamAssassinがすでにインストールされ、動作していることを前提としています。主な設定ディレクトリは/etc/mail/spamassassin/です。ディレクトリが異なる場合(たとえば、ISPConfig 2がインストールされている場合、ディレクトリは/home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassin/)、問題ありません。どこを変更するかを注釈します。
SpamAssassinのバージョンがFuzzyOCRと互換性があることを確認してください。たとえば、ここでインストールするFuzzyOCRのバージョン(fuzzyocr-3.5.1-devel.tar.gz)は、SpamAssassin 3.1.4以降が必要です。
2 FuzzyOCRの前提条件をインストールする
FuzzyOCRには、次のような前提条件がいくつかあります。これらは次のようにインストールできます:
yum install netpbm gifsicle giflib giflib-utils gocr ocrad ImageMagick tesseract perl-String-Approx perl-MLDBM perl-CPANまた、MLDBM::Sync Perlモジュールをインストールする必要がありますが、これはRPMパッケージとしては利用できません。Perlシェルを開きます….
perl -MCPAN -e shell…そして、次のようにモジュールをインストールします:
install MLDBM::Syncその後、Perlシェルを終了するには、
qと入力します。
3 FuzzyOCRをインストールする
cd /usr/src/
wget http://users.own-hero.net/~decoder/fuzzyocr/fuzzyocr-3.5.1-devel.tar.gz次に、FuzzyOCRを解凍し、すべてのFuzzyOcr*ファイルとFuzzyOcrディレクトリ(すべてFuzzyOcr-3.5.1/ディレクトリ内にあります)を/etc/mail/spamassassinに移動します:
tar xvfz fuzzyocr-3.5.1-devel.tar.gz
cd FuzzyOcr-3.5.1/
mv FuzzyOcr* /etc/mail/spamassassin/SpamAssassinのディレクトリが異なる場合(たとえば、/home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassin/)、最後のコマンドは次のように置き換える必要があります。
mv FuzzyOcr* /home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassin/まだ/usr/src/FuzzyOcr-3.5.1/ディレクトリを削除しないでください。そこにはサンプル画像スパムメールが含まれているディレクトリ(samples/)があり、FuzzyOCRが期待通りに動作しているかをテストするために後で必要です。
これでFuzzyOCRがインストールされました。次に、設定を行う必要があります。
4 FuzzyOCRを設定する
FuzzyOCRの設定ファイルは/etc/mail/spamassassin/FuzzyOcr.cfです。そのファイルのほとんどはコメントアウトされています。今、そのファイルを開いていくつかの変更を加えます:
vi /etc/mail/spamassassin/FuzzyOcr.cfFuzzyOCRのスパムワードファイルの場所を定義するために、次の行を追加します:
| [...] focr_global_wordlist /etc/mail/spamassassin/FuzzyOcr.words [...] |
/etc/mail/spamassassin/FuzzyOcr.wordsは、FuzzyOCRに付属の定義済みの単語リストです。必要に応じて調整できます。
次に、
| [...] # Include additional scanner/preprocessor commands here: # focr_bin_helper pnmnorm, pnminvert, pamthreshold, ppmtopgm, pamtopnm focr_bin_helper tesseract [...] |
を次のように変更します:
| [...] # Include additional scanner/preprocessor commands here: # focr_bin_helper pnmnorm, pnminvert, convert, ppmtopgm, tesseract [...] |
最後に、次の行を追加/有効にします:
| [...] # Search path for locating helper applications focr_path_bin /usr/local/netpbm/bin:/usr/local/bin:/usr/bin focr_preprocessor_file /etc/mail/spamassassin/FuzzyOcr.preps focr_scanset_file /etc/mail/spamassassin/FuzzyOcr.scansets focr_enable_image_hashing 2 focr_digest_db /etc/mail/spamassassin/FuzzyOcr.hashdb focr_db_hash /etc/mail/spamassassin/FuzzyOcr.db focr_db_safe /etc/mail/spamassassin/FuzzyOcr.safe.db [...] |
最後の4行で画像ハッシュ化を有効にします。FuzzyOCRの開発者は、画像ハッシュ化について次のように述べています:
“画像ハッシュデータベース機能により、プラグインは画像特徴のベクトルをデータベースに保存できるため、2回目にこの画像が到着したときにそれを認識します(したがって、再度スキャンする必要はありません)。この機能の特別な点は、スパマーによってわずかに変更された場合でも画像を再認識できることです。”
/home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassinを使用する場合、FuzzyOCRの設定ファイルは/etc/mail/spamassassin/FuzzyOcr.cfの代わりに/home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassin/FuzzyOcr.cfになりますので、そのファイルを編集してください。設定ファイルでは、/etc/mail/spamassassinのすべての出現を/home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassinに置き換えるか、または前述のようにそのままにして、次のようにシンボリックリンクを作成します:
mkdir /etc/mail/
ln -s /home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassin/ /etc/mail/spamassassinこれでFuzzyOCRの設定は完了です。次に、期待通りに動作するかどうかを確認しましょう。
5 FuzzyOCRをテストする
前述のように、FuzzyOCRにはサンプル画像スパムメール(samples/ディレクトリ内)が付属しています:
ls -l /usr/src/FuzzyOcr-3.5.1/samples/出力は次のようになります:
total 156
-rw-r--r-- 1 1000 users 13633 2007-01-07 12:55 ocr-animated.eml
-rw-r--r-- 1 1000 users 16108 2007-01-07 12:55 ocr-gif.eml
-rw-r--r-- 1 1000 users 27506 2007-01-07 12:55 ocr-jpg.eml
-rw-r--r-- 1 1000 users 27842 2007-01-07 12:59 ocr-multi.eml
-rw-r--r-- 1 1000 users 24657 2007-01-07 12:55 ocr-obfuscated.eml
-rw-r--r-- 1 1000 users 18236 2007-01-07 12:55 ocr-png.eml
-rw-r--r-- 1 1000 users 16113 2007-01-07 12:55 ocr-wrongext.eml
-rw-r--r-- 1 1000 users 3576 2007-01-07 12:55 READMEこれらのメールをSpamAssassinに渡して、FuzzyOCRが正しくリンクされているかどうかを確認できます。spamassassin実行可能ファイルの場所を見つけます(通常はPATHにあります - これは次のコマンドを実行することで確認できます:
which spamassassin結果が表示されれば、spamassassinはPATHにあり、フルパスを指定する必要はありません。)
spamassassinの場所がわからない場合は、次のコマンドを実行して見つけることができます:
updatedb
locate spamassassinISPConfig 2を使用している場合、spamassassinはここにあります:/home/admispconfig/ispconfig/tools/spamassassin/usr/bin/spamassassin
spamassassinの場所がわかったので、次のようにサンプル画像スパムメールをspamassassinに渡すことができます:
/path/to/spamassassin --debug FuzzyOcr < /usr/src/FuzzyOcr-3.5.1/samples/ocr-gif.eml > /dev/null例えば:
/home/admispconfig/ispconfig/tools/spamassassin/usr/bin/spamassassin --debug FuzzyOcr < /usr/src/FuzzyOcr-3.5.1/samples/ocr-gif.eml > /dev/nullまたは、spamassassinがPATHにある場合:
spamassassin --debug FuzzyOcr < /usr/src/FuzzyOcr-3.5.1/samples/ocr-gif.eml > /dev/nullこれで多くの出力が表示されるはずで、最後は次のようになります:
[...]
[10025] dbg: FuzzyOcr:
[10025] dbg: FuzzyOcr: Friday Augurt 4, 4:01 pm ET
[10025] dbg: FuzzyOcr: LAS VEGAS, NEVADA--(MARKET WIRE)--Aug 4, 2006 -- auantum Energy, lnc. (OTC
[10025] dbg: FuzzyOcr: BB:aEGY.oB-_-
[10025] dbg: FuzzyOcr: auantum Energy, lnc. is pleased to announce that it has applied to have its shares listed for
[10025] dbg: FuzzyOcr: trading on the Frankfurt Stock Exchange. The company has retained the services ofBaltic
[10025] dbg: FuzzyOcr: lnvestment Group of Hamburg, Germany to assist with the application.
[10025] dbg: FuzzyOcr:
[10025] dbg: FuzzyOcr: _ qEGY,OB "
[10025] dbg: FuzzyOcr:
[10025] dbg: FuzzyOcr: <<=end
[10025] info: FuzzyOcr: Scanset "ocrad" found word "target" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "short term price target oo"
[10025] info: FuzzyOcr: Scanset "ocrad" found word "service" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "trading on the frankfurt stock exchange the company has retained the services ofbaltic"
[10025] info: FuzzyOcr: Scanset "ocrad" found word "stock" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "hot energy stocki"
[10025] info: FuzzyOcr: Scanset "ocrad" found word "stock" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "trading on the frankfurt stock exchange the company has retained the services ofbaltic"
[10025] info: FuzzyOcr: Scanset "ocrad" found word "price" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "current price o"
[10025] info: FuzzyOcr: Scanset "ocrad" found word "price" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "short term price target oo"
[10025] info: FuzzyOcr: Scanset "ocrad" found word "company" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "trading on the frankfurt stock exchange the company has retained the services ofbaltic"
[10025] info: FuzzyOcr: Scanset "ocrad" found word "recommendation" with fuzz of 0.0000
[10025] info: FuzzyOcr: line: "sboog bup recommendation"
[10025] dbg: FuzzyOcr: Enough OCR Hits without space stripping, skipping second matching pass...
[10025] info: FuzzyOcr: Scanset "ocrad" generates enough hits (8), skipping further scansets...
[10025] info: FuzzyOcr: Message is spam, score = 15.000
[10025] info: FuzzyOcr: Adding Hash to "/etc/mail/spamassassin/FuzzyOcr.db" with score "15.000"
[10025] dbg: FuzzyOcr: Digest: 538584:327:549:7::255:255:255:255:168580::0:0:0:0:9098::0:128:0:75:1086::0:0:128:15:395::128:0:128:53:213::0:0:255:29:115
[10025] info: FuzzyOcr: Words found:
[10025] info: FuzzyOcr: "target" in 1 lines
[10025] info: FuzzyOcr: "service" in 1 lines
[10025] info: FuzzyOcr: "stock" in 2 lines
[10025] info: FuzzyOcr: "price" in 2 lines
[10025] info: FuzzyOcr: "company" in 1 lines
[10025] info: FuzzyOcr: "recommendation" in 1 lines
[10025] info: FuzzyOcr: (12 word occurrences found)
[10025] dbg: FuzzyOcr: Remove DIR: /tmp/.spamassassin10025QnPTq8tmp
[10025] dbg: FuzzyOcr: FuzzyOcr ending successfully...
[10025] dbg: FuzzyOcr: Processed in 2.191381 sec.ご覧のとおり、/usr/src/FuzzyOcr-3.5.1/samples/ocr-gif.emlはスパムとして15ポイントのスコアで分類されましたので、FuzzyOCRは機能しています。
これで、あなたのSpamAssassinはFuzzyOCRの助けを借りて画像スパムを認識できるようになりました。
6 リンク
- FuzzyOCR: http://www.fuzzyocr.net/
- SpamAssassin: http://spamassassin.apache.org/
- Fedora: http://fedoraproject.org/
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。