<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mail on Such geek. Wow.</title><link>https://www.ericlight.com/tags/mail.html</link><description>Recent content in Mail on Such geek. Wow.</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Mon, 12 Apr 2021 00:00:00 +1200</lastBuildDate><atom:link href="https://www.ericlight.com/tags/mail/index.xml" rel="self" type="application/rss+xml"/><item><title>Blocking bad extensions and extortion with iRedMail</title><link>https://www.ericlight.com/post/iredmail.html</link><pubDate>Mon, 12 Apr 2021 00:00:00 +1200</pubDate><guid>https://www.ericlight.com/post/iredmail.html</guid><description>&lt;p&gt;Turns out this is my third Amavis article. I guess it&amp;rsquo;s just one of those systems.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Heads up, if you&amp;rsquo;re trying to do this, make sure you also read &lt;a class="link" href="https://www.ericlight.com/post/amavis2.html" &gt;my other article&lt;/a&gt; about the &amp;ldquo;banned_files_lover&amp;rdquo; thing.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Today I&amp;rsquo;m on a mission to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Drop all incoming Office &amp;lsquo;97 files (they&amp;rsquo;re predominantly malicious these days)&lt;/li&gt;
&lt;li&gt;Drop all incoming Macro-enabled Office 2007+ files (there aren&amp;rsquo;t legitimate reasons to receive these &lt;em&gt;in my scenario&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Drop any emails containing a .onion address&lt;/li&gt;
&lt;li&gt;Drop any emails containing a bitcoin wallet&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="dropping-attachments"&gt;Dropping Attachments
&lt;/h2&gt;&lt;p&gt;The attachment block is easily handled by Amavis. In iRedMail on Debian, the configuration file is found at &lt;code&gt;/etc/amavis/conf.d/50-user&lt;/code&gt;. Open your config file, and scroll down to the section where the &lt;code&gt;$banned_filename_re&lt;/code&gt; variable is set. Insert the following line:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; qr&amp;#39;.\.(doc|dot|docm|docb|xls|xlm|xlt|xlsm|xlsb|
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; xla|xlam|ppt|pps|pptm|potm|ppam|ppsm|sldm)$&amp;#39;i, # Office &amp;#39;97-2003 and Macro-enabled files
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; qr&amp;#39;.\.(adn|accdb|accdr|accdt|accda|mdw|accde|mam|maq|mar|mat|
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; maf|laccdb|ade|adp|mdb|cdb|mda|mdn|mdt|mdf|mde|ldb)$&amp;#39;i, # Microsoft Access files
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; qr&amp;#39;^\.pub$&amp;#39;, # Microsoft Publisher files
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That will block all core Office &amp;lsquo;97-2003 files, as well as all Macro-enabled Office 2007-365 files.&lt;/p&gt;
&lt;p&gt;By default, this will &lt;strong&gt;silently&lt;/strong&gt; reject mails containing these attachments. If you want senders to receive a bounce message, search for the &lt;code&gt;$final_banned_destiny&lt;/code&gt; variable and make sure it&amp;rsquo;s set to &lt;code&gt;D_BOUNCE&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="dropping-onion-and-btc"&gt;Dropping .onion and BTC
&lt;/h2&gt;&lt;p&gt;This part happens in Postfix, and it&amp;rsquo;s more-super-easy than the last bit. To configure Postfix&amp;rsquo;s body checks, edit &lt;code&gt;/etc/postfix/body_checks.pcre&lt;/code&gt;. I simply added the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/(\w+\.onion)/ REJECT This mail server does not accept references to .onion addresses (${1})
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/(\b(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39})/ DISCARD Bitcoin wallet detected (${1})
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I used the REJECT directive for testing, but to be honest I don&amp;rsquo;t want to send bounces back to these people, so I changed to DISCARD after it was working. You can see the difference above.&lt;/p&gt;
&lt;p&gt;The text after the REJECT directive is returned to the sender, and the text after the DISCARD directive is logged. The variable &lt;code&gt;${1}&lt;/code&gt; contains the detected string, and is appended to the response message.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s the end! Safety. Yes.&lt;/p&gt;
&lt;h1 id="acknowledgements"&gt;Acknowledgements
&lt;/h1&gt;&lt;p&gt;Thanks to Brad and Hamish for this post - Brad for the regex, Hamish for the idea, and both of them for the review!&lt;/p&gt;</description></item><item><title>iRedMail, SpamAssassin, and Lynis</title><link>https://www.ericlight.com/post/iredmail-lynis.html</link><pubDate>Mon, 02 Nov 2020 00:00:00 +1300</pubDate><guid>https://www.ericlight.com/post/iredmail-lynis.html</guid><description>&lt;p&gt;I really like iRedMail, and I also really like Lynis.&lt;/p&gt;
&lt;p&gt;However, they don&amp;rsquo;t exactly like &lt;em&gt;each other&lt;/em&gt;&amp;hellip; or, more accurately, some of Lynis&amp;rsquo; recommendations can cause a couple iRedMail components to fail. Today we&amp;rsquo;re talking about SpamAsassin.&lt;/p&gt;
&lt;p&gt;One of the suggestions from Lynis is to turn off the &amp;rsquo;execute&amp;rsquo; bit on compilers for users who aren&amp;rsquo;t either the owner or in the owner group (the &amp;lsquo;other&amp;rsquo; execute bit). For example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
root@server:/# chmod o-x /usr/bin/as
root@server:/# chmod o-x /usr/bin/gcc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Easy peasy! But once you do this, you might start getting the following in your daily iRedMail Cron reports:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::text
/etc/cron.daily/spamassassin:
/bin/sh: 1: x86_64-linux-gnu-gcc: Permission denied
make: *** [Makefile:346: body_0.o] Error 126
command 'make PREFIX=/tmp/.spamassassin23046Zmmrr9tmp/ignored INSTALLSITEARCH=/var/lib/spamassassin/compiled/5.028/3.004002 &amp;gt;&amp;gt;/tmp/.spamassassin23046Zmmrr9tmp/log' failed: exit 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are probably a bunch of ways to fix this. My way, I&amp;rsquo;m sure, is not the best way&amp;hellip; however it was quick and easy, and it worked.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
root@server:/# chgrp debian-spamd /usr/bin/as
root@server:/# chgrp debian-spamd /usr/bin/gcc
root@server:/# runuser -l debian-spamd -c sa-compile
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Look ma, no more errors!&lt;/p&gt;
&lt;p&gt;This solution really &lt;em&gt;only&lt;/em&gt; works for me because debian-spamd is the only non-root user that calls these compilers. If I had another user which needed to call them, I&amp;rsquo;d have to come up with a better fix. But for a standalone iRedMail server, this does the trick!&lt;/p&gt;</description></item><item><title>iRedMail: Daily user unknown entries from backup_sogo.sh</title><link>https://www.ericlight.com/post/sogo-unknown.html</link><pubDate>Sun, 01 Nov 2020 00:00:00 +1300</pubDate><guid>https://www.ericlight.com/post/sogo-unknown.html</guid><description>&lt;p&gt;If you&amp;rsquo;ve been running iRedMail for a while, eventually you&amp;rsquo;ll probably start seeing &amp;lsquo;user unknown&amp;rsquo; events in your daily logs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::text
* Backup all users' data under /var/vmail/backup/sogo/2020/11/01
&amp;lt;0x0x5574a64c36b0[SOGoCache]&amp;gt; Cache cleanup interval set every 300.000000 seconds
&amp;lt;0x0x5574a64c36b0[SOGoCache]&amp;gt; Using host(s) '127.0.0.1' as server(s)
2020-11-01 09:29:12.784 sogo-tool[29749:29749] user 'abdulm' unknown
2020-11-01 09:29:12.786 sogo-tool[29749:29749] user 'bent' unknown
2020-11-01 09:29:12.786 sogo-tool[29749:29749] user 'brettr' unknown
2020-11-01 09:29:12.786 sogo-tool[29749:29749] user 'catalinar' unknown
2020-11-01 09:29:12.787 sogo-tool[29749:29749] user 'clinth' unknown
2020-11-01 09:29:12.787 sogo-tool[29749:29749] user 'danield' unknown
2020-11-01 09:29:12.787 sogo-tool[29749:29749] user 'dannyn' unknown
2020-11-01 09:29:12.788 sogo-tool[29749:29749] user 'darcyk' unknown
2020-11-01 09:29:12.788 sogo-tool[29749:29749] user 'davidl' unknown
* Compress backup files.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is because removal of an iRedMail user doesn&amp;rsquo;t remove the corresponding SOGo user data. You can take care of this with &lt;code&gt;sogo-tool&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
root@server:/# sogo-tool remove abdulm@&amp;lt;domain.xyz&amp;gt; bent@&amp;lt;domain.xyz&amp;gt; brettr@&amp;lt;domain.xyz&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;hellip; etc. Once you&amp;rsquo;re done, run the backup again to make sure you&amp;rsquo;ve got them all:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
root@server:/# /bin/bash /var/vmail/backup/backup_sogo.sh
* Backup all users data under /var/vmail/backup/sogo/2020/11/01
&amp;lt;0x0x563fd0e2b6b0[SOGoCache]&amp;gt; Cache cleanup interval set every 300.000000 seconds
&amp;lt;0x0x563fd0e2b6b0[SOGoCache]&amp;gt; Using host(s) '127.0.0.1' as server(s)
* Compress backup files.
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Zentyal 6.0 to 6.1 upgrade getting stuck</title><link>https://www.ericlight.com/post/zentyal_dns.html</link><pubDate>Tue, 17 Dec 2019 00:00:00 +1300</pubDate><guid>https://www.ericlight.com/post/zentyal_dns.html</guid><description>&lt;p&gt;So I faced a little challenge with a &lt;a class="link" href="https://www.zentyal.com" target="_blank" rel="noopener"
 &gt;Zentyal&lt;/a&gt; server the other day. I was upgrading from ye olde 6.0 to 6.1, when everything just stopped. I let it sit in the corner for about an hour or so, but it never picked up the thread. All the services were still live, so I logged in to have a look.&lt;/p&gt;
