-
Notifications
You must be signed in to change notification settings - Fork 5
/
README
449 lines (339 loc) · 18.5 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
Additional information and a guide can be found at
http://qmailwiki.inter7.com/index.php?title=Simscan
= Overview =
SimScan is a simplified scanner for qmail similar to qmail-scanner and qscand.
It uses clamav, trophie, and/or spamassassin. It also supports attachment
blocking by extension. Simscan is written entirely in C to ensure maximum
speed. There are several options to allow simscan to scan per domain, and
reject spam mail.
= Requirements =
# ripmime (If you plan on using attachment blocking)<br>
# qmail with qmail-queue patch<br>
# clamav (optional)<br>
# spamassassin (optional)<br>
# trophie (or sophie) (both optional)
= How it works =
* Simscan creates a temporary working directory. You can specify the base
working directory with the --enable-workdir=/path. The default location
of this base is the /var/qmail/simscan directory. The temporary working
directory under this bass directory is named as
"unix time in seconds" . "microseconds" . "process id".
The email is read into a temporary file named "msg.unixtime.micro.pid.
* ripmime is called to break this file into separate mime parts.
* Optionally (--enable-attach) the mime message parts are checked against
the list of attachments to block.
Put the list of attachments in /var/qmail/control/ssattach or place the list
in the /var/qmail/control/simcontrol file for per-domain blocking.
This file gets read each time simscan is kicked off.
* clamdscan is called to check all the files in the working directory.
The return code of clamdscan is checked to see if it found a virus.
If it did, simscan exits back to qmail-smtpd with a permenent error,
causing the mail to be bounced back to the sender.
* Optionally (--enable-spam) spam assassin is called via spamc.
The email returned by spamc is checked X-Spam-Flag: header. If this header
contains "YES", the spam is rejected. You can reject instead on the calculated
hit count value by adding the --enable-spam-hits. SimScan checks for both
"hits=" and "score=" so that both old and new versions of spamassassin are
supported.
* Optionally (--enable-per-domain) enable per domain clamav and
spamassassin processing. You will need to edit /var/qmail/control/simcontrol
to define what domains get what scans. Further details on editing this file
are below.
Then run /var/qmail/bin/simscanmk to build the cdb files that simscan
uses. The changes will take effect immediately.
* Finally, if all of the above succeeds then the msg file is passed on to
qmail-queue. And the working directory and all the temporary files are deleted,
unless the SIMSCAN_DEBUG environment variable is set.
= Configuration Options =
Following is a list of all of the configure options and defaults:
--enable-user=<user> Change the user for simscan.
Default: simscan.
--enable-clamav=y|n Turn on clamav scanning. default yes.
--enable-clamdscan=PATH Full path to clamdscan program.
--enable-custom-smtp-reject=y|n Return smtp reject message with virus name.
--enable-per-domain=y|n Turn on per domain based checking.
--enable-attach=y|n Turn on attachment scanning. default no.
--enable-spam=y|n Turn on spam scanning. default no.
--enable-spam-passthru=y|n Pass spam email thru or reject
Default: disable (reject)
--enable-spamc-user=y|n Set user option to spamc.
--enable-spam-hits=number Reject spam above this hit level.
Default 10.0
--enable-spamc=PATH Full path to spamc program.
--enable-spamc-args=ARGS Arguments to pass to spamc.
--enable-dropmsg=y|n Drop message in case of virus/spam found.
Don't return error to sender.
Default: disable (return error)
--enable-quarantinedir=DIR Directory to keep spam and/or infected emails
Default: disabled
--enable-qmaildir=DIR Base qmail directory /var/qmail.
--enable-workdir=DIR Directory to unpack emails
Default: /var/qmail/simscan
--enable-qmail-queue=PATH Full path to qmail-queue program.
--enable-trophie-path=PATH Full path to the trophie binary.
--enable-trophie-socket=PATH Full path to the trophie socket.
--enable-ripmime=PATH Full path to ripmime program.
--enable-received=y|n Simscan should add a received line showing
the version of all scanners that checked
the message
These options are only needed when the received line option (--enabled-received=y)
and the corresponding scanners are enabled as well:
--enable-spamassassin-path=PATH Path to the spamassassin binary
--enable-clamavdb-path=PATH Directory where the clamav master.cvd and
daily.cvd files are saved
--enable-sigtool-path=PATH Path to the sigtool binary
= Configuration Details =
Below are more detailed descriptions of each configuration option.
--enable-user=<user>
This option defines the user that simscan will run as. By default, the
user is 'simscan'.
--enable-clamav=y|n
This option turns clamav scanning on or off. When enabled, an incoming
email will be rejected if a virus is detected in the email.
--enable-clamdscan=PATH
This option defines the path to the clamdscan binary. This is the full
path to the binary.
Note : This option does nothing when clamav is not enabled.
--enable-custom-smtp-reject=y|n
This option turns custom smtp reject messages on and off. When enabled
simscan will place the virus name in the reject message if a virus is
detected.
Note : The qmail-queue-custom-error.patch is needed to make this option
work properly. You can find this patch in the contrib directory.
Note 2 : Enabling dropmsg disables this option
--enable-per-domain=y|n
This option turns per-domain scanning on and off. Per domain scanning
allows the administrator to explicitly state what scanning occurs for
what domain. In addition, attachment scanning can be enabled or disabled
for each domain. Details about how to set up per-domain scanning are
below.
--enable-attach=y|n
This option turns on attachment scanning. Attachment scanning will block
all attachments specified in /var/qmail/control/ssattach. Attachment
scanning is disabled by default.
--enable-spam=y|n
Ths option turns spam scanning on and off. When enabled, simscan allows
mail over a certain spam threshold to be rejected back to the sender.
--enable-spam-passthru=y|n
This option turns spam passthru on and off. When enabled, email
identified as spam via the X-Spam-Status: header will be passed on to the
user instead of rejected.
Note : Enabling spam-hits effectively disables this option.
--enable-spamc-user=y|n
This option turns per-user spamassassin on or off. When enabled, the email
address of the first rcpt to user is sent to spamassassin. This allows
spamassassin to use customized rules and settings for that email.
--enable-spam-hits=number
This option specifies the number of hits a spam must receive to be rejected
by simscan. This option defaults to 10 hits.
Note : This option disables spam passthru
--enable-spamc=PATH
This option specifies the full path to the spamc binary.
--enable-spamc-args=ARGS
This option defines the arguments to pass to spamc. Be sure to place quotes
around the options you define.
--enable-dropmsg=y|n
This option causes messaged to be dropped when a virus/spam is found, rather
than returning a 5xx error to the sender. This option is disabled by default.
Note : This option overrides the Custom SMTP Reject option
Note 2 : If SPAM Passthru is enabled, SPAM will NOT be dropped unless
spam-hits is enabled
--enable-quarantinedir=DIR
This option defined a directory to keep spam and/or infected emails. This
option is disabled by default.
--enable-qmaildir=DIR
This option defines the location of qmail.
--enable-workdir=DIR
This option defines the location of the working directory. Note : The
default directory is /var/qmail/simscan
--enable-qmail-queue=PATH
This option defines the full path and name of the qmail-queue program.
Incoming mail is passed to this program after being scanned by SimScan.
--enable-trophie-path=PATH
This option defines the full path to the trophie binary. This option is only
necessary if the received line option (--enable-received) is chosen.
--enable-trophie-socket=PATH
This option defines the path to the trophie socket. Defining this option
enables trophie scanning.
--enable-ripmime=PATH
This option defines the path to the ripmime program. This program is used
to rip apart emails into files.
--enable-received=y|n
Simscan adds a Received line, showing the runtime, and a version string of
the scanners that checked the message:
Received: by simscan 1.0.6 ppid: 25399, pid: 25400, t: 4.7007s
scanners: attach: 1.0.6 clamav: 0.80/m:27/d:556 trophie: 7.000-1011/218/74141 spam: 2.63
--enable-spamassassin-path=PATH
This option defines the full path to the spamassassin binary. This option
is only necessary if the received line option (--enable-received) is chosen.
--enable-clamavdb-path=PATH
This option defines the full path to clamav master.cvd and daily.cvd files.
This option is only necessary if the received line option (--enable-received)
is chosen.
--enable-sigtool-path=PATH
This option defines the full path to the sigtool binary. This option is only
necessary if the received line option (--enable-received) is chosen.
= Attachment blocking option =
Attachments can be blocked. It is disabled by default.
If you use the per domain scanning as well, look in that section of the
documentation on how to enable the checking.
With only the attachment blocker and NO per domain option it works like
this:
Put the list of attachments in /var/qmail/control/ssattach.
List each attachment on it's own line. For example:
[user@mailserver user]$ cat /var/qmail/control/ssattach
.jpg
.mp3
.scr
.bat
Then configure with:
./configure --enable-attach (with any other options you want)
make
make install-strip
= SpamAssassin options =
-------------------------------------------------
There are four different ways to configure simscan with spamassassin
* no spam processing
This is the default. No spamassassin processing will be done.
* Reject email at smtp level if spamassassin considers it spam. This might reject false positives (good email that looks like spam)
--enable-spam
* Reject email above a "score" of some number, like 15 and pass everything else through to the user.
--enable-spam --enable-spam-hits=15
* Do not reject anything. Pass the spamassassin processed message through to the user
--enable-spam --enable-spam-passthru
In addtion you can enable per user preference processing for email with just one recipient. Add the following option
--enable-spamc-user
Look at the rc.spamd sample startup script for spamd options that work with vpopmail and per user preferences. Also look at the contrib directory for patches to spamassassin to make vpopmail/per user processing work.
= Trophie/Sophie option =
To enable the trophie virus scanner :
./configure --enable-trophie-socket=/path/to/the/socket \
--enable-trophie-path=/path/to/trophie/binary
As sophie uses the same interface it may work as well,
but is not tested!
= How SMTP rejection works =
There are currently three options for handling SMTP rejection. SMTP
rejection occurs when a virus is detected, or when the spam score is
over the spam-hits level.
The default rejection option is to reject with a standard 5XX reject
message. This rejection message looks as follows :
554 mail server permanently rejected message (#5.3.0)
If --enable-dropmsg is used, messages are dropped with no rejection
message. The connection is simply closed without warning.
If --enable-custom-smtp-reject is used, messages are rejected with
a custom message. You will need to apply the qmail-queue-custom-error.patch
patch located in the contrib directory in order to make this work.
For virus rejection, the message contains the name of the virus such as :
Your email was rejected because it contains the Worm.Bagle.AU virus
For spam rejection, the message is more generic, merely stating that
the message was rejected because it was considered spam :
Your email is considered spam (53.5 spam-hits)
For attachment rejection, the message contains the name of the
attachment :
Your email was rejected because it contains a bad attachment: trojan.exe
= Enable Per Domain processing =
To enable per domain processing :
./configure --enable-per-domain (with any other options you want)
make
make install-strip
Edit the /var/qmail/control/simcontrol text file
You can enable/disable clam/spam/trophie/attachments per domain
and per user and set a default for the whole machine.
Here is an example:
[user@mailserver user]$ cat /var/qmail/control/simcontrol
[email protected]:clam=yes,spam=no,attach=.txt:.com
example.com:clam=no,spam=yes,attach=.mp3
:clam=yes,spam=yes,trophie=yes,spam_hits=20.1
The third line sets the default for the whole machine to
enable clam,trophie, spam scanning, and sets the reject level for
spam hits to 20.1.
The second line sets clam off and spam on for the example.com domain and
disallows .mp3 files for the attachment scanner
The first line sets clam on and spam off for [email protected] and
.txt and .com files for the attachment names.
The order of precedence is:
email address (overrides all)
domain (overrides default)
default (only used if not overridden by domain or email address.
First the sender address will be looked up and then the recipients.
Without any matches, no scans will be done.
Then run /var/qmail/bin/simscanmk to build the simcontrol.cdb file.
You can rebuild this files at any time. The simscanmk program can safely
update the cdb files while the system is running.
If you are using the --enable-received option, you also need to run simscanmk with the -g option. This will create the simversions.cdb files that contain the current versions of spamassassin and clamav. Freshclam, the clamav update tool, can be configured to run simscanmk -g after each update. See the freshclam.conf file for more information.
Qmail extensions are handled like this: the address is broken into their
parts and are looked up. [email protected] looks up:
= Security =
The simscan program is restricted to running setuid simscan
to protect the rest of the system. It does all of it's work
in the /var/qmail/simscan directory (default location).
The simscan program runs setuid simscan. It does all of it's work
in the /var/qmail/simscan directory which is owned by simscan.
= Permissions and ClamAntiVirus =
To get ClamAV to play nicely with simscan's permissions you have two options:
* run clamd as root
* Add clamav to simscan's group. Then clamav will have access
to the working directory and it's files. On Linux like systems:
usermod -G simscan clamav
= How to chain additional scanning programs with simscan =
When simscan finishes it expects to call a program that reads
the file descriptors like qmail-queue does. You can configure
simscan to call a different program. By default the configure
script picks up the path to your qmail-queue program, which
is normally /var/qmail/bin/qmail-queue. Use this configure option:
--enable-qmail-queue=PATH
where PATH is full path to qmail-queue program.
I do not know why you would want to have another scanning process happen,
but you can sure configure it before compiling.
= How to Disable/Enable simscan for smtp connections by IP ranges =
Use the standard tcp.smtp text file to set or not set the QMAILQUEUE
environment variable per IP ranges. qmails smtp server is normally
run via tcpserver with the -x option to the constant database file
tcp.smtp.cdb.
Example:
Turn simscan off for our machines loopback address (127.*.*.*).<br>
Disable it for hypothetical local linux users on the 192.168.1.* lan.<br>
Enable it for hypothetical local windows users on the 192.168.2.* lan.<br>
Finally, we enable simscan(clamav/spamassassin) for all those untrusted
internet email senders.
Example tcp.smtp file contents:
[user@mailserver user]$ cat tcp.smtp
127.:allow,RELAYCLIENT=""
192.168.1.:allow,RELAYCLIENT=""
192.168.2.:allow,RELAYCLIENT="",QMAILQUEUE="/var/qmail/bin/simscan"
:allow,QMAILQUEUE="/var/qmail/bin/simscan"
This tcp.smtp file then needs to be compiled into the tcp.smtp.cdb file
using your systems method of generating it. If you only need the rules
in the tcp.smtp file you can compile it with this command:
[user@mailserver user]$ cd /to/directory/where/your/tcp.smtp.cdb file lives
[user@mailserver user]$ /usr/local/bin/tcprules tcp.smtp.cdb tempfile < tcp.smtp
Once compiled, the rules take effect immediately. Actually it
takes effect on every new smtp connection.
= Temporary File Management =
Simscan uses unique file names for the message, to/from headers and the
optional spamassassin output. The files are created in the unique simscan
work directory for this process. The files are unlinked along with the
temporary work directory just before we hand/execl all the information to
qmail-queue or on error exits.
data file name
____________ _______________
message fd 0 = msg.X.Y.Z where X = unix seconds
to/from fd 1 = addr.X.Y.Z Y = microseconds
spamassassin = spamc.msg.X.Y.Z Z = simscan process id
fd 0 and fd 1 normally come from the qmail smtp daemon.
Temporary files and directories are not deleted if the SIMSCAN_DEBUG
environment variable is set.
= Sample qmail startup script =
rc.qmail in the contrib directory is our sample qmail startup script. It shows you how you
can set the QMAILQUEUE environment variable to call simscan for
all incoming SMTP email.
Notice that we run our smtp server as root. We also run clamd as root. If you are having permission
problems you may want to consider running both as root.
= Sample spamassassin startup script =
rc.spamd in the contrib directory is a sample spamd startup script.
It sets enables the vpopmail and per user perferences option. It also
sets the spamd socket to /tmp/spamd.sock.
You must use the --enable-spamc-args="-U /tmp/spamd.sock" option to
simscan if you use this startup script.