Virus and file blocking HOWTO using smtpfront-qmail for sme server

Release supported: sme 6.0, 6.0.1 (not compatible with 6.0beta or earlier sme versions). For sme 6.5 see specific install procedure section below.

For sme 7.0 see note below.

Author: Ray Mitchell -

Contributor: Gordon Rowell, Shad Lords

Updated: 1 April 2006 v5e

Note re sme 7.0 - This feature has been incorporated into sme server v7.0. See the Email panel in server manager. This HOWTO is not applicable to sme server 7.0.


Your sme server receives a lot of email with virus infected attachments and you want to reject it before it enters your server's mail system.

You want to block email with certain types of file attachments to improve security of your server or reduce bandwidth use caused by unwanted or undesired large multimedia files.

Current methods typically use Anti Virus detection software. These methods are processor & memory intensive and can annoy recipients with excessive virus detection notification messages.

There is presently no system for blocking multimedia or other file attachments



This contribution for sme server 6.0 or 6.0.1, adds a feature to mailfront/smtpfront-qmail, which allows incoming & outgoing messages to be rejected if the attached file has executable content, which matches specific file type patterns.

A default pattern matching database is created with common executable file patterns, which cover the majority of currently known Windows type executable viruses.

Patterns can be created for any file types to allow multimedia or other attachments to be rejected where the system management policy considers it appropriate.

Note that this contribution is NOT compatible with sme server 6.0beta, 5.6, or earlier releases.

For use on sme server 6.5 please see specific installation section below.

Email messages are rejected if the attachment content matches an entry in the patterns database. By default this includes the majority of *.exe files, older v1.0 *.zip files and some *.gif files.

This blocking applies to both incoming and outgoing smtp email messages, including the local network, in order to stop virus propagation.

If these file types need to be sent using email, they should be compressed using WinZip (v2.0 format) or WinRAR or other suitable compression software, or alternatively shared on the local network use filesharing. Note that recent releases of compression software use the v2.0 zip format.

Messages with attachments that match the patterns database are rejected by the mail system, and as a result there is no further processing. In practice a large number of virus infected messages will be rejected, perhaps 95 % or more, depending on the type of virus infections you receive and your system exposure (email addresses).

In conjunction with RBL list blocking of spam messages (see separate HOWTO) my server has experienced a reduction in virus detections by Clamavis-ng from hundreds per week to one message in three weeks. The use of RBL list spam blocking also helps reduce virus infected email messages entering the server, probably due to the fact that some virus infected messages come from similar sources as spam messages.

This method works for servers configured as either Server & Gateway or Server Only as long as the mail server components are enabled (smtpfront-qmail & qmail) and the server has access to the Internet via another sme server or firewall.


Additional Information:

WARNING: Installation of these rpms will make major changes to your server's mail system. Please follow all instructions carefully and ensure that an anti-relay test is carried out after implementation to ensure your server is not inadvertantly misconfigured as an open mail relay. This is only a precaution, but a necessary one.

Pattern matching acts as a "gross filter" to reject many known virus types, but a regularly updated virus scanner is still required to catch new viruses. Once these new viruses have been analysed, additional patterns can be created and added to the patterns database as required. It is envisaged that new patterns would be added infrequently.

See separate section below for information on analysing, determining & adding file patterns.

This pattern matching feature should be used in conjunction with virus scanning software and spam filtering software, although these programs will have a lot less work to do.

It has been tested on a sme 6.0 server with Clamavis-ng and Spamassassin installed and works very effectively. It also works OK with Jesper Knudsens Antivirus & Spam Filter panels installed.

Pattern blocking should be compatible with other brands of virus & spam software based programs. They generally scan or filter the message after it has been accepted by the servers mail system.

Pattern blocking occurs before the message is accepted, and if a matching occurs the message is rejected so it would never be scanned by secondary software based systems. Incompatibilities are therefore unlikely.

An additional feature I recommend to implement is "RBL List blocking" using smtpfront-qmail, to reject spam messages from senders that are included on RBL lists. This technique will dramatically reduce the amount of spam entering the server. See separate HOWTO for details.

The RBL feature has been incorporated into Jesper Knudsens Spam Filter panel.



This HOWTO is based on devinfo posts, emails, and rpms developed by Gordon Rowell, in conjunction with my own investigations & testing. Thanks also to Gordon Rowell & Charlie Brady for their assistance & suggestions and the work they did to integrate this feature into sme 6.0 and to Russell Nelson for the initial work done on qmail pattern matching and Bruce Guenter who added the feature to mailfront (& also wrote mailfront). Additional information re v6.5 from forum post by Shad Lords.