&lt;p&gt;(Note, my DNS server is named RIMU; yours may be something else!)&lt;/p&gt;
&lt;p&gt;Running &lt;code&gt;ps aux&lt;/code&gt;, I discovered this line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
sh -c /usr/bin/sudo -p sudo: /var/lib/zentyal/tmp/x2M7gkZVvm.cmd 2&amp;gt; /var/lib/zentyal/tmp/stderr
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, I had a quick look at the contents of that stderr file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
# cat /var/lib/zentyal/tmp/stderr 
Password has expired
dns-RIMU@ad.ericlight.com's Password: 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And what does that temp .cmd file contain?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
# cat /var/lib/zentyal/tmp/x2M7gkZVvm.cmd 
kinit -k -t /var/lib/samba/private/dns.keytab dns-RIMU
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Running that kinit command indeed prompts for a password reset, but the interesting thing is that samba-tool shows me this password shouldn&amp;rsquo;t expire:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
# pdbedit -u dns-RIMU -v | grep change
Password can change: Wed, 31 Oct 2018 21:47:30 NZDT
Password must change: never
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;hellip; &lt;em&gt;riiiiiiight&lt;/em&gt;, that&amp;rsquo;s a bit interesting. And yet I&amp;rsquo;m still being prompted to set a new password. I used samba-tool to remind samba that this password shouldn&amp;rsquo;t expire:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
# samba-tool user setexpiry dns-RIMU --noexpiry
Expiry for user 'dns-RIMU' disabled.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now&amp;hellip;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::bash
# pdbedit -u dns-RIMU -v | grep -i change
Password can change: Wed, 31 Oct 2018 21:47:30 NZDT
Password must change: Tue, 19 Jan 2038 16:14:07 NZDT
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now I can run kinit against dns-RIMU perfectly fine, and indeed the Zentyal upgrade succeeded!&lt;/p&gt;</description></item><item><title>Respecting Amavis' "Banned Extensions" setting</title><link>https://www.ericlight.com/post/amavis2.html</link><pubDate>Sun, 13 Aug 2017 00:00:00 +1200</pubDate><guid>https://www.ericlight.com/post/amavis2.html</guid><description>&lt;p&gt;I&amp;rsquo;ve been dabbling a little bit with &lt;a class="link" href="http://www.iredmail.org" target="_blank" rel="noopener"
 &gt;iRedMail&lt;/a&gt;, mostly just to have a play with a mail server, but also to see what&amp;rsquo;s involved in mail security. iRedMail is a package that &lt;a class="link" href="http://www.iredmail.org/docs/used.components.html" target="_blank" rel="noopener"
 &gt;pulls together&lt;/a&gt; Postfix as an MTA, Dovecot as a POP3 &amp;amp; IMAP server, SOGo for ActiveSync, Roundcube for Webmail, SpamAssassin for spam protection, and ClamAV for virus scanning.&lt;/p&gt;
