🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #17900

INN: Perl spam filter improved

#17900
From: Jeff Garzik
Date: Wed, 21 May 1997 00:00
195 lines
6152 bytes
This is a multi-part message in MIME format.

--------------44849E8F373A16E37C44B24E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Enclosed is an update to my Perl spam filter.  It has been running on my
system for more than a week.  It includes a few small but important
changes:

	- separate EMP history remembers spams longer, and
	  works much more quickly
	- fixes a bug that caused control messages, usually
	  spam cancels, to be filtered along with all the
	  other articles.  Usually the ECP filter gobbled
	  20-40 spam cancels a day.


The Perl spam filter includes three simple filters that attempt to
reject spam by scanning common article headers.  This filter catches, on
average, over 50,000 articles a day.  That's 50,000 extraneous articles
your readers don't see, and 50,000 articles your outgoing feeds don't
download.  The Perl filter itself does consume additional CPU resources,
but they are neglible in comparison to the time and disk I/O saved by
not storing and forwarding the spam article.


MMF Filter

Rejects articles with subjects containing 'make money fast', 'cash cash
cash', and a general regex pattern matching something like '$$$ SOME
TEXT HERE $$$'.


ECP Filter

If the number of groups listed in a Newsgroups: header exceeds a certain
cap, the article is rejected.


EMP Filter

Each From, Subject, and Lines header is stored in a history array of the
last 3000 articles received.  If the same From/Subject/Lines combination
appears 5 times in the last 3000 articles, then that From/Subject/Lines
combo is considered an EMP, excessive multi-post, thereafter.

The spam filter places the newly detected EMP in a special EMP history
array, which stores the last 900 EMP Subject/From/Lines headers.  This
allows succeeding EMP copies to be recognized and rejected more quickly,
avoiding the more CPU-intensive operations of this filter.


Installation is easy:

1) Make sure your copy of INN supports Perl filtering.  It's a
compile-time option admins sometimes compile out if they aren't using
it.

2) Edit ~news/bin/control/filter_innd.pl and replace the filter_art
subroutine with the one enclosed below.

3) Use Perl to make sure you installed it correctly:

	perl -cw ~news/bin/control/filter_innd.pl

4) Tell INN to start using the new filter:

	ctlinnd reload filter.perl 'Spam filtering by Garzik'


This filter is always available via Anonymous FTP at
ftp://ftp.spinne.com/pub/usenet/tools/filter_innd.pl
-- 
Jeff Garzik
News Administrator, Spinne, Inc.
http://www.spinne.com/usenet/

--------------44849E8F373A16E37C44B24E
Content-Type: text/plain; charset=us-ascii; name="filter_innd.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="filter_innd.pl"

#
# Perl spam filter by Jeff Garzik <jeff.garzik@spinne.com>
# Version 3, 5/21/1997
# 

#
# Called on each article innd receives from a peer. Return "" to accept,
# and any other non-null string to reject. If rejecting the string returned
# will be part of the logged reason.
#

sub filter_art {

  $MaxCrossposts = 40;	# max number of crossposts per article
  $MaxMultiPosts = 5;	# max article copies kept before EMP filter begins
  $ArticleHistSize = 3000; # keep history of last N message ids
  $ControlPassthru = 1;	# true (non-zero) to exempt cmsgs from filtering
  $EMPHistSize = 900;	# number of EMP ids to hold in memory


  ##
  ## allow control messages to be exempted from filtering if
  ## $ControlPassthru is true
  ##

  # For those who don't want to filter cancels...
  return "" if (($ControlPassthru) && ($hdr{"Control"}));


  ##
  ## For bulk spamming, a EMP filter with a longer memory
  ##

  ## build key message info buffer
  $i = "$hdr{'From'} $hdr{'Subject'} $hdr{'Lines'}";

  return "EMP rejected" if ($EMP{$i});


  ##
  ## MMF filter
  ##

  ## Filter out strings 'make money fast', 'cash cash cash',
  ## any string that completely matches
  ##   $$... CAPITAL LETTERS AND SPACES AND D-A-S-H-E-S $$... 

  return "MMF rejected"
    if (($hdr{"Subject"} =~ /make\s+money\s+fast/io) ||
	($hdr{"Subject"} =~ /cash\s*cash\s*cash/io) ||
	($hdr{"Subject"} =~ /^\s*\$+[A-Z\s\-]+\$+\s*$/o));


  ##
  ## ECP filter
  ##

  ## Split newsgroups line by ","
  @newsgroups_hdr = split(/,/, $hdr{"Newsgroups"});

  ## filter out resulting arrays whose size is larger than the limit.
  return "ECP rejected" if ($#newsgroups_hdr >= $MaxCrossposts);


  ##
  ## EMP filter
  ##

  ## default value is to accept the article
  $rval = "";

  ## Store From, Subject, and Lines in history array and hash
  push(@history, $i);
  $history{$i}++;

  ## If post appears more than high limit, save for
  ## continual rejection, outside of history window
  if ($history{$i} > $MaxMultiPosts) {
    while ($#EMP_Hist > $EMPHistSize) {
      $tmp_hist = shift(@EMP_Hist);
      delete $EMP{$tmp_hist} if (exists $EMP{$tmp_hist});
    }

    $EMP{$i} = 1;
    push(@EMP_Hist, $i);

    $rval = "new EMP detected";
  }

  ## Trim old entries from history file.  Remember that
  ## data structure stays around, even between filter.perl
  ## reloads.
  while ($#history > $ArticleHistSize) {
    $tmp_hist = shift(@history);
    next unless (exists $history{$tmp_hist});

    if ($history{$tmp_hist} < 2) {
      delete $history{$tmp_hist};
    } else {
      $history{$tmp_hist}--;
    }
  }

  ## return EMP value, rejected or "" for accepted
  return $rval;
}

--------------44849E8F373A16E37C44B24E--


Technical Details
Message-ID: <3383A7FB.77E9E66F@spinne.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <3383A7FB.77E9E66F@spinne.com>
Subject: INN: Perl spam filter improved
Date: Wed, 21 May 1997 00:00:00 +0000
From: Jeff Garzik <jeff.garzik@spinne.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 242968521
Organization: Spinne http://spinne.com
Newsgroups: news.software.nntp