SpamDetector/SpamSink.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 62 CC 4 SCAR 15.9
CC
4
Cov
0%
parse_logs
12.0
preconfig
6.0
config_prefix
2.0
CRAP 4.9
1  
2 package SyslogScan::Daemon::SpamDetector::SpamSink;
3  
4 use strict;
5 use warnings;
6 use SyslogScan::Daemon::SpamDetector::Plugin;
7 use Plugins::SimpleConfig;
8 our(@ISA) = qw(SyslogScan::Daemon::SpamDetector::Plugin);
9  
10 my %defaults = (
11 rx_extra => '.',
12 rx_month => '(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)',
13 rx_date => '',
14 logfile => '/var/log/syslog',
15 debug => 0,
16 );
17  
18 sub config_prefix { 'sdspamsink_' }
19  
20 sub parse_config_line { simple_config_line(\%defaults, @_); }
21  
22 sub new { simple_new(\%defaults, @_); }
23  
24 our $Mon;
25 our $Date;
26 our $iprx;
27  
28 sub preconfig
29 {
30 my $self = shift;
31 $self->{Mon} = qr/$self->{rx_month}/;
32 $self->{Date} = $self->{rx_date} ? qr/$self->{rx_date}/ : qr/$self->{Mon} [ 1-3][0-9] \d\d:\d\d:\d\d/;
33 $self->{Extra} = qr/$self->{rx_extra}/;
34 }
35  
36 sub get_logs
37 {
38 my $self = shift;
39 my $Date = $self->{Date};
40 return (
41 $self->{logfile} => [
42 # Oct 27 21:12:51 idiom spamsink: Message-ID: <000f01c6fa8a$2847c1e0$083fb0ec@office42c36499>
43 qr{^$Date (\S+) spamsink: Message-I[dD]: <(.*?)>},
44 ],
45 );
46 }
47  
48 sub parse_logs
49 {
50 my ($self, $logfile, $rx) = @_;
51 my $debug = $self->{debug};
52 my $logline = $_;
53 my ($host, $id) = ($1, $2);
54 print "SpamSink: $host $id\n" if $debug;
55 return () if $self->{Extra} && ! /$self->{Extra}/;
56 return (
57 status => 'spam',
58 id => $id,
59 logline => $_,
60 match => 'SpamSink',
61 score => 'spamsink',
62 hideid => 1,
63 host => $host,
64 );
65 }
66  
67 1;
68  
69 =head1 NAME
70  
71 SyslogScan::Daemon::SpamDetector::SpamSink - notice messages sent to a honeypot
72  
73 =head1 SYNOPSIS
74  
75 plugin SyslogScan::Daemon::SpamDetector as sd_
76  
77 sd_plugin SyslogScan::Daemon::SpamDetector::SpamSink
78 debug 0
79 logfile /var/log/mail.info
80  
81 =head1 DESCRIPTION
82  
83 Watch the system log files for message sent to spam honeypots.
84  
85 It looks for the following kind of message line:
86  
87 $Date \S+ spamsink: Message-I[dD]: <.*?>
88  
89 Lines like this can be generate by forwarding mail to a program like:
90  
91 #!/bin/sh
92 perl -e '
93 $x = <>;
94 while (<>) {
95 last if /^$/;
96 next unless /^(Message-I[dD]: .*)/;
97 $y = $1;
98 }
99 print "$y\n"
100 if $x =~ /\@/
101 && $y =~ /\@/
102 && $x !~ /mailer-daemon/i
103 && $x !~ /postmaster/ ;
104 ' | /usr/bin/logger -p mail.info -t spamsink
105  
106 =head1 CONFIGURATION PARAMETERS
107  
108 The following configuration parameters are supported:
109  
110 =over 4
111  
112 =item debug
113  
114 Debugging on (1) or off (0).
115  
116 =item logfile
117  
118 Which logfile to watch (default: C</var/log/syslog>).
119  
120 =back
121  
122 =head1 SEE ALSO
123  
124 L<SyslogScan::Daemon::SpamDetector>
125  
126 =head1 THANK THE AUTHOR
127  
128 If you need high-speed internet services (T1, T3, OC3 etc), please
129 send me your request-for-quote. I have access to very good pricing:
130 you'll save money and get a great service.
131  
132 =head1 LICENSE
133  
134 Copyright(C) 2006 David Muir Sharnoff <muir@idiom.com>.
135 This module may be used and distributed on the same terms
136 as Perl itself.
137