&lt;p&gt;Okay I have &lt;strong&gt;no idea&lt;/strong&gt; why I have to write this, but apparently it&amp;rsquo;s a thing.&lt;/p&gt;
&lt;p&gt;Amavis has a list of banned file extensions. In Debian, they live in &lt;code&gt;/etc/amavis/conf.d/20-debian_defaults&lt;/code&gt;, and &lt;code&gt;/etc/amavis/conf.d/50-user&lt;/code&gt;, and are set in the &lt;code&gt;$banned_filename_re&lt;/code&gt; variable. THIS MAKES PERFECT SENSE.&lt;/p&gt;
&lt;p&gt;But of course, there&amp;rsquo;s always something that doesn&amp;rsquo;t make sense, and that is the fact that there is a SQL backend (at least in the environment created by iRedMail), and settings in here take precedence over the Amavis config files somehow.&lt;/p&gt;
&lt;p&gt;And even more bizarrely, there exists in this SQL environment, a policy setting entitled &amp;ldquo;&lt;em&gt;&lt;strong&gt;banned_files_lover&lt;/strong&gt;&lt;/em&gt;&amp;rdquo;, which was set to &amp;ldquo;Y&amp;rdquo;. I shit you not. My only hope is that this only defaults to &amp;ldquo;Y&amp;rdquo; for postmaster.&lt;/p&gt;
&lt;p&gt;To fix this, you need to hop into the database, and update the appropriate column in the &lt;code&gt;policy&lt;/code&gt; table:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ mariadb
MariaDB [none]&amp;gt; \u amavis
MariaDB [amavisd]&amp;gt; update policy set banned_files_lover=&amp;quot;N&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now, Amavis will obey your file extension filters!&lt;/p&gt;
&lt;p&gt;Thankfully, I found this information at &lt;a class="link" href="http://www.iredmail.org/forum/topic13147-iredmail-support-amavisd-passed-but-setup-at-ddiscard.html" target="_blank" rel="noopener"
 &gt;http://www.iredmail.org/forum/topic13147-iredmail-support-amavisd-passed-but-setup-at-ddiscard.html&lt;/a&gt; &amp;ndash; I never would have found it otherwise!&lt;/p&gt;</description></item><item><title>Making Amavis work with ESET Antivirus</title><link>https://www.ericlight.com/post/amavis.html</link><pubDate>Sat, 12 Aug 2017 00:00:00 +1200</pubDate><guid>https://www.ericlight.com/post/amavis.html</guid><description>&lt;p&gt;I&amp;rsquo;ve been dabbling a little bit with &lt;a class="link" href="http://www.iredmail.org" target="_blank" rel="noopener"
 &gt;iRedMail&lt;/a&gt;, mostly just to have a play with a mail server, but also to see what&amp;rsquo;s involved in mail security. iRedMail is a package that &lt;a class="link" href="http://www.iredmail.org/docs/used.components.html" target="_blank" rel="noopener"
 &gt;pulls together&lt;/a&gt; Postfix as an MTA, Dovecot as a POP3 &amp;amp; IMAP server, SOGo for ActiveSync, Roundcube for Webmail, SpamAssassin for spam protection, and ClamAV for virus scanning.&lt;/p&gt;
