/usr/bin/spamalyze is in libnet-rblclient-perl 0.5-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | #!/usr/bin/perl
# program to analyze an mbox
# and show how different RBL's would affect it.
# Asher Blum <asher@wildspark.com> Fri May 7 2004
# licensed under the same terms as Perl
my $max_blockers_shown = 10;
use strict;
use Net::RBLClient;
use Data::Dumper;
my $rbl = Net::RBLClient->new( max_time => 5, max_hits => 8 );
my @messages;
my %block_freq;
my $msg = '';
#my %netblocks = read_netblocks('netblocks');
my %netblocks = (
'210.0.0.0/7' => 'APNIC-CIDR-BLK2',
'217.0.0.0/8' => '217-RIPE',
'64.51.0.0/16' => 'DSLNET-4',
'63.68.128.0/20' => 'UU-63-68-128',
'217.32.0.0/16' => 'UK-BT-20000920',
'206.13.0.0/17' => 'PBI-NET',
'200.128.0.0/9' => 'BRAZIL-BLK2',
'66.95.0.0/16' => 'NASDSL-BLK2',
'216.40.192.0/14' => 'EVRY-BLK-6',
);
my %blocker_char; # character for each blocker
my @blocker_chars = ( 'A' .. 'Z', 0 .. 9, 'a' .. 'z' );
while(<>) {
if(/^From /) {
handle_msg($msg);
$msg = <>;
}
$msg .= $_;
}
my @blockers = sort {$block_freq{ $b } <=> $block_freq{ $a }} keys %block_freq;
my $nblockers = @blockers;
#print Dumper(\@blockers); exit 0;
foreach my $message(@messages) {
my $block_string = '';
for(0..$nblockers) {
last if $_ >= $max_blockers_shown;
$block_string .= $message->{ blockers }{ $blockers[ $_ ] } ?
$blocker_chars[ $_ ] : '.';
}
printf("%-15.15s %30.30s %s %-16.16s\n",
$message->{ ip },
substr($message->{ hostname }, -30, 30),
$block_string,
$message->{ netblock },
);
}
print "\n";
for(0..$nblockers) {
printf "%s %-30.30s %6d\n",
$blocker_chars[ $_ ],
$blockers[ $_ ],
$block_freq{ $blockers[ $_ ] },
}
sub handle_msg {
my $msg = shift or return undef;
return undef if $msg =~ /From: root\@wildspark.com/;
my($h, $b) = split /\n\n/, $msg;
$h =~ s/\n\s+/ /g;
if($h =~ /Received:.*\[(\d+\.\d+\.\d+\.\d+)\].*by/) {
my $addr = $1;
$rbl->lookup($addr);
my @blockers = $rbl->listed_by;
#printf "%-16.16s %s\n", $addr, $blockers;
$block_freq{ $_ } ++ for @blockers;
my $hostname = hostname($addr);
push @messages, {
ip => $addr,
hostname => $hostname,
blockers => { map(($_ => 1), @blockers) },
netblock => get_netblock($addr),
};
#printf("%-16.16s %-16.16s %s\n", $addr, get_netblock($addr), $hostname);
}
else {
#die" No match: $msg\n";
#warn "No match";
}
}
sub get_netblock {
my $addr = shift;
foreach my $n(keys %netblocks) {
if(in_netblock($n, $addr)) {
return $netblocks{ $n };
}
}
return "x";
foreach my $registry qw( arin apnic ripe ){
my $res = `whois $addr\@whois.arin.net`;
return $1 if $res =~ /Netblock: (.+)/;
}
return "UNKNOWN";
}
sub in_netblock {
use Socket;
my($cidr, $addr) = @_;
#invoke with ('217.32.0.0/16', '128.222.123.0');
return undef unless $addr =~ /^(\d+)+\.(\d+)\.(\d+)\.(\d+)$/;
my $n = pack('C4', $1, $2, $3, $4);
return undef unless $cidr =~ m|^(\d+)+\.(\d+)\.(\d+)\.(\d+)/(\d+)$|;
my $block = pack('C4', $1, $2, $3, $4);
my $ones = $5;
my $zeros = 32 - $ones;
my $mask = pack('B32', '1' x $ones . '0' x $zeros);
#print "mask=" . inet_ntoa($mask); exit;
my $c1 = $block & $mask;
my $c2 = $n & $mask;
#print "c1=" . inet_ntoa($c1) . " c2=" . inet_ntoa($c2) . "\n";
return 1 if $c1 eq $c2;
0;
}
sub read_netblocks {
my $fn = shift;
open F, "$fn" or die "Can't open $fn: $!";
my %n;
while(<F>) {
next unless /(\S+)\s+(\S+)/;
$n{ $1 } = $2;
}
close F;
return %n;
}
sub hostname {
my $address = shift;
my ($name,$aliases,$addrtype,$length,@addrs);
$name = 'TIMEOUT';
eval {
alarm 1;
local $SIG{ALRM} = sub { die "alarm\n" };
($name,$aliases,$addrtype,$length,@addrs) =
gethostbyaddr(inet_aton($address), AF_INET);
alarm 0;
};
$name;
}
__END__
=head1 NAME
spamalyze - Apply multiple Realtime Blackhole Lists to all messages in an mbox
=head1 SYNOPSIS
spamalyze myspam.mbox
spamalyze goodstuff.mbox
tail -3000 some.mbox | spamalzse
=head1 DESCRIPTION
Spamalyze reads in an mbox file containing multiple mail messages and looks up the originating server of each message on multiple Realtime Blackhole Lists. Spamalyze uses L<Net::RBLClient>.
Spamalyze lets you find out what the impact would be of filtering via various RBL's.
The output report contains two sections. The first section has one line per email message, showing:
=over 4
=item * Sending IP address
=item * Sending hostname if any
=item * Whether the IP is on a small list of possibly spammish netblocks
=item * A list of letters representing RBL's which returned responses for this IP address
=back
The second section contains one line for each of the top RBL's. That is, the RBL's which produced the most hits. The RBL's are listed in decreasing order of hits. Each line contains:
=over 4
=item * The letter assigned to the RBL - C<A> is the one with the most hits
=item * The domain name of the RBL
=item * The number of hits from the RBL
=back
=head1 OPTIONS
No options.
=head1 SEE ALSO
L<Net::RBLClient(3)>
=head1 AUTHOR
Asher Blum E<lt>F<asher@wildspark.com>E<gt>
=head1 COPYRIGHT
Copyright (C) 2004 Asher Blum. All rights reserved.
This code is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut
|