<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Random thoughts of an overloaded mind &#187; scanner</title>
	<atom:link href="http://blog.amarkulo.com/tag/scanner/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.amarkulo.com</link>
	<description>Yet another technical blog about iOS, Windows, Linux, Arduino and everything else</description>
	<lastBuildDate>Tue, 13 Dec 2011 16:56:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to build antispam SMTP gateway for Exchange on Ubuntu 8.04</title>
		<link>http://blog.amarkulo.com/how-to-build-spam-free-smtp-gateway-for-exchange-on-ubuntu-804</link>
		<comments>http://blog.amarkulo.com/how-to-build-spam-free-smtp-gateway-for-exchange-on-ubuntu-804#comments</comments>
		<pubDate>Sat, 13 Sep 2008 16:10:51 +0000</pubDate>
		<dc:creator>amar</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[8.04]]></category>
		<category><![CDATA[antivirus]]></category>
		<category><![CDATA[apt]]></category>
		<category><![CDATA[aptitude]]></category>
		<category><![CDATA[clam]]></category>
		<category><![CDATA[clamav]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[exchange]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[mailscanner]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[relay]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[spamassassin]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[virus]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://dzo.blogsite.org/?p=141</guid>
		<description><![CDATA[Because previous solution that I have done on Windows didn&#8217;t worked in way I wanted, I have decided to make dedicated Linux SMTP filtering gateway. Note: You can copy/paste all commands written here although they are not inline, they will &#8230; <a href="http://blog.amarkulo.com/how-to-build-spam-free-smtp-gateway-for-exchange-on-ubuntu-804">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Because previous solution that I have done on Windows didn&#8217;t worked in way I wanted, I have decided to make dedicated Linux SMTP filtering gateway.</p>
<p><strong>Note:</strong> You can copy/paste all commands written here although they are not inline, they will be when you paste them to shell or file.</p>
<p>For this I needed to have:</p>
<ul>
<li>Fully functional Linux machine ( I had already installed Ubuntu 8.04 server )</li>
<li>Postfix &#8211; default installation will do</li>
<li>Mail Scanner &#8211; free package that you can get on <a title="Mail scanner" href="http://mailscanner.info/" target="_blank">MailScanner home page</a></li>
<li>SpamAssassin &#8211; free antispam solution</li>
<li>Clam AV &#8211; free antivirus</li>
</ul>
<p>Before of installing anything we will fetch the latest list of packages from Ubuntu repositories with command:</p>
<blockquote><p><strong>aptitude update</strong></p></blockquote>
<p>Now before installation of a Mail Scanner we need to install some packages with command:<strong> </strong><strong></strong></p>
<blockquote><p><strong>aptitude </strong><strong>install libconvert-tnef-perl libdbd-sqlite3-perl libfilesys-df-perl libmailtools-perl libmime-tools-perl libmime-perl libnet-cidr-perl libsys-syslog-perl libio-stringy-perl libfile-temp-perl</strong> <strong>libole-storage-lite-perl libarchive-zip-perl postfix clamav clamav-daemon libsys-hostname-long-perl libnet-cidr-lite-perl spamassassin<br />
</strong></p></blockquote>
<p>Answer with Y when asked to install dependencies for these packages. During the installation of postfix you will get simple menu in which you need to select Internet site and write your full host name with domain.</p>
<p>Because whole configuration of Postfix is being done via main.cf and master.cf files we need to change some values in them. Open <strong>main.cf</strong> and add/edit following lines to look like this:</p>
<blockquote><p><strong> myhostname = ubuntu.sp.local<br />
mydomain = sp.local<br />
myorigin = $mydomain<br />
inet_interfaces = all<br />
mydestination = $myhostname, localhost.$mydomain $mydomain<br />
mynetwork_style = host<br />
relay_domains = lab.net<br />
transport_maps = hash:/etc/postfix/transport<br />
append_at_myorigin = no<br />
local_recipient_maps =<br />
header_checks = regexp:/etc/postfix/header_checks<br />
</strong></p></blockquote>
<p>Now open <strong>/etc/postfix/transport </strong>and add your forwarding domains in it. For multiple domains go to new row by same principle.</p>
<blockquote><p><strong>sp.local smtp:[192.168.1.5]</strong></p></blockquote>
<p>This ip <strong>192.168.1.5</strong> is IP of my Exchange server, not of my Linux machine and <strong>sp.local</strong> is the name of my domain, replace IP and domain name with yours. After this editing we need to create hash of the transport file and to restart Postfix.</p>
<blockquote><p><strong>postmap /etc/postfix/transport<br />
/etc/init.d/postfix restart</strong></p></blockquote>
<p>Now you can control if Postfix is working like it should and if it transports mail. If everything works stop it so that we can configure other options in it and because it needs to be started after MailScanner.</p>
<blockquote><p><strong>/etc/init.d/postfix stop<br />
</strong></p></blockquote>
<p>Next step would be to unpack and install the latest version of Mail Scanner because Ubuntu 8.04 still doesn&#8217;t have the latest version in the repositories. You can get the latest version of Mail Scanner <a title="Mail scanner" href="http://mailscanner.info/downloads.html" target="_blank">here</a>. Because we will compile it we need .tar.gz version.</p>
<blockquote><p><strong>wget <a class="linkification-ext" title="Linkification: http://mailscanner.info/files/4/tar/MailScanner-install-4.71.10-1.tar.gz" href="http://mailscanner.info/files/4/tar/MailScanner-install-4.71.10-1.tar.gz">http://mailscanner.info/files/4/tar/MailScanner-install-4.71.10-1.tar.gz</a><br />
tar zxvf MailScanner-install-4.71.10-1.tar.gz<br />
cd MailScanner-install-4.71.10<br />
./install.sh</strong></p></blockquote>
<p>You will see lot of output when you run <strong>./install.sh</strong> because it will check which Perl modules do you have installed and install those that are missing, but as installation says:</p>
<blockquote><p><em>Do not worry too much about errors from the next command.<br />
It is quite likely that some of the Perl modules are<br />
already installed on your system.</em></p></blockquote>
<p>When <strong>install.sh </strong>is done you will get message to enter some lines in crontab to automatize jobs. Type <strong>crontab -e</strong> and enter following lines in crontab (:w to write and exit if you are using Vi editor ctrl+x for Pico).</p>
<blockquote><p><strong>37 5 * * * /opt/MailScanner/bin/update_phishing_sites<br />
07 * * * * /opt/MailScanner/bin/update_bad_phishing_sites<br />
58 23 * * * /opt/MailScanner/bin/clean.quarantine<br />
42 * * * * /opt/MailScanner/bin/update_virus_scanners<br />
3,23,43 * * * * /opt/MailScanner/bin/check_mailscanner</strong></p></blockquote>
<p>Now we need to edit <strong>/etc/default/spamassassin</strong> file and to enable SpamAssassin daemon. Open this file with editor and change these lines:</p>
<blockquote><p><strong>ENABLED=0 to ENABLED=1<br />
CRON=0 to CRON=1</strong></p></blockquote>
<p>Now we have enabled SpamAssassin as a daemon and enabled it to update daily via cron. It&#8217;s time to start it for the first time.</p>
<blockquote><p><strong>/etc/init.d/spamassassin start</strong></p></blockquote>
<p>Next step would be to edit MailScanner.conf. Find following lines and edit them to look like this:</p>
<blockquote><p><strong>Run As User = postfix<br />
Run As Group = postfix<br />
MTA = postfix<br />
Incoming Queue Dir = /var/spool/postfix/hold<br />
Outgoing Queue Dir = /var/spool/postfix/incoming<br />
Virus Scanners = clamav<br />
Spam List = SBL+XBL<br />
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin<br />
</strong></p></blockquote>
<p>Now we will run MailScanner with command:</p>
<blockquote><p><strong>/opt/MailScanner/bin/check_mailscanner</strong></p></blockquote>
<p>It will automatically go to background. Now we need to tell Postfix to wait with forwarding of mails while they are checked against spam and antivirus definitions. We will need to edit file <strong>/etc/postfix/header_checks</strong> and to add following line because without it nothing will work.</p>
<blockquote><p><strong>/^Received:/ HOLD</strong></p></blockquote>
<p>Now we need to restart Postfix with command:</p>
<blockquote><p><strong>/etc/init.d/postfix start</strong></p></blockquote>
<p>I have got interesting output when I once killed MailScanner process that really make me laugh.</p>
<blockquote><p><strong>11818 ? Ss 0:00 MailScanner: killing children, bwahaha!<br />
</strong>11819 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
11862 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
11905 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
11948 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
11991 ? Z 0:01 [MailScanner] &lt;defunct&gt;<strong><br />
12038 ? Ss 0:00 MailScanner: killing children, bwahaha!<br />
</strong>12039 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
12083 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
12126 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
12169 ? Z 0:01 [MailScanner] &lt;defunct&gt;<br />
12212 ? Z 0:01 [MailScanner] &lt;defunct&gt;</p></blockquote>
<p>LOL, they have a good sense of humor.</p>
<p>So if everything is working correctly you should receive now mails with small footer text:</p>
<blockquote><p><span style="color: #888888;">&#8211;<br />
This message has been scanned for viruses and<br />
dangerous content by <a href="http://www.mailscanner.info/" target="_blank"><strong>MailScanner</strong></a>, and is<br />
believed to be clean. </span></p></blockquote>
<p>You can control message delivery with command:</p>
<blockquote><p><strong>tail -f /var/log/syslog</strong></p></blockquote>
<p>There you will see scrolling text like:</p>
<blockquote><p>Sep 11 10:14:14 ubuntu postfix/smtpd[13220]: connect from web54408.mail.yahoo.com[206.190.49.138]<br />
Sep 11 10:14:14 ubuntu postfix/smtpd[13220]: CE433E643: client=web54408.mail.yahoo.com[206.190.49.138]<br />
Sep 11 10:14:15 ubuntu postfix/cleanup[13222]: CE433E643: hold: header Received: from web54408.mail.yahoo.com (web54408.mail.yahoo.com [206.190.49.138])??by ubuntu.sp.local (Postfix) with SMTP id CE433E643??for &lt;<strong>mymail@mydomain</strong>&gt;; Thu, 11 Sep 2008 10:14:14 -0400 (EDT) from web54408.mail.yahoo.com[206.190.49.138]; from=&lt;<strong>my_yahoo_mail</strong>@yahoo.com&gt; to=&lt;<strong><a class="linkification-ext" title="Linkification: mailto:mymail@mydomain.com" href="mailto:mymail@mydomain.com">mymail@mydomain.com</a></strong>&gt; proto=SMTP helo=&lt;web54408.mail.yahoo.com&gt;<br />
Sep 11 10:14:15 ubuntu postfix/cleanup[13222]: CE433E643: message-id=&lt;<a class="linkification-ext" title="Linkification: mailto:225121.37413.qm@web54408.mail.yahoo.com" href="mailto:225121.37413.qm@web54408.mail.yahoo.com">225121.37413.qm@web54408.mail.yahoo.com</a>&gt;<br />
Sep 11 10:14:15 ubuntu postfix/smtpd[13220]: disconnect from web54408.mail.yahoo.com[206.190.49.138]<br />
Sep 11 10:14:15 ubuntu MailScanner[13211]: New Batch: Scanning 1 messages, 2392 bytes<br />
Sep 11 10:14:16 ubuntu MailScanner[13211]: Virus and Content Scanning: Starting<br />
Sep 11 10:14:20 ubuntu MailScanner[13211]: Requeue: CE433E643.352A5 to 424A5E650<br />
Sep 11 10:14:20 ubuntu postfix/qmgr[13003]: 424A5E650: from=&lt;<strong>my_yahoo_mail</strong>@yahoo.com&gt;, size=1712, nrcpt=1 (queue active)<br />
Sep 11 10:14:20 ubuntu postfix/smtp[13245]: 424A5E650: to=&lt;<strong><a class="linkification-ext" title="Linkification: mailto:mymail@mydomain.com" href="mailto:mymail@mydomain.com">mymail@mydomain.com</a></strong>&gt;, relay=192.168.1.5[192.168.1.5]:25, delay=5.6, delays=5.5/0.01/0/0.15, dsn=2.6.0, status=sent (250 2.6.0 &lt;<a class="linkification-ext" title="Linkification: mailto:225121.37413.qm@web54408.mail.yahoo.com" href="mailto:225121.37413.qm@web54408.mail.yahoo.com">225121.37413.qm@web54408.mail.yahoo.com</a>&gt; Queued mail for delivery)<br />
Sep 11 10:14:20 ubuntu postfix/qmgr[13003]: 424A5E650: removed<br />
Sep 11 10:14:20 ubuntu <strong>MailScanner[13211]:</strong> <strong>Uninfected: Delivered 1 messages</strong></p></blockquote>
<p>This means that MailScanner is scanning messages against spam and viruses.</p>
<p>Now the latest step would be to create RC script to start MailScanner on boot and before Postfix. <a title="Mailscanner bash script" href="http://blog.amarkulo.com/wp-content/uploads/2008/09/mailscanner.txt" target="_blank">Here</a> you can read/download file <a title="Mailscanner bash script" href="http://blog.amarkulo.com/wp-content/uploads/2008/09/mailscanner.txt" target="_blank"><strong>mailscanner.txt</strong></a> file which you will use to create new <strong>/etc/init.d/mailscanner</strong> file.</p>
<p>This script is slightly modified original init script for MailScanner from Ubuntu. Next step would be to change permissions to the file and to create symlinks with commands:</p>
<blockquote><p><strong>chmod 755 /etc/init.d/mailscanner<br />
cd /etc/rc0.d/<br />
ln -s ../init.d/mailscanner K20mailscanner</strong></p>
<p><strong>cd /etc/rc1.d/<br />
ln -s ../init.d/mailscanner K20mailscanner</strong></p>
<p><strong>cd /etc/rc2.d/<br />
ln -s ../init.d/mailscanner S20mailscanner</strong></p>
<p><strong>cd /etc/rc3.d/<br />
ln -s ../init.d/mailscanner S20mailscanner</strong></p>
<p><strong>cd /etc/rc4.d/<br />
ln -s ../init.d/mailscanner S20mailscanner</strong></p>
<p><strong>cd /etc/rc5.d/<br />
ln -s ../init.d/mailscanner S20mailscanner</strong></p>
<p><strong>cd /etc/rc6.d/<br />
ln -s ../init.d/mailscanner K20mailscanner<br />
</strong></p></blockquote>
<p>So now we need to test everything with commands:</p>
<blockquote><p><strong>/etc/init.d/postfix stop<br />
/etc/init.d/mailscanner start<br />
/etc/init.d/postfix start</strong></p></blockquote>
<p><strong>Notes</strong>:</p>
<p>If SpamAssassin doesn&#8217;t detect some of your messages as spam although they are spam you can easy manually learn it to detect that and other similar messages as spam. Follow next few steps:</p>
<ol>
<li>Find that message and save it to text file including headers and content</li>
<li>Transfer file to your linux machine</li>
<li>From the directory where you have transfered file run command: <strong>spamassassin &#8211;spam &lt; your_text_file</strong></li>
</ol>
<hr>
<p><div class="entry-utility">If you don't already have a <a href="http://db.tt/aqrG0tY">Dropbox</a> account then you can create it by clicking on my <a href="http://db.tt/aqrG0tY">affiliate link</a>. You will receive 2GB free account + 250 MB extra and I will receive 250 MB as well. Win-Win :-)</div></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.amarkulo.com/how-to-build-spam-free-smtp-gateway-for-exchange-on-ubuntu-804/feed</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>

