Article View: news.software.nntp
Article #16928INN filter.perl update -- filter out spam
From: Jeff Garzik
Date: Sat, 12 Apr 1997 00:00
Date: Sat, 12 Apr 1997 00:00
118 lines
4048 bytes
4048 bytes
Hi,
I tweaked my Perl spam filter a little bit to work better, and have been
running it for a couple days without problems. In the 60 hours or so
that this has been running with settings close to the ones below, I have
filtered out
54,516 excessive multi-posts
1,397 excessive crossposts
1,290 make-money-fast posts
This has resulting in a definite speed *increase* on my machine --
because it doesn't have to store so many articles at once -- and the CPU
this routine is sucking is very negligible, certainly worth the effort
IMHO.
If you are unfamiliar with how to use this, you need INN 1.5 or later
with Perl support enabled. Add the below routine to
/usr/news/bin/control/filter_innd.pl.
- Most importantly, the Lines header is now kept in the history too.
This means that an EMP must also be the same length as previous EMPs for
it to be rejected. This safety measure is intended to prevent false
positives by people posting many quick (but valid) replies to the same
thread. This allowed me to lower MaxMultiPosts to 2 -- since when is
someone going to post 3 or more articles of equal subject and length in
the same ~10 minute time spam?
- The log entries are substantially less verbose, so log reports only
summarize the total number of ECP, EMP, and MMF posts filtered out.
- The MMF filter now includes a generic filter for any string with ALL
CAPS, preceded and succeeded by one or more '$' chars.
- Easily tunable by constants at the beginning.
- Routine is reload-safe. You can change the Perl code and issue a
'ctlinnd reload filter.perl', but you will not lost your existing
in-memory history hash and array.
Feel free to distribute, abuse, and laugh at this code as you see fit.
Jeff
## filter_art spam filter by Jeff Garzik <jeff.garzik@spinne.com>
sub filter_art {
$MaxCrossposts = 29; # Crosspost limit
$MaxMultiPosts = 2; # Multi-post limit, N or more EMPs
$MultiPostHistSize = 5000; # in the history queue cause a rejection
##
## MMF filter
##
## Filter out strings 'make money fast', 'cash cash cash',
## any string that completely matches
## $... CAPITAL LETTERS AND SPACES $...
## The "o" option on the pattern is important for speed.
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
$i = "$hdr{'From'} $hdr{'Subject'} $hdr{'Lines'}";
push(@history, $i);
$history{$i}++;
## If post appears more than limit, then reject as EMP
$rval = "EMP rejected" if ($history{$i} > $MaxMultiPosts);
## Trim old entries from history file. Remember that
## data structure stays around, even between filter.perl
## reloads.
while ($#history > $MultiPostHistSize) {
$tmp_hist = shift(@history);
if ($history{$tmp_hist} < 2) {
delete $history{$tmp_hist};
} else {
$history{$tmp_hist}--;
}
}
## return EMP value, rejected or "" for accepted
return $rval;
}
Technical Details
Message-ID:
<334FFBCC.55F71787@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-mailShow Full Headers
Complete Article Headers
Message-ID: <334FFBCC.55F71787@spinne.com> Subject: INN filter.perl update -- filter out spam Date: Sat, 12 Apr 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: 234391058 Organization: Spinne http://spinne.com Newsgroups: news.software.nntp