Install Procedure: (sme 6.5 server only)

Please note these rpms have been incorporated into the release of sme server v6.5. You DO NOT need to carry out the steps outlined in this HOWTO, simply enable Pattern matching using the following command.

/sbin/e-smith/config setprop smtpfront-qmail Patterns enabled

If you wish to enable pattern matching on the secure email interface do the following command.

/sbin/e-smith/config setprop ssmtpfront-qmail Patterns enabled

Then configure the file types to be blocked in the Server Manager Email panel and Save.


Install Procedure: (sme 6.0 or 6.0.1 server only)

You will first need to decide which patterns you wish block. By default the majority of Windows executable, zip (v1.0) & some gif files will be blocked. The default is generally suitable for most users. Note that zip (v2.0 format) will NOT be blocked by default, but can be enabled with a simple command.

Additional patterns can be added to the database after install is completed.

Also see separate section below for information on analysing, creating & adding patterns.

WARNING: Enable additional patterns with care. Verify that the patterns do not block attachment types that you wish to receive.


Checking your installed version of rpms

Check and note the versions of rpms you currently have installed. This information will be required if you wish to undo the installation later. A standard install of sme 6.0 or 6.0.1 may not have all these rpms installed.


rpm -q mailfront e-smith-email e-smith-mailfront

Output for sme 6.0 Output for sme 6.0.1

mailfront-0.81-1.i386.rpm mailfront-0.81-1.i386.rpm

e-smith-email-4.14.0-06.noarch.rpm e-smith-email-4.14.0-07.noarch.rpm

e-smith-mailfront-1.3.0-11.noarch.rpm e-smith-mailfront-1.3.0-11.noarch.rpm


To enable Pattern Matching do the following

Download to an empty folder the following rpms from ibiblio or other mirror sites. Please note that later versions may have been released, which will replace the files mentioned in this section. Dependencies require that perl-perl-ldap, perl-Net-Server, perl-libnet & sortspam rpms also be installed.














/etc/init.d/smtpfront-qmail stop

cp /etc/tcprules/tcp.smtp /tmp

rpm -Uvh *.rpm


/sbin/e-smith/db mailpatterns delete ZIPV1 (This command is only necessary if you previously tested an earlier version of the contrib as this pattern has changed).

/sbin/e-smith/db mailpatterns delete PATTERNTYPE (This command is only necessary if you previously tested or created other pattern types that are in the default database, where PATTERNTYPE is the pattern name you created).



/sbin/e-smith/expand-template /etc/tcprules/tcp.smtp

diff /etc/tcprules/tcp.smtp /tmp/tcp.smtp

WARNING: If there are any differences except blank lines, undo the installation by reverting to the previously installed versions of the rpms.


Here is an example of diff output showing "blank line" changes, this can be safely ignored:




During testing, a custom template created by the installation of the smeserver-spamassassin-1.0.0-01 rpm, conflicted with the revised tcprules/tcp.smtp template and caused some differences to be observed. As the function of the custom template was being duplicated, it was safe to remove the custom template and proceed with the installation. After again running the diff command above, no differences other than blank lines were seen.

If you have any problems review any custom templates in your system and remove them where necessary.

See section below for further info on the tcp.smtp file contents



To enable:

/sbin/e-smith/db configuration setprop smtpfront-qmail Patterns enabled

/sbin/e-smith/expand-template /etc/tcprules/tcp.smtp

diff /etc/tcprules/tcp.smtp /tmp/tcp.smtp

Note: Each line should now have a PATTERNS entry, but no other changes when compared to the previous diff output. See section below for further info on the tcp.smtp file contents.

/sbin/e-smith/signal-event email-update

/etc/init.d/smtpfront-qmail start

Furthermore to ensure that all .qmail files are updated after package changes do the following

/sbin/e-smith/signal-event post-upgrade

/sbin/e-smith/signal-event reboot



A menu box is added to the server manager Email panel, which allows executable content blocking to be enabled or disabled. It is enabled by default. Use "Ctrl click" to highlight or unhighlight the various groups of file types, and then click the Save button to enable/disable pattern matching.



Run anti-relay test to check system is OK:

There are two ways this can be done

At the server's command prompt do:


Note: This only works if the outgoing address is also your mailserver address, which is usually the case in standard installations. This may not be true in some more complex network setups.


Alternatively browse to

and enter your server details and perform the test



Before and after contents of the /etc/tcprules/tcp.smtp file

