-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsa-phish-gen
executable file
·186 lines (174 loc) · 6.2 KB
/
sa-phish-gen
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
#!/bin/bash
##################################################################
# Copyright (C) 2008 - Jon Agland #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful,#
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
##################################################################
# ---------------------------------------------------------------
# IMPORTANT NOTE: This version has *not* been extensively tested.
# ---------------------------------------------------------------
# Name: sa-phish-gen
# Version: 1.1.1
# Description: This script (sa-phish-gen) is intended to parse the list from
# the anti-phishinge-email-reply project into a SpamAssassin config file (.cf)
# See http://code.google.com/p/anti-phishing-email-reply/
# Usage: ./sa-phish-gen <filename>
# Example usage:./sa-phish-gen phishing_reply_addresses > sa-phish.cf
#
#
#################################################################
# ChangeLog
#
# 1.1.1 - change to mailaddrreg / sed line submitted by Todd Aiken 09/12/2012
# Script now looks for the following symbols in an address and prepends
# them with a backslash:
# . _ ? + \ * & = # @ ( )
# 1.1 - changes submitted by Thomas Bullinger 20/03/2012
# http://consult.btoy1.net
#
# Adapted to personal taste and BASH specific constructs
# Added rules for type "E" records
#################################################################
###################################################################
# Adjust these values to your own desire. The defaults are set *very* high.
#
ONEDAYSCORE="1000"; ONEDAYSCORE=5
ONEWEEKSCORE="500"; ONEWEEKSCORE=4
ONEMONTHSCORE="200"; ONEMONTHSCORE=3
THREEMONTHSCORE="100"; THREEMONTHSCORE=2
SIXMONTHSCORE="50"; SIXMONTHSCORE=1
ONEYEARSCORE="20"; ONEYEARSCORE=0.75
# This score should only get used for over 1 year old.
BASESCORE="10"; BASESCORE=0.5
mailaddrreg() {
# Convert e-mail address from [email protected] to me\@domain\.com
saaddr=$(echo "$addr" | sed -e 's|[\.\/\_\?\+\\\*\&\=\#\@\(\)]|\\&|g')
}
createreplytotest() {
mailaddrreg;
# This should deal with those with a Reply-To or other header
# containing the listed e-mail address
# Results containing the Type A
echo "# $addr is listed in a Reply-To header"
echo "header SA_PHISH_GEN_REPLYTO_$value reply-to =~ /$saaddr/i"
echo "score SA_PHISH_GEN_REPLYTO_$value $score"
echo "describe SA_PHISH_GEN_REPLYTO_$value $addr is listed in http://code.google.com/p/anti-phishing-email-reply"
}
createfromtest() {
mailaddrreg;
# This should deal with those with a From header
# containing the listed e-mail address
# Results containing the Type B
echo "# $addr is listed in a From header"
echo "header SA_PHISH_GEN_FROM_$value From =~ /$saaddr/i"
echo "score SA_PHISH_GEN_FROM_$value $score"
echo "describe SA_PHISH_GEN_FROM_$value $addr is listed in http://code.google.com/p/anti-phishing-email-reply"
}
createbodytest() {
mailaddrreg;
# This should deal with those with the content/body
# containing the list e-mail address
# Results containing the Type C or D
echo "# $addr is listed in the email body"
echo "body SA_PHISH_GEN_BODY_$value /\b$saaddr\b/i"
echo "score SA_PHISH_GEN_BODY_$value $score"
echo "describe SA_PHISH_GEN_BODY_$value $addr is listed in http://code.google.com/p/anti-phishing-email-reply"
}
createinvalidtest() {
mailaddrreg;
# This should deal with those addresses which might
# receive replies it were not intended to receive
# the replies.
# Results containing the Type E
echo "# $addr is very likely invalid"
echo "body SA_PHISH_GEN_INVALID_$value /\b$saaddr\b/i"
echo "score SA_PHISH_GEN_INVALID_$value 0.05"
echo "describe SA_PHISH_GEN_INVALID_$value $addr is listed in http://code.google.com/p/anti-phishing-email-reply"
}
# This function uses the Last Seen date to determine a score.
datescorer() {
# Takes the date from the list and converts it to EPOCH/Unix time
dateinepoch=$(date --date=$thedate +%s)
# Todays date in EPOCH/Unix time
todaydate=$(date +%s)
# Some definitions of - very rough.
oneday=$(($todaydate - 86400))
oneweek=$(($todaydate - (7*86400)))
onemonth=$(($todaydate - (28*86400)))
threemonth=$(($todaydate - (72*86400)))
sixmonth=$(($todaydate - (182*86400)))
oneyear=$(($todaydate - (365*86400)))
# Set the Base score
# Anything over year should get this score.
score=$BASESCORE
# Now check if the listed date is greater than than
# One day ago...
if [ $dateinepoch -ge $oneday ]; then
score=$ONEDAYSCORE
return
fi
# One week ago...
if [ $dateinepoch -ge $oneweek ]; then
score=$ONEWEEKSCORE
return
fi
# One month ago...
if [ $dateinepoch -ge $onemonth ]; then
score=$ONEMONTHSCORE
return
fi
# Three months ago...
if [ $dateinepoch -ge $threemonth ]; then
score=$THREEMONTHSCORE
return
fi
# Six Months ago..
if [ $dateinepoch -ge $sixmonth ]; then
score=$SIXMONTHSCORE
return
fi
# One year ago.
if [ $dateinepoch -ge $oneyear ]; then
score=$ONEYEARSCORE
return
fi
}
# Main body of code.
# Get the newest list of phishing reply addresses
wget -q 'https://aper.svn.sourceforge.net/svnroot/aper/phishing_reply_addresses' -O /tmp/phishing_reply_addresses
value=0
awk '!/#/ {gsub(/,/," "); print}' /tmp/phishing_reply_addresses | while read addr type thedate
do
# Loop count for unique rules
value=$(($value + 1));
# Call scoring function
datescorer;
# This choose what lines we create
# in somone instances we create more than one
# We don't really have a test for D (obfuscated in body)
if [[ $type =~ A ]]; then
createreplytotest;
fi
if [[ $type =~ B ]]; then
createfromtest;
fi
if [[ $type =~ C ]]; then
createbodytest;
fi
if [[ $type =~ D ]]; then
createbodytest;
fi
if [[ $type =~ E ]]; then
createinvalidtest;
fi
done
# We are done
exit 0