Postfix mail server block Malware with blacklist

Malware is used for a harmful purpose. It can be in your software or hardware. Email and free (don't confuse with OSS) or pirated software is the most famous way to spread malware. It is inserted in a system w/o user notification.

Wikipedia defines Malware as:

Malware is software designed to infiltrate or damage a computer system without the owner's informed consent. It is a portmanteau of the words "malicious" and "software". The expression is a general term used by computer professionals to mean a variety of forms of hostile, intrusive, or annoying software or program code.

It will be a nice idea to block malware spreading urls and website. Setting up a mlaware blacklist in Postix MTA is quite easy. The Malware Block List is a free, automated and user contributed system for checking URLs for the presence of Viruses, Trojans, Worms, or any other software considered Malware. The list is available in 25 formats.

Create a blacklist

First you need to create a blacklist, type the following command:
# wget -O - http://www.malware.com.br/cgi/submit?action=list_postfix > /etc/postfix/mbl-body-deny

Configure Postfix

Open postfix main.cf file:
# vi /etc/postfix/main.cf
Setup postfix body_check directive:
body_checks = regexp:/etc/postfix/mbl-body-deny

Restart Postfix

Now just restart postfix:
# postmap /etc/postfix/mbl-body-deny
# /etc/init.d/postfix restart

Automate procedure

You need to setup a cron job to automate entire procedure. Create a shell script as follows (Download link):

#!/bin/bash
# Script to update malware urls
/usr/bin/wget -O - http://www.malware.com.br/cgi/submit?action=list_postfix > /etc/postfix/mbl-body-deny
/usr/sbin/postmap /etc/postfix/mbl-body-deny
/etc/init.d/postfix reload

Add cronjob as follows:
40 23 * * * /etc/admin/scripts/fetch.postfixmalware.sh >/dev/null 2>&1

You may wan to combine this feature with mime attachments blocking and anti spam blacklist for the best result.

Further readings

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 8 comments… read them below or add one }

1 BOK 06.25.07 at 8:49 pm

I’m giving it a try, even though the current list shows to have some duplicates.
Oh and AFAIK “postfix reload” will do fine too (instead of restarting)!

2 vivek 06.25.07 at 9:11 pm

BOK,

Yes, reload is fine too, I’ve used reload in script. Just checked my log and there are 4 dupes. But it works like a charm on our anti spam email gateway :)

3 matthias 06.26.07 at 8:12 am

Nice – I’ll give it a try!

4 bitou 08.10.07 at 4:26 am

What will be the perl script to download this malware list please?

Regards

5 Jean Brooks 10.07.07 at 6:24 pm

How do you unsuscribe Malware? I don’t want it, it is messing up my computer totally!! I want to delete now!!

6 vivek 10.07.07 at 8:06 pm

Remove:
body_checks = regexp:/etc/postfix/mbl-body-deny

Restart postfix and you are done!

7 rogers 11.01.07 at 9:39 am

I want you to know that we are very pleased with the quality of Article you have provided. I sincerely appreciate your responsiveness and the way you conduct. I have recommended your to others because of our satisfaction. I look forward to doing with you further comment or suggestions. regards.electronic projects

8 Lorenzo Luengo 07.01.08 at 11:27 pm

Is it needed to ‘postmap’ the malware file? it complains about many duplicate entries, because i’m using it to block some domains (using ‘From:’ header). I think postmap is not helping in any way with this, because it’s a pcre table, that can’t be postmap’d

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , , ,

Previous post: Install and configure MySQL on Windows XP or Vista or 2003 server

Next post: Hans Reiser: Once a Linux Visionary, Now Accused of Murder