Depending on the configuration of your server the contents of this file may vary from the examples shown below.

The /etc/tcprules/tcp.smtp file without Clamavis-ng installed and before Pattern Matching has been installed looks like this

(Note local IP = 192.XXX.X.X)

(Note gateway IP =,RELAYCLIENT=""






The /etc/tcprules/tcp.smtp file with Clamavis-ng installed and before Pattern Matching has been installed looks like this

(Note local IP = 192.XXX.X.X)

(Note gateway IP =,RELAYCLIENT="",QMAILQUEUE="/usr/bin/qmail-queue.amavis"







My server's /etc/tcprules/tcp.smtp file with Clamavis-ng installed and after Pattern Matching has been installed & enabled looks like this

(Note local IP = 192.XXX.X.X)

(Note gateway IP =,RELAYCLIENT="",QMAILQUEUE="/usr/bin/qmail-queue.amavis",PATTERNS="/var/qmail/control/patterns.default"







Analyzing and creating patterns

Common file patterns (or signatures or magic)

The standard patterns enabled by default are:

Windows executables seen in active viruses

Additional Windows executable signatures not yet seen in viruses

ZIP file signature seen in SoBig.E and mydoom
UEsDBAoAA (this pattern is blocked - zip v1.0 format)
UEsDBBQAA (this pattern is NOT blocked by default - zip v2.0 format

GIF file found in a previous Microsoft virus

Extra patterns not included in default database that may be enabled if required for blocking of new viruses

A recent pattern identified for the virus




Identified as MS-DOS executable



Extra patterns not included in default database that may be enabled if required for blocking of multimedia files etc (long & short versions listed)

Note that these have not been tested and may need further refinement to ensure they accurately represent the signature pattern for all occurrences of the particular file type

***** Feedback is welcomed on the correctness of these patterns *****

SCR screen saver files - MS-DOS executable (EXE)




PIF1 - data



Pattern: AHhUYXgg


PIF2 - data



PIF3 - data



Pattern: AHhIYW5k


WAV sound file - data


Pattern: Uk1GRiRwL


JPEG image data, JFIF standard 0.00, aspect ratio, 0 x 0


TIF - TIFF image data, little-endian


Pattern: SUkqAAgAAAA


PPT powerpoint presentation -Microsoft Office Document


Pattern: 0M8R4KGxGuEA

WMV Windows Media Player video file - Microsoft ASF


Pattern: MCaydY5mzxGm

MPG mpeg1 video file - MPEG system stream data



M2P mpeg2 video file - MPEG system stream data



AVI video file - RIFF (little-endian) data





Determining file patterns (or signature or magic)

To find out what the pattern or signature or magic for a file is, we need to run it through a base64 encoding routine and look for the appropriate strings in the first line of the output. That is, for "sane" files which have "magic" numbers at the start. We also can decode the file to find out what type of file it is. Published file specifications (where available) could also be referred to.

Copy a file to a folder on your sme server, say

At the command prompt do

perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' < | head -1

we get an output of


We need to pick a suitable substring to use as the pattern for this file type, for example:


We want the pattern string to be long enough to avoid "false positives" and short enough to catch all of that file type. Running the above command across a few files of a particular type will usually clearly show the appropriate substring.


To find out the file type details do

echo '
UEsDBAoAA' | perl -MMIME::Base64 -0777 -ne 'print decode_base64($_)' >/tmp/17.exe

then run "file" on the result

file /tmp/17.exe

the output is

/tmp/17.exe: Zip archive data, at least v1.0 to extract

which identifies the type of file



An alternative way of identifying the file pattern or signature for users of Clamavis-ng is to view the quarantined messages in /var/spool/amavis-ng/quarantine

Here is an extract from a quarantined infected message that mimics a zip file

File: 406a8bee~aad.msg Col 0 30787 bytes
Content-Type: application/octet-stream; name=""
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=""


So to create a new pattern for this message we would use
which is the pattern corresponding to ZIPV1 file type

UEsDBAoAA: Zip archive data, at least v1.0 to extract

Enabling or disabling patterns

Let's say we want to add a pattern to the existing EXEFILES type (which you should do if you discover new patterns for common new MSDOS Executable type viruses)

A pattern analysed from email messages received is


As we wish to add this to the existing db entry we would do:

/sbin/e-smith/db mailpatterns set EXEFILES pattern Body TVqQAAMAA,TVpQAAIAA,


TVouARsAA,TVrQAT8AA,TVoAAAEAAA,TVoAAD8AA Description "MS-DOS executables"

Glob yes LineStart yes Status enabled

(the above is all on one line, watch the spaces are correct)

/sbin/e-smith/signal-event email-update


To check the entry is correct do:

/sbin/e-smith/db mailpatterns show EXEFILES

which gives an output of



Description=MS-DOS executables





Let's say we want to enable the pattern for PIF2 type files (which you should do if you wish to block some PIF attachments)

A pattern being tested for this file type is


So we do:

/sbin/e-smith/db mailpatterns set PIF2 pattern Body AMlIbDk5Lm Description "PIF2 data" Glob yes LineStart yes Status enabled

(the above is all on one line)

/sbin/e-smith/signal-event email-update

To check the entry is correct do:

/sbin/e-smith/db mailpatterns show PIF2

which gives an output of



Description=PIF2 data





The fields are as follows:

pattern the type of the entry in the database (currently only the "pattern" type is used)

Body the substring to match

Description free format text to describe this pattern. This text will be used to display a menu

of patterns to enable/disable in a later version

Glob whether to apply a wildcard match after the pattern

LineStart whether to only match this pattern at the start of the line

Status whether this pattern is currently enabled (i.e. blocked)


To disable the pattern do:

/sbin/e-smith/db mailpatterns setprop PIF2 Status disabled

/sbin/e-smith/signal-event email-update



The alternative but more correct approach is as follows:

The initialize-default-databases loads the db with fragments from /etc/e-smith/db. When new patterns are added to the master rpm, new fragments are also added.

To add a pattern to the default set in the rpm, we do:

mkdir -p /etc/e-smith/db/mailpatterns/defaults/PIF2/

and in that directory, create the following files/contents:

Description/PIF2 data

then do


which will load the default settings


To show all the patterns in the mailpatterns database & their status (enabled or disabled) do

/sbin/e-smith/db mailpatterns show

which will give an output similar to

(Note the last entry for ZIPV2 is disabled)

/sbin/e-smith/db mailpatterns show



Description=MS-DOS executables






Description=GIF file from old virus






Description=Zip archive data, at least v1.0 to extract






Description=Zip archive data, at least v2.0 to extract







Checking logs for effectiveness of blocking messages with executable content in the attachments

By reviewing /var/log/smtpfront-qmail/current and var/log/smtpfront-qmail/* you can see the entries for rejected messages and generally enough information as to why the rejection occurred, and therefore see the effectiveness of Pattern Matching blocking.

Note that you will only see these types of entries after blocking has been enabled and messages have been rejected.

If you do not see all of the types of entries shown below, it would either be due to not having the particular Pattern enabled or not receiving attachments with that type of content.

You can view date formatted logs using the Server Manager View log files panel


To see ALL the log entries do

grep "" /var/log/smtpfront-qmail/current | tai64nlocal


To see only the rejected message entries and the reason for rejection do

grep "We don't accept email with executable content" /var/log/smtpfront-qmail/current | tai64nlocal

(the above is all on one line)

Here is an example of some typical entries

Note: you will only see these entries after some messages have been rejected

2004-04-15 12:32:11.892522500 smtpfront-qmail[23392]: 554 We don't accept email with executable content ZIPV1 (#5.3.4)

2004-04-15 15:23:40.765202500 smtpfront-qmail[28963]: 554 We don't accept email with executable content EXE01 (#5.3.4)

2004-04-15 15:33:08.132041500 smtpfront-qmail[29241]: 554 We don't accept email with executable content EXE12 (#5.3.4)

2004-04-15 15:33:09.021650500 smtpfront-qmail[29265]: 554 We don't accept email with executable content PIF (#5.3.4)


Alternatively you could filter on the pattern type code to see how many messages with a particular type of executable content are being rejected eg

grep EXE01 /var/log/smtpfront-qmail/current | tai64local

2004-04-15 15:23:40.765202500 smtpfront-qmail[28963]: 554 We don't accept email with executable content EXE01 (#5.3.4)

2004-04-15 15:33:08.132041500 smtpfront-qmail[29241]: 554 We don't accept email with executable content EXE01 (#5.3.4)

2004-04-15 15:33:09.021650500 smtpfront-qmail[29265]: 554 We don't accept email with executable content EXE01 (#5.3.4)

2004-04-15 15:33:24.986426500 smtpfront-qmail[29274]: 554 We don't accept email with executable content EXE01 (#5.3.4)


Web sites for background information

These links may be of interest. Note that they do not specifically apply to sme server, so DO NOT implement them. They are listed for background information only.