2
# Licensed to the Apache Software Foundation (ASF) under one or more
3
# contributor license agreements. See the NOTICE file distributed with
4
# this work for additional information regarding copyright ownership.
5
# The ASF licenses this file to you under the Apache License, Version 2.0
6
# (the "License"); you may not use this file except in compliance with
7
# the License. You may obtain a copy of the License at:
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# # Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
18
###########################################################################
20
package Mail::SpamAssassin::Plugin::PhishTag;
25
use Mail::SpamAssassin;
26
use Mail::SpamAssassin::Logger;
30
our @ISA = qw(Mail::SpamAssassin::Plugin);
33
my ($class, $mailsa)=@_;
34
$class=ref($class) ||$class;
35
my $self = $class->SUPER::new($mailsa);
37
$self->set_config($mailsa->{conf});
42
my($self, $conf) = @_;
46
setting => 'trigger_target',
47
type => $Mail::SpamAssassin::Conf::CONF_TYPE_HASH_KEY_VALUE,
52
setting => 'trigger_config',
53
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
59
setting => 'trigger_ratio',
60
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC,
65
$conf->{parser}->register_commands(\@cmds);
70
my ($self, $params) = @_;
71
my $pms = $params->{permsgstatus};
73
#initialize the PHISHTAG data structure for
74
#saving configuration information
75
$pms->{PHISHTAG} = {};
76
$pms->{PHISHTAG}->{triggers}={};
77
$pms->{PHISHTAG}->{targets}=[];
79
#read the configuration info
80
$self->read_configfile($params);
81
$self->read_settings($params);
85
my ($self, $params) = @_;
86
my $pms = $params->{permsgstatus};
88
my $triggers= $pms->{PHISHTAG}->{triggers};
89
my $targets= $pms->{PHISHTAG}->{targets};
90
while (my ($tname,$ttarget)=each %{$pms->{conf}->{trigger_target}}){
91
push @$targets, [$ttarget, $tname];
98
my ($self, $params) = @_;
99
my $pms = $params->{permsgstatus};
101
#nothing interesting here if there is not a configuration file
102
return if($pms->{conf}->{trigger_config} !~/\S/);
104
my $triggers= $pms->{PHISHTAG}->{triggers};
105
my $targets= $pms->{PHISHTAG}->{targets};
109
open(F, '<', $pms->{conf}->{trigger_config});
110
for ($!=0; <F>; $!=0) {
111
#each entry is separated by blank lines
112
undef($target) if(!/\S/);
114
#lines that start with pound are comments
117
#an entry starts with a URL line prefixed with the word "target"
118
if(/^target\s+(\S+)/){
120
push @$targets,$target;
122
#add the test to the list of listened triggers
123
#and to the triggers of the last target
124
elsif(defined $target){
130
defined $_ || $!==0 or
131
$!==EBADF ? dbg("PHISHTAG: error reading config file: $!")
132
: die "error reading config file: $!";
133
close(F) or die "error closing config file: $!";
137
my ($self, $params) = @_;
138
my $pms = $params->{permsgstatus};
139
my $rulename = $params->{rulename};
141
#mark the rule as hit
142
if(defined($pms->{PHISHTAG}->{triggers}->{$rulename})){
143
$pms->{PHISHTAG}->{triggers}->{$rulename}=1;
144
dbg("PHISHTAG: $rulename has been caught\n");
148
sub check_post_learn {
149
my ($self, $params) = @_;
150
my $pms = $params->{permsgstatus};
152
#find out which targets have fulfilled their requirements
153
my $triggers= $pms->{PHISHTAG}->{triggers};
154
my $targets= $pms->{PHISHTAG}->{targets};
156
foreach my $target(@$targets){
157
my $uri= $$target[0];
159
#all the triggers of a target have to exist for it to be fulfilled
160
foreach my $i(1..$#$target){
161
if(! $triggers->{$$target[$i]}){
168
dbg("PHISHTAG: Fulfilled $uri\n");
172
if(scalar(@filled) &&
173
$pms->{conf}->{trigger_ratio} > rand(100)){
174
$pms->{PHISHTAG}->{letgo}=0;
175
$pms->{PHISHTAG}->{uri}=$filled[int(rand(scalar(@filled)))];
177
dbg("PHISHTAG: Decided to keep this email and point to ".
178
$pms->{PHISHTAG}->{uri});
179
#make sure that SpamAssassin does not remove this email
180
$pms->got_hit("PHISHTAG_TOSS",
185
dbg("PHISHTAG: Will let this email to SpamAssassin's discretion\n");
186
$pms->{PHISHTAG}->{letgo}=1;
190
#nothing interesting here, if we will not rewrite the email
191
if($pms->{PHISHTAG}->{letgo}){
195
my $pristine_body=\$pms->{msg}->{pristine_body};
196
#dbg("PRISTINE>>\n".$$pristine_body);
198
my $uris = $pms->get_uri_detail_list();
200
while (my($uri, $info) = each %{$uris}) {
201
if(defined ($info->{types}->{a})){
202
$$pristine_body=~s/$uri/$pms->{PHISHTAG}->{uri}/mg;
205
dbg("PRISTINE>>\n".$$pristine_body);
213
PhishTag - SpamAssassin plugin for redirecting links in incoming emails.
219
loadplugin Mail::SpamAssassin::Plugin::PhishTag
222
trigger_target RULE_NAME http://www.antiphishing.org/consumer_recs.html
228
PhishTag enables administrators to rewrite links in emails that trigger certain
229
tests, preferably anti-phishing blacklist tests. The plugin will inhibit the
230
blocking of a portion of the emails that trigger the test by SpamAssassin, and
231
let them pass to the users' inbox after the rewrite. It is useful in providing
232
training to email users about company policies and general email usage.
236
The following options can be set by modifying the configuration file.
240
=item * trigger_ratio percentage_value
242
Sets the probability in percentage that a positive test will trigger the
243
email rewrite, e.g. 0.1 will rewrite on the average 1 in 1000 emails that
246
=item * trigger_target RULE_NAME http_url
248
The name of the test which would trigger the email rewrite; all the URLs
249
will be replaced by http_url.
255
The source of this plugin is avaliable at:
256
http://umut.topkara.org/PhishTag/PhishTag.pm
257
a sample configuration file is also available:
258
http://umut.topkara.org/PhishTag/PhishTag.cf
262
Check the list of tests performed by SpamAssassin to modify the
263
configuration file to match your needs from
264
http://spamassassin.apache.org/tests.html
268
Umut Topkara, 2008, E<lt>umut@topkara.orgE<gt>
269
http://umut.topkara.org
271
=head1 COPYRIGHT AND LICENSE
273
This plugin is free software; you can redistribute it and/or modify
274
it under the same terms as SpamAssassin itself, either version 3.2.4
275
or, at your option, any later version of SpamAssassin you may have