8dc8bb1885bc3a45163e38fe728cc3dadeb462c0
[exim-website.git] / system_filter.exim
1 # Exim filter
2 ## Version: 0.10
3 #       $Id$
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 [vb2_regexp]
57 if $header_content-type: matches "(?:file)?name=(\"[^\"]+\\\\.(?:vb[se]|ws[fh]|jse?|exe|com|cmd|shs|bat|scr|pif)\"|[\\\\w.-]+\\\\.(?:vb[se]|ws[fh]|jse?|exe|com|cmd|shs|bat|scr|pif))"
58 then
59   fail text "This message has been rejected because it has\n\
60              \ta potentially executable attachment $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
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|cmd|shs|bat|scr|pif)\"|[\\\\w.-]+\\\\.(?:vb[se]|ws[fh]|jse?|exe|com|cmd|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 or other malware.\n\
78              \tIf you meant to send this file then please\n\
79              \tpackage it up as a zip file and resend it."
80   seen finish
81 endif
82
83 #### Version history
84 #
85 # 0.01 5 May 2000
86 #       Initial release
87 # 0.02 8 May 2000
88 #       Widened list of content-types accepted, added WSF extension
89 # 0.03 8 May 2000
90 #       Embedded the install notes in for those that don't do manuals
91 # 0.04 9 May 2000
92 #       Check global content-type header.  Efficiency mods to REs
93 # 0.05 9 May 2000
94 #       More minor efficiency mods, doc changes
95 # 0.06 20 June 2000
96 #       Added extension handling - thx to Douglas Gray Stephens & Jeff Carnahan
97 # 0.07 19 July 2000
98 #       Latest MS Outhouse bug catching
99 # 0.08 19 July 2000
100 #       Changed trigger length to 80 chars, fixed some spelling
101 # 0.09 29 September 2000
102 #       More extensions... its getting so we should just allow 2 or 3 through
103 # 0.10 18 January 2001
104 #       Removed exclusion for error messages - this is a little nasty
105 #       since it has other side effects, hence we do still exclude
106 #       on unix like error messages
107 # 0.11 20 March, 2001
108 #       Added CMD extension, tidied docs slightly, added RCS tag
109 #
110 #### Install Notes
111 #
112 # Exim filters run the exim filter language - a very primitive
113 # scripting language - in place of a user .forward file, or on
114 # a per system basis (on all messages passing through).
115 # The filtering capability is documented in the main set of manuals
116 # a copy of which can be found on the exim web site
117 #       http://www.exim.org/
118 #
119 # To install, copy the filter file (with appropriate permissions)
120 # to /etc/exim/system_filter.exim and add to your exim config file
121 # [location is installation depedant - typicaly /etc/exim/config ]
122 # at the top the line:-
123 #       message_filter = /etc/exim/system_filter.exim
124 #       message_body_visible = 5000
125 #
126 # You may also want to set the message_filter_user & message_filter_group
127 # options, but they default to the standard exim user and so can
128 # be left untouched.  The other message_filter_* options are only
129 # needed if you modify this to do other functions such as deliveries.
130 # The main exim documentation is quite thorough and so I see no need
131 # to expand it here...
132 #
133 # Any message that matches the filter will then be bounced.
134 # If you wish you can change the error message by editing it
135 # in the section above - however be careful you don't break it.
136 #
137 # After install exim should be restarted - a kill -HUP to the
138 # daemon will do this.
139 #
140 #### LIMITATIONS
141 #
142 # This filter tries to parse MIME with a regexp... that doesn't
143 # work too well.  It will also only see the amount of the body
144 # specified in message_body_visible
145 #
146 #### BASIS
147 #
148 # The regexp that is used to pickup MIME/uuencoded parts is replicated
149 # below (in perl format).  You need to remember that exim converts
150 # newlines to spaces in the message_body variable.
151 #
152 #  (?:Content-                                  # start of content header
153 #  (?:Type: (?>\s*)                             # rest of c/t header
154 #    [\w-]+/[\w-]+                              # content-type (any)
155 #    |Disposition: (?>\s*)                      # content-disposition hdr
156 #    attachment)                                        # content-disposition
157 #  ;(?>\s*)                                     # ; space or newline
158 #  (?:file)?name=                               # filename=/name= 
159 #  |begin (?>\s+) [0-7]{3,4} (?>\s+))           # begin octal-mode
160 #  (\"[^\"]+\.                                  # quoted filename.
161 #       (?:vb[se]                               # list of extns
162 #       |ws[fh]
163 #       |jse?
164 #       |exe
165 #       |com
166 #       |cmd
167 #       |shs
168 #       |bat
169 #       |scr
170 #       |pif)
171 #       \"                                      # end quote
172 #  |[\w.-]+\.                                   # unquoted filename.ext
173 #       (?:vb[se]                               # list of extns
174 #       |ws[fh]
175 #       |jse?
176 #       |exe
177 #       |com
178 #       |cmd
179 #       |shs
180 #       |bat
181 #       |scr
182 #       |pif)
183 #  )                                            # end of filename capture
184 #  [\s;]                                        # trailing ;/space/newline
185 #
186 #
187 ### [End]