filter updates
[exim-website.git] / filter / system_filter.exim
1 # Exim filter
2 ## Version: 0.12
3 #       $Id: system_filter.exim,v 1.2 2001/05/10 11:35:45 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 #
136 #### Install Notes
137 #
138 # Exim filters run the exim filter language - a very primitive
139 # scripting language - in place of a user .forward file, or on
140 # a per system basis (on all messages passing through).
141 # The filtering capability is documented in the main set of manuals
142 # a copy of which can be found on the exim web site
143 #       http://www.exim.org/
144 #
145 # To install, copy the filter file (with appropriate permissions)
146 # to /etc/exim/system_filter.exim and add to your exim config file
147 # [location is installation depedant - typicaly /etc/exim/config ]
148 # at the top the line:-
149 #       message_filter = /etc/exim/system_filter.exim
150 #       message_body_visible = 5000
151 #
152 # You may also want to set the message_filter_user & message_filter_group
153 # options, but they default to the standard exim user and so can
154 # be left untouched.  The other message_filter_* options are only
155 # needed if you modify this to do other functions such as deliveries.
156 # The main exim documentation is quite thorough and so I see no need
157 # to expand it here...
158 #
159 # Any message that matches the filter will then be bounced.
160 # If you wish you can change the error message by editing it
161 # in the section above - however be careful you don't break it.
162 #
163 # After install exim should be restarted - a kill -HUP to the
164 # daemon will do this.
165 #
166 #### LIMITATIONS
167 #
168 # This filter tries to parse MIME with a regexp... that doesn't
169 # work too well.  It will also only see the amount of the body
170 # specified in message_body_visible
171 #
172 #### BASIS
173 #
174 # The regexp that is used to pickup MIME/uuencoded parts is replicated
175 # below (in perl format).  You need to remember that exim converts
176 # newlines to spaces in the message_body variable.
177 #
178 #  (?:Content-                                  # start of content header
179 #  (?:Type: (?>\s*)                             # rest of c/t header
180 #    [\w-]+/[\w-]+                              # content-type (any)
181 #    |Disposition: (?>\s*)                      # content-disposition hdr
182 #    attachment)                                        # content-disposition
183 #  ;(?>\s*)                                     # ; space or newline
184 #  (?:file)?name=                               # filename=/name= 
185 #  |begin (?>\s+) [0-7]{3,4} (?>\s+))           # begin octal-mode
186 #  (\"[^\"]+\.                                  # quoted filename.
187 #       (?:vb[se]                               # list of extns
188 #       |ws[fh]
189 #       |jse?
190 #       |exe
191 #       |com
192 #       |cmd
193 #       |shs
194 #       |hta
195 #       |bat
196 #       |scr
197 #       |pif)
198 #       \"                                      # end quote
199 #  |[\w.-]+\.                                   # unquoted filename.ext
200 #       (?:vb[se]                               # list of extns
201 #       |ws[fh]
202 #       |jse?
203 #       |exe
204 #       |com
205 #       |cmd
206 #       |shs
207 #       |hta
208 #       |bat
209 #       |scr
210 #       |pif)
211 #  )                                            # end of filename capture
212 #  [\s;]                                        # trailing ;/space/newline
213 #
214 #
215 ### [End]