Thread View: news.software.nntp
2 messages
2 total messages
Started by Jeff Garzik
Wed, 21 May 1997 00:00
INN: Perl spam filter improved
Author: Jeff Garzik
Date: Wed, 21 May 1997 00:00
Date: Wed, 21 May 1997 00:00
195 lines
6152 bytes
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--
Re: INN: Perl spam filter improved
Author: Craig Dewick
Date: Thu, 29 May 1997 00:00
Date: Thu, 29 May 1997 00:00
31 lines
1780 bytes
1780 bytes
In <3383A7FB.77E9E66F@spinne.com> Jeff Garzik <jeff.garzik@spinne.com> writes:
>Enclosed is an update to my Perl spam filter. It has been running on my
>system for more than a week.
I've installed the filter on my news server and it works very well, however
it's missing one important type of SPAM article - the multi-level marketting
advertisement. These are not trapped by Jeff's filter in it's current form.
Something that looks for the string 'MLM', or something that will match
variants of 'multi-level marketting', with or without capitalisation of the
first letters of each word, and with or without the hyphen, etc. would make
the filter even better.
Another thing that might be worth considering is to do something like what
can be done with sendmail and build a 'spammers' file containing domain
names of known spamming sites, and if an article comes from one of these, it
can be despatched to /dev/null before being accepted.
Ideas?
Regards,
Craig.
--
Craig Dewick. Send email to 'cdewick@lios.apana.org.au'
Point a web browser at 'http://lios.apana.org.au/~cdewick/sun_ark.html' to
access my collection of Sun information and links to other places.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads