| 1 | |||
| 2 | package SyslogScan::Daemon::BlacklistDetector; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Carp; | ||
| 7 | use Plugins; | ||
| 8 | use Plugins::SimpleConfig; | ||
| 9 | use SyslogScan::Daemon::Plugin; | ||
| 10 | |||
| 11 | our(@ISA) = qw(SyslogScan::Daemon::Plugin); | ||
| 12 | our $VERSION = 0.44; | ||
| 13 | |||
| 14 | # | ||
| 15 | # These are hard-coded rather than configured because they're universal and | ||
| 16 | # should be shared by all users of this code. | ||
| 17 | # | ||
| 18 | # These are 2nd-level matches that explain away bounces. The first-level | ||
| 19 | # match is currently done in BlacklistDetector/Postfix.pm | ||
| 20 | # | ||
| 21 | my $recipient_reject_rx = qr{Blacklist for this recipient|Recipient address rejected|mailbox \S+ is blacklisted|Email address unknown|This user doesn't have a \S+ account|This email receives too much spam, please remove it from the To: |to=<(.*?)>.*554 blacklisted \(\1\)|550 <\S+> is not a valid mailbox|sorry, that domain isn't in my list of allowed rcpthosts|550 \S+ unknown user account}; | ||
| 22 | |||
| 23 | my $realtime_reject_rx = qr{Spamming not allowed|Stop Spamming\.\s*You are being monitored!|Remove lines beginning with|The EMail\s+is Blacklisted}; | ||
| 24 | |||
| 25 | my $content_reject_rx = qr{(?:\b|\d\d\d-|\s)(in the content|out of your message and resend|A URL in the email is Blacklisted|[bB]lacklisted URL in (?:message|mail)|Message contains blacklisted domain|contains links to an IP address that is blacklisted|because its checksum is in|message content unacceptable|Mail contained a URL rejected by|No user with this name is found at|URL MATCH|The EMail \S+\@\S+ is Blacklisted|http://postmaster.info.aol.com/errors/554hvub1.html|user account is.*?blacklisted|Matched regular expression|\S+\@\S+ address is blacklisted|No such user|this domain doesn't accept mail|Blacklisted file extension detected|This message matches a blacklisted|message was identified as junk mail, score|Message body contains|http:\/\/lookup\.uribl\.com/\?domain=|Blocked by p licy: blacklisted URL in mail|Message rejected - blacklisted URLs|For security reasons we do not accept messages containing images|URL in message blacklisted)\b}; | ||
| 26 | |||
| 27 | my $sender_reject_rx = qr{(The From Address\s+blacklisted or blank|Sender address rejected|Sender is on our global blacklist|The EMail \(from\)\s+is Blacklisted|550 Sender verify failed)}; | ||
| 28 | |||
| 29 | my %defaults = ( | ||
| 30 | debug => 0, | ||
| 31 | configfile => '', | ||
| 32 | ); | ||
| 33 | |||
| 34 | sub config_prefix { 'bld_' } | ||
| 35 | |||
| 36 | sub parse_config_line { simple_config_line(\%defaults, @_); } | ||
| 37 | |||
| 38 | sub new { simple_new(\%defaults, @_); } | ||
| 39 | |||
| 40 | sub preconfig | ||
| 41 | { | ||
| 42 | my ($self, $ssd_configfile) = @_; | ||
| 43 | |||
| 44 | $self->set_api($ssd_configfile, | ||
| 45 | process_match => { optional => 1 }, | ||
| 46 | greylisted => { optional => 1 }, | ||
| 47 | realtime_reject => { optional => 1 }, | ||
| 48 | recipient_reject => { optional => 1 }, | ||
| 49 | sender_reject => { optional => 1 }, | ||
| 50 | content_reject => { optional => 1 }, | ||
| 51 | blacklisted => { optional => 1 }, | ||
| 52 | ); | ||
| 53 | } | ||
| 54 | |||
| 55 | sub matched_line | ||
| 56 | { | ||
| 57 | my ($self, $logfile, $rx) = @_; | ||
| 58 | |||
| 59 | for my $plugin (@{$self->{logs}{$logfile}{$rx}}) { | ||
| 60 | my %info = $plugin->invoke('parse_logs', $logfile, $rx); | ||
| 61 | next unless %info; | ||
| 62 | $self->process_match(%info); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | sub process_match | ||
| 67 | { | ||
| 68 | my ($self, %info) = @_; | ||
| 69 | |||
| 70 | my $status = $info{status}; | ||
| 71 | my $logline = $info{logline}; | ||
| 72 | my $error = $info{error} || $info{logline}; | ||
| 73 | if ($self->{debug} > 5) { | ||
| 74 | print "PROCESS_MATCH:\n"; | ||
| 75 | for my $k (sort keys %info) { | ||
| 76 | print "\t$k=\t$info{$k}\n"; | ||
| 77 | } | ||
| 78 | if ($self->{debug} > 7) { | ||
| 79 | Carp::longmess("debugging..."); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | if ($status eq 'deferred') { | ||
| 84 | if ($error =~ /\bgreylisted\b/i) { | ||
| 85 | print STDERR "Greylisted $logline\n" if $self->{debug}; | ||
| 86 | $self->greylisted(%info); | ||
| 87 | return; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | if ($status eq 'bounced') { | ||
| 92 | if ($error =~ /$recipient_reject_rx/) { | ||
| 93 | print STDERR "Bad recipient rejection $logline\n" if $self->{debug}; | ||
| 94 | $self->recipient_reject(%info); | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | if ($error =~ /$sender_reject_rx/) { | ||
| 98 | print STDERR "Bad sender rejection $logline\n" if $self->{debug}; | ||
| 99 | $self->sender_reject(%info); | ||
| 100 | return; | ||
| 101 | } | ||
| 102 | if ($error =~ /$content_reject_rx/) { | ||
| 103 | print STDERR "Bad content: $1 - $logline\n" if $self->{debug}; | ||
| 104 | $self->content_reject(%info); | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | if ($error =~ /$realtime_reject_rx/) { | ||
| 108 | print STDERR "Realtime spam rejection $logline\n" if $self->{debug}; | ||
| 109 | $self->realtime_reject(%info); | ||
| 110 | return; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | print STDERR "Blacklisted $logline\n" if $self->{debug}; | ||
| 115 | $self->blacklisted(%info); | ||
| 116 | } | ||
| 117 | |||
| 118 | package SyslogScan::Daemon::BlacklistDetector::Plugin; | ||
| 119 | |||
| 120 | use SyslogScan::Daemon::Plugin; | ||
| 121 | use strict; | ||
| 122 | use warnings; | ||
| 123 | |||
| 124 | our @ISA = qw(SyslogScan::Daemon::Plugin); | ||
| 125 | |||
| 126 | 1; |