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