doc/news updates
[exim-website.git] / system_filter.exim
1 # Exim filter
2 ## Version: 0.17
3 #       $Id: sysfilter.tmpl,v 1.4 2001/09/19 10:19:42 nigel Exp $
4
5 ## Exim system filter to refuse potentially harmful payloads in
6 ## mail messages
7 ## (c) 2000-2001 Nigel Metheringham <nigel@exim.org>
8 ##
9 ##     This program is free software; you can redistribute it and/or modify
10 ##    it under the terms of the GNU General Public License as published by
11 ##    the Free Software Foundation; either version 2 of the License, or
12 ##    (at your option) any later version.
13 ##
14 ##    This program is distributed in the hope that it will be useful,
15 ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ##    GNU General Public License for more details.
18 ##
19 ##    You should have received a copy of the GNU General Public License
20 ##    along with this program; if not, write to the Free Software
21 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 ## -A copy of the GNU General Public License is distributed with exim itself
23
24 ## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
25 ## If you haven't worked with exim filters before, read
26 ## the install notes at the end of this file.
27 ## The install notes are not a replacement for the exim documentation
28 ## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
29
30
31 ## -----------------------------------------------------------------------
32 # Only run any of this stuff on the first pass through the
33 # filter - this is an optomisation for messages that get
34 # queued and have several delivery attempts
35 #
36 # we express this in reverse so we can just bail out
37 # on inappropriate messages
38 #
39 if not first_delivery
40 then
41   finish
42 endif
43
44 ## -----------------------------------------------------------------------
45 # Check for MS buffer overruns as per BUGTRAQ.
46 # http://www.securityfocus.com/frames/?content=/templates/article.html%3Fid%3D61
47 # This could happen in error messages, hence its placing
48 # here...
49 # We substract the first n characters of the date header
50 # and test if its the same as the date header... which
51 # is a lousy way of checking if the date is longer than
52 # n chars long
53 if ${length_80:$header_date:} is not $header_date:
54 then
55   fail text "This message has been rejected because it has\n\
56              an overlength date field which can be used\n\
57              to subvert Microsoft mail programs\n\
58              The following URL has further information\n\
59              http://www.securityfocus.com/frames/?content=/templates/article.html%3Fid%3D61"
60   seen finish
61 endif
62
63 ## -----------------------------------------------------------------------
64 # These messages are now being sent with a <> envelope sender, but
65 # blocking all error messages that pattern match prevents
66 # bounces getting back.... so we fudge it somewhat and check for known
67 # header signatures.  Other bounces are allowed through.
68 if $header_from: contains "@sexyfun.net"
69 then
70   fail text "This message has been rejected since it has\n\
71              the signature of a known virus in the header."
72   seen finish
73 endif
74 if error_message and $header_from: contains "Mailer-Daemon@"
75 then
76   # looks like a real error message - just ignore it
77   finish
78 endif
79
80 ## -----------------------------------------------------------------------
81 # Look for single part MIME messages with suspicious name extensions
82 # Check Content-Type header using quoted filename [content_type_quoted_fn_match]
83 if $header_content-type: matches "(?:file)?name=(\"[^\"]+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc])\")"
84 then
85   fail text "This message has been rejected because it has\n\
86              potentially executable content $1\n\
87              This form of attachment has been used by\n\
88              recent viruses or other malware.\n\
89              If you meant to send this file then please\n\
90              package it up as a zip file and resend it."
91   seen finish
92 endif
93 # same again using unquoted filename [content_type_unquoted_fn_match]
94 if $header_content-type: matches "(?:file)?name=(\\\\S+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc]))"
95 then
96   fail text "This message has been rejected because it has\n\
97              potentially executable content $1\n\
98              This form of attachment has been used by\n\
99              recent viruses or other malware.\n\
100              If you meant to send this file then please\n\
101              package it up as a zip file and resend it."
102   seen finish
103 endif
104
105
106 ## -----------------------------------------------------------------------
107 # Attempt to catch embedded VBS attachments
108 # in emails.   These were used as the basis for 
109 # the ILOVEYOU virus and its variants - many many varients
110 # Quoted filename - [body_quoted_fn_match]
111 if $message_body matches "(?:Content-(?:Type:(?>\\\\s*)[\\\\w-]+/[\\\\w-]+|Disposition:(?>\\\\s*)attachment);(?>\\\\s*)(?:file)?name=|begin(?>\\\\s+)[0-7]{3,4}(?>\\\\s+))(\"[^\"]+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc])\")[\\\\s;]"
112 then
113   fail text "This message has been rejected because it has\n\
114              a potentially executable attachment $1\n\
115              This form of attachment has been used by\n\
116              recent viruses or other malware.\n\
117              If you meant to send this file then please\n\
118              package it up as a zip file and resend it."
119   seen finish
120 endif
121 # same again using unquoted filename [body_unquoted_fn_match]
122 if $message_body matches "(?:Content-(?:Type:(?>\\\\s*)[\\\\w-]+/[\\\\w-]+|Disposition:(?>\\\\s*)attachment);(?>\\\\s*)(?:file)?name=|begin(?>\\\\s+)[0-7]{3,4}(?>\\\\s+))(\\\\S+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc]))[\\\\s;]"
123 then
124   fail text "This message has been rejected because it has\n\
125              a potentially executable attachment $1\n\
126              This form of attachment has been used by\n\
127              recent viruses or other malware.\n\
128              If you meant to send this file then please\n\
129              package it up as a zip file and resend it."
130   seen finish
131 endif
132 ## -----------------------------------------------------------------------
133
134
135 #### Version history
136 #
137 # 0.01 5 May 2000
138 #       Initial release
139 # 0.02 8 May 2000
140 #       Widened list of content-types accepted, added WSF extension
141 # 0.03 8 May 2000
142 #       Embedded the install notes in for those that don't do manuals
143 # 0.04 9 May 2000
144 #       Check global content-type header.  Efficiency mods to REs
145 # 0.05 9 May 2000
146 #       More minor efficiency mods, doc changes
147 # 0.06 20 June 2000
148 #       Added extension handling - thx to Douglas Gray Stephens & Jeff Carnahan
149 # 0.07 19 July 2000
150 #       Latest MS Outhouse bug catching
151 # 0.08 19 July 2000
152 #       Changed trigger length to 80 chars, fixed some spelling
153 # 0.09 29 September 2000
154 #       More extensions... its getting so we should just allow 2 or 3 through
155 # 0.10 18 January 2001
156 #       Removed exclusion for error messages - this is a little nasty
157 #       since it has other side effects, hence we do still exclude
158 #       on unix like error messages
159 # 0.11 20 March, 2001
160 #       Added CMD extension, tidied docs slightly, added RCS tag
161 #       ** Missed changing version number at top of file :-(
162 # 0.12 10 May, 2001
163 #       Added HTA extension
164 # 0.13 22 May, 2001
165 #       Reformatted regexps and code to build them so that they are
166 #       shorter than the limits on pre exim 3.20 filters.  This will
167 #       make them significantly less efficient, but I am getting so
168 #       many queries about this that requiring 3.2x appears unsupportable.
169 # 0.14 15 August,2001
170 #       Added .lnk extension - most requested item :-)
171 #       Reformatted everything so its now built from a set of short
172 #       library files, cutting down on manual duplication.
173 #       Changed \w in filename detection to . - dodges locale problems
174 #       Explicit application of GPL after queries on license status
175 # 0.15 17 August, 2001
176 #       Changed the . in filename detect to \S (stops it going mad)
177 # 0.16 19 September, 2001
178 #       Pile of new extensions including the eml in current use
179 # 0.17 19 September, 2001
180 #       Syntax fix
181 #
182 #### Install Notes
183 #
184 # Exim filters run the exim filter language - a very primitive
185 # scripting language - in place of a user .forward file, or on
186 # a per system basis (on all messages passing through).
187 # The filtering capability is documented in the main set of manuals
188 # a copy of which can be found on the exim web site
189 #       http://www.exim.org/
190 #
191 # To install, copy the filter file (with appropriate permissions)
192 # to /etc/exim/system_filter.exim and add to your exim config file
193 # [location is installation depedant - typicaly /etc/exim/config ]
194 # in the first section the line:-
195 #       message_filter = /etc/exim/system_filter.exim
196 #       message_body_visible = 5000
197 #
198 # You may also want to set the message_filter_user & message_filter_group
199 # options, but they default to the standard exim user and so can
200 # be left untouched.  The other message_filter_* options are only
201 # needed if you modify this to do other functions such as deliveries.
202 # The main exim documentation is quite thorough and so I see no need
203 # to expand it here...
204 #
205 # Any message that matches the filter will then be bounced.
206 # If you wish you can change the error message by editing it
207 # in the section above - however be careful you don't break it.
208 #
209 # After install exim should be restarted - a kill -HUP to the
210 # daemon will do this.
211 #
212 #### LIMITATIONS
213 #
214 # This filter tries to parse MIME with a regexp... that doesn't
215 # work too well.  It will also only see the amount of the body
216 # specified in message_body_visible
217 #
218 #### BASIS
219 #
220 # The regexp that is used to pickup MIME/uuencoded body parts with
221 # quoted filenames is replicated below (in perl format).  
222 # You need to remember that exim converts newlines to spaces in
223 # the message_body variable.
224 #
225 #         (?:Content-                                   # start of content header
226 #         (?:Type: (?>\s*)                              # rest of c/t header
227 #           [\w-]+/[\w-]+                               # content-type (any)
228 #           |Disposition: (?>\s*)                       # content-disposition hdr
229 #           attachment)                                 # content-disposition
230 #         ;(?>\s*)                                      # ; space or newline
231 #         (?:file)?name=                                # filename=/name= 
232 #         |begin (?>\s+) [0-7]{3,4} (?>\s+))            # begin octal-mode
233 #         (\"[^\"]+\.                                   # quoted filename.
234 #               (?:ad[ep]                               # list of extns
235 #               |ba[st]
236 #               |chm
237 #               |cmd
238 #               |com
239 #               |cpl
240 #               |crt
241 #               |eml
242 #               |exe
243 #               |hlp
244 #               |hta
245 #               |in[fs]
246 #               |isp
247 #               |jse?
248 #               |lnk
249 #               |md[be]
250 #               |ms[cipt]
251 #               |pcd
252 #               |pif
253 #               |reg
254 #               |scr
255 #               |sct
256 #               |shs
257 #               |url
258 #               |vb[se]
259 #               |ws[fhc])
260 #         \"                                            # end quote
261 #         )                                             # end of filename capture
262 #         [\s;]                                         # trailing ;/space/newline
263
264 #
265 #
266 ### [End]