Postfix provides Mime header check for all incoming messages. You can put restrictions on .exe / .bat / .vbs files and block all attachments.
mime_header_checks directive allows you to define file, you will place a restriction for any file extensions that you do not want to have passing through your mail sever system.
On most mail server the first thing that needs to be done is to enable header checks and block dangerous files.
Define mine header checks
Open main.cf file:
# vi /etc/postfix/main.cf
Append / set mime_header_checks directive as follows:
mime_header_checks = regexp:/etc/postfix/mime_header_checks
Save and close the file.
Block attachments
Now open /etc/postfix/mime_header_checks file:
# vi /etc/postfix/mime_header_checks
Append following line:
/name=[^>]*\.(bat|com|exe|dll|vbs)/ REJECT
Save and close the file.
Restart postfix
First create postfix lookup table for mime_header_checks file:
# /etc/init.d/postfix restart
Watch log file
You should see rejected mail log in /var/log/maillog file:
# tail -f /var/log/maillog
Output:
Jun 20 14:28:06 server postfix/smtpd[5442]: connect from web31601.mail.mud.yahoo.com[68.142.198.147] Jun 20 14:28:07 server postfix/smtpd[5442]: 245F913906EE: client=web31601.mail.mud.yahoo.com[68.142.198.147] Jun 20 14:28:07 server postfix/cleanup[5492]: 245F913906EE: message-id=<274995.40473.qm@web31601.mail.mud.yahoo.com> Jun 20 14:28:07 server postfix/cleanup[5492]: 245F913906EE: reject: header Content-Type: application/x-msdos-program; name="updatebankdetails.bat" from web31601.mail.mud.yahoo.com[68.142.198.147]; from=to= proto=SMTP helo= : Message content rejected
For more information please read postfix and header_checks man page.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins

- My 10 UNIX Command Line Mistakes
- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
Facebook it - Tweet it - Print it -
We're here to help you make the most of sysadmin work. So, subscribe!


{ 7 comments… read them below or add one }
Do not postmap regexp (or pcre) files ;)
If i wanted to allow send these extensions for few members. How to configure ?
After a LONG afternoon spent on removing Bagle from users’ PCs, no more exe attachments in mail ;)
If you use this rule, you may have problems with the emails, which has attachments containing a website adress in file name. For example: “yahoo.com statistics.xls”
I use
/name=[^>]*\.(bat|com|exe|dll|vbs)$/ REJECTto fix this issue :)with only $ at the end this rule will not work at all, because filename is placed between “”, so all line looks like follows:
/name=[^>]*\.(bat|com|exe|dll|vbs)\”$/ REJECT
Can I do this only for a user list or a group? This is a global setting which is applied to all users. If its possible, please send some guidelines.
Need to perform postmap /etc/postfix/mime_header_checks to create the db.