&lt;p&gt;But of course, ClamAV has &lt;a class="link" href="https://www.av-test.org/en/news/news-single-view/linux-16-security-packages-against-windows-and-linux-malware-put-to-the-test/" target="_blank" rel="noopener"
 &gt;shown disappointing performance&lt;/a&gt;, and it would be really nice to use something more&amp;hellip; commercially suitable.&lt;/p&gt;
&lt;p&gt;To tie together mail receipt and scanning, iRedMail uses &lt;a class="link" href="https://www.ijs.si/software/amavisd/" target="_blank" rel="noopener"
 &gt;Amavis&lt;/a&gt; (strictly speaking, &amp;lsquo;amavisd-new&amp;rsquo;). Amavis uses ClamAV by default, but it comes with a bunch of &lt;a class="link" href="https://www.apt-browse.org/browse/ubuntu/trusty/main/all/amavisd-new/1:2.7.1-2ubuntu3/file/etc/amavis/conf.d/15-av_scanners" target="_blank" rel="noopener"
 &gt;configuration blocks&lt;/a&gt; to bring together other antivirus applications.&lt;/p&gt;
&lt;p&gt;But although amavisd-new is stable and still maintained, some parts of it are really old. In particular, many of these av-scanner config blocks are&amp;hellip; uhh&amp;hellip; &amp;ldquo;deprecated&amp;rdquo;. There&amp;rsquo;s one particular entry for ESET that is dated 2002 - things have changed a lot in the last fifteen years. *shudder*&lt;/p&gt;
&lt;p&gt;So, with the help of &lt;a class="link" href="https://www.akadia.com/download/documents/amavisd.conf.txt" target="_blank" rel="noopener"
 &gt;some documentation&lt;/a&gt;, I managed to piece together a code block that works:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;['ESET File Security for Linux',
 ['/opt/eset/esets/sbin/esets_scan','esets_scan'],
 '--subdir --unsafe --unwanted --clean-mode=strict {}',
 [0,10,100],[1,50],
 qr/threat=&amp;quot;([^&amp;quot;]+)&amp;quot;/m
],
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That would be the end of the story, except I also had to hunt around to find out the right place to put my beautiful codeblock into. It turns out that Debian&amp;rsquo;s Amavis config structure is quite different to the CentOS config that is most-frequently mentioned in the iRedMail forums. I spent a lot of time playing with &lt;code&gt;/etc/amavis/conf.d/15-av_scanners&lt;/code&gt;, and nothing seemed to work. Eventually I found out that Debian features a &lt;code&gt;/etc/amavis/conf.d/50-users&lt;/code&gt; file that overwrites the settings from &lt;code&gt;15-av_scanners&lt;/code&gt;. Finally I had progress!&lt;/p&gt;
&lt;p&gt;Somewhere around line 154 in &lt;code&gt;/etc/amavis/conf.d/50-users&lt;/code&gt;, you&amp;rsquo;ll find an &lt;code&gt;@av_scanners&lt;/code&gt; codeblock. I deleted the ClamAV section in there, and replaced it with the ESET codeblock above. I left the ClamAV settings in the &lt;code&gt;@av_scanners_backup&lt;/code&gt; section, because Amavis will fall back to that if ESET fails.&lt;/p&gt;
&lt;p&gt;That seems to be all! At least, it works with the &lt;a class="link" href="http://www.eicar.org/" target="_blank" rel="noopener"
 &gt;EICAR anti-malware test file&lt;/a&gt;.&lt;/p&gt;</description></item></channel></rss>