various updates
[exim-website.git] / system_filter.exim
1 # Exim filter
2 ## Version: 0.10
3
4 ## If you haven't worked with exim filters before, read
5 ## the install notes at the end of this file.
6
7 #
8 # Only run any of this stuff on the first pass through the
9 # filter - this is an optomisation for messages that get
10 # queued and have several delivery attempts
11 #
12 # we express this in reverse so we can just bail out
13 # on inappropriate messages
14 #
15 if not first_delivery
16 then
17   finish
18 endif
19
20 # Check for MS buffer overruns as per latest BUGTRAQ.
21 # http://www.securityfocus.com/frames/?content=/templates/article.html%3Fid%3D61
22 # This could happen in error messages, hence its placing
23 # here...
24 # We substract the first n characters of the date header
25 # and test if its the same as the date header... which
26 # is a lousy way of checking if the date is longer than
27 # n chars long
28 if ${length_80:$header_date:} is not $header_date:
29 then
30   fail text "This message has been rejected because it has\n\
31              \tan overlength date field which can be used\n\
32              \tto subvert Microsoft mail programs\n\
33              \tThe following URL has further information\n\
34              \thttp://www.securityfocus.com/frames/?content=/templates/article.html%3Fid%3D61"
35   seen finish
36 endif
37
38 # This is a nasty compromise.
39 # This crud is now being sent with a <> envelope sender, but
40 # blocking all error messages that pattern match prevents
41 # bounces getting back.... so we fudge it somewhat
42 if $header_from: contains "@sexyfun.net"
43 then
44   fail text "This message has been rejected since it has\n\
45                 \tthe signature of a known virus in the header."
46   seen finish
47 endif
48 if error_message and $header_from: contains "Mailer-Daemon@"
49 then
50   # looks like a real error message - just ignore it
51   finish
52 endif
53
54 # Look for single part MIME messages with suspicious name extensions
55 # Check Content-Type header [vb2_regexp]
56 if $header_content-type: matches "(?:file)?name=(\"[^\"]+\\\\.(?:vb[se]|ws[fh]|jse?|exe|com|shs|bat|scr|pif)\"|[\\\\w.-]+\\\\.(?:vb[se]|ws[fh]|jse?|exe|com|shs|bat|scr|pif))"
57 then
58   fail text "This message has been rejected because it has\n\
59              \ta potentially executable attachment $1\n\
60              \tThis form of attachment has been used by\n\
61              \trecent viruses such as that described in\n\
62              \thttp://www.fsecure.com/v-descs/love.htm\n\
63              \tIf you meant to send this file then please\n\
64              \tpackage it up as a zip file and resend it."
65   seen finish
66 endif
67
68 # Attempt to catch embedded VBS attachments
69 # in emails.   These were used as the basis for 
70 # the ILOVEYOU virus and its variants
71 # [vb_regexp]
72 if $message_body matches "(?:Content-(?:Type:(?>\\\\s*)[\\\\w-]+/[\\\\w-]+|Disposition:(?>\\\\s*)attachment);(?>\\\\s*)(?:file)?name=|begin(?>\\\\s+)[0-7]{3,4}(?>\\\\s+))(\"[^\"]+\\\\.(?:vb[se]|ws[fh]|jse?|exe|com|shs|bat|scr|pif)\"|[\\\\w.-]+\\\\.(?:vb[se]|ws[fh]|jse?|exe|com|shs|bat|scr|pif))[\\\\s;]"
73 then
74   fail text "This message has been rejected because it has\n\
75              \ta potentially executable attachment $1\n\
76              \tThis form of attachment has been used by\n\
77              \trecent viruses such as that described in\n\
78              \thttp://www.fsecure.com/v-descs/love.htm\n\
79              \tIf you meant to send this file then please\n\
80              \tpackage it up as a zip file and resend it."
81   seen finish
82 endif
83
84 #### Version history
85 #
86 # 0.01 5 May 2000
87 #       Initial release
88 # 0.02 8 May 2000
89 #       Widened list of content-types accepted, added WSF extension
90 # 0.03 8 May 2000
91 #       Embedded the install notes in for those that don't do manuals
92 # 0.04 9 May 2000
93 #       Check global content-type header.  Efficiency mods to REs
94 # 0.05 9 May 2000
95 #       More minor efficiency mods, doc changes
96 # 0.06 20 June 2000
97 #       Added extension handling - thx to Douglas Gray Stephens & Jeff Carnahan
98 # 0.07 19 July 2000
99 #       Latest MS Outhouse bug catching
100 # 0.08 19 July 2000
101 #       Changed trigger length to 80 chars, fixed some spelling
102 # 0.09 29 September 2000
103 #       More extensions... its getting so we should just allow 2 or 3 through
104 # 0.10 18 January 2001
105 #       Removed exclusion for error messages - this is a little nasty
106 #       since it has other side effects, hence we do still exclude
107 #       on unix like error messages
108 #
109 #### Install Notes
110 #
111 # Exim filters run the exim filter language - a very primitive
112 # scripting language - in place of a user .forward file, or on
113 # a per system basis (on all messages passing through).
114 # The filtering capability is documented in the main set of manuals
115 # a copy of which can be found on the exim web site
116 #       http://www.exim.org/
117 #
118 # To install, copy the filter file (with appropriate permissions)
119 # to /etc/exim/system_filter.exim and add to your exim config file
120 # [location is installation depedant - typicaly /etc/exim/config ]
121 # at the top the line:-
122 #       message_filter = /etc/exim/system_filter.exim
123 #       message_body_visible = 5000
124 #
125 # Any message that matches the filter will then be bounced.
126 # If you wish you can change the error message by editing it
127 # in the section above - however be careful you don't break it.
128 #
129 # After install exim should be restarted - a kill -HUP to the
130 # daemon will do this.
131 #
132 #### LIMITATIONS
133 #
134 # This filter tries to parse MIME with a regexp... that doesn't
135 # work too well.  It will also only see the amount of the body
136 # specified in message_body_visible
137 #
138 #### BASIS
139 #
140 # The regexp that is used to pickup MIME/uuencoded parts is replicated
141 # below (in perl format).  You need to remember that exim converts
142 # newlines to spaces in the message_body variable.
143 #
144 #  (?:Content-                                  # start of content header
145 #  (?:Type: (?>\s*)                             # rest of c/t header
146 #    [\w-]+/[\w-]+                              # content-type (any)
147 #    |Disposition: (?>\s*)                      # content-disposition hdr
148 #    attachment)                                        # content-disposition
149 #  ;(?>\s*)                                     # ; space or newline
150 #  (?:file)?name=                               # filename=/name= 
151 #  |begin (?>\s+) [0-7]{3,4} (?>\s+))           # begin octal-mode
152 #  (\"[^\"]+\.                                  # quoted filename.
153 #       (?:vb[se]                               # list of extns
154 #       |ws[fh]
155 #       |jse?
156 #       |exe
157 #       |com
158 #       |shs
159 #       |bat
160 #       |scr
161 #       |pif)
162 #       \"                                      # end quote
163 #  |[\w.-]+\.                                   # unquoted filename.ext
164 #       (?:vb[se]                               # list of extns
165 #       |ws[fh]
166 #       |jse?
167 #       |exe
168 #       |com
169 #       |shs
170 #       |bat
171 #       |scr
172 #       |pif)
173 #  )                                            # end of filename capture
174 #  [\s;]                                        # trailing ;/space/newline
175 #
176 #
177 ### [End]