{"id":446,"date":"2021-07-23T12:30:03","date_gmt":"2021-07-23T12:30:03","guid":{"rendered":"https:\/\/ssdsunucum.com\/blog\/how-to-customize-the-exim-system-filter-file\/"},"modified":"2021-07-23T12:30:03","modified_gmt":"2021-07-23T12:30:03","slug":"how-to-customize-the-exim-system-filter-file","status":"publish","type":"post","link":"https:\/\/ssdsunucum.com\/blog\/how-to-customize-the-exim-system-filter-file\/","title":{"rendered":"How to Customize the Exim System Filter File"},"content":{"rendered":"<\/p>\n<div class=\"col-md-9\">\n<div class=\"flex-column flex-md-row article-header\"><\/div>\n<hr>\n<h2 id=\"overview\">Overview<\/h2>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n        The steps in this document are for advanced users only.\n    <\/div>\n<\/div>\n<p>The Exim system filter file scans messages that your server has received, but that it has not yet delivered. To add custom filter rules to your Exim configuration, you may either create custom filter rule files for Exim to include in its configuration, or create a custom Exim system filter file.<\/p>\n<h2 id=\"how-to-create-a-custom-filter-rule-file\">How to create a custom filter rule file<\/h2>\n<p>To create a custom filter rule file, perform the following steps:<\/p>\n<ol>\n<li>Create a file in the <code>\/usr\/local\/cpanel\/etc\/exim\/sysfilter\/options\/<\/code> directory.<\/li>\n<li>\n<p>Within that file, enter your custom filter rules. For example, to block mail from <code>user@example.com<\/code>, add the following rule:<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"color:#66d9ef\">if<\/span> (<span style=\"color:#e6db74\">\"$h_from:\"<\/span> <span style=\"color:#a6e22e\">contains<\/span> <span style=\"color:#e6db74\">\"user@example.com\"<\/span>)\n<span style=\"color:#a6e22e\">then<\/span> <span style=\"color:#a6e22e\">fail<\/span>\n<span style=\"color:#a6e22e\">endif<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p>Navigate to WHM\u2019s <em>Exim Configuration Manager<\/em> interface (<em>WHM &gt;&gt; Home &gt;&gt; Service Configuration &gt;&gt; Exim Configuration Manager<\/em>). In the <em>Basic Editor<\/em> section, select the <em>Filters<\/em> tab.<\/p>\n<\/li>\n<li>\n<p>Disable any undesired filter rules.<\/p>\n<\/li>\n<li>\n<p>Click <em>Save<\/em>.<\/p>\n<\/li>\n<\/ol>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n        The Exim configuration enables all of the custom filter rules within the <code>\/usr\/local\/cpanel\/etc\/exim\/sysfilter\/options\/<\/code> directory.\n    <\/div>\n<\/div>\n<h2 id=\"customfilter\">How to create a custom Exim system filter file<\/h2>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n<p>Do <strong>not<\/strong> directly edit the <code>\/etc\/cpanel_exim_system_filter<\/code> file. The system will lose any changes when your Exim Configuration rebuilds.<\/p>\n<\/p><\/div>\n<\/div>\n<p>To create a custom system filter file, perform the following steps:<\/p>\n<ol>\n<li>Log in to the server as the <code>root<\/code> user.<\/li>\n<li>\n<p>Run the following command to copy the <code>\/etc\/cpanel_exim_system_filter<\/code> file:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">cp <span style=\"color:#f92672\">-<\/span>p <span style=\"color:#e6db74\">\/etc\/c<\/span>panel_exim_system_filter <span style=\"color:#e6db74\">\/etc\/c<\/span>panel_system_filter_new<\/code><\/pre>\n<\/div>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n<p>We <strong>strongly<\/strong> recommend that you copy this file before you edit it. If you experience problems, use the file to revert your changes.<\/p>\n<\/p><\/div>\n<\/div>\n<\/li>\n<li>\n<p>Confirm that the new file has the following ownership and file permissions:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\"><span style=\"color:#f92672\">-<\/span>rw<span style=\"color:#f92672\">-<\/span>r<span style=\"color:#f92672\">--<\/span>r<span style=\"color:#f92672\">--<\/span> <span style=\"color:#ae81ff\">1<\/span> root root<\/code><\/pre>\n<\/div>\n<\/li>\n<li>\n<p>Use your preferred text editor to edit the <code>\/etc\/cpanel_system_filter_new<\/code> file.<\/p>\n<\/li>\n<li>\n<p>Navigate to the <em>Basic Editor<\/em> section of  WHM\u2019s <em>Exim Configuration Manager<\/em> interface (<em>WHM &gt;&gt; Home &gt;&gt; Service Configuration &gt;&gt; Exim Configuration Manager<\/em>).<\/p>\n<\/li>\n<li>\n<p>Select the textbox option for the <em>System Filter File<\/em> setting.<\/p>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n<p>Regardless of which option you select, the Exim configuration will include <strong>all<\/strong> of the files within the <code>\/usr\/local\/cpanel\/etc\/exim\/sysfilter\/options\/<\/code> directory.<\/p>\n<\/p><\/div>\n<\/div>\n<\/li>\n<li>\n<p>Enter the new file\u2019s absolute path in the text box (for example, <code>\/etc\/cpanel_system_filter_new<\/code>).<\/p>\n<\/li>\n<li>\n<p>Click <em>Save<\/em>.<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>Exim restarts when you save changes in the <em>Exim Configuration Manager<\/em> interface.<\/p>\n<\/p><\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>For more information about the Exim system filter file, visit Exim\u2019s system filter documentation.<\/p>\n<h2 id=\"how-to-block-additional-extensions\">How to block additional extensions<\/h2>\n<p>The <code>\/etc\/cpanel_exim_system_filter<\/code> file is the system\u2019s default filter file. It contains the following sections:<\/p>\n<ul>\n<li>Single-part MIME messages with suspicious name extensions.<\/li>\n<li>Single-part MIME messages with suspicious name extensions that use unquoted filenames.<\/li>\n<li>Embedded VBS attachments.<\/li>\n<li>Embedded VBS attachments that use unquoted filenames.<\/li>\n<\/ul>\n<p>To block a new extension:<\/p>\n<div class=\"callout callout-success\">\n<div class=\"callout-heading\">Remember:<\/div>\n<div class=\"callout-content\">\n<p>Do <strong>not<\/strong> directly edit the <code>\/etc\/cpanel_exim_system_filter<\/code> file. The system will lose any changes when your Exim Configuration rebuilds.<\/p>\n<\/p><\/div>\n<\/div>\n<ol>\n<li>\n<p>Create a custom filter file. To do this, follow steps 1-3 of the How to create a custom Exim system filter file section.<\/p>\n<\/li>\n<li>\n<p>Edit the regular expressions in the following lines:\n<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">4\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">5\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">6\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">7\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">header_content<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#66d9ef\">type<\/span>: <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:file)?name=(\"[^\"]+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc])\")\"<\/span>\n\n<span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">header_content<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#66d9ef\">type<\/span>: <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:file)?name=(\\\\S+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc]))\"<\/span>\n\n<span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">message_body<\/span> <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:Content-(?:Type:(?&gt;\\\\s*)[\\\\w-]+\/[\\\\w-]+|Disposition:(?&gt;\\\\s*)attachment);(?&gt;\\\\s*)(?:file)?name=|begin(?&gt;\\\\s+)[0-7]{3,4}(?&gt;\\\\s+))(\"[^\"]+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc])\")[\\\\s;]\"<\/span>\n\n<span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">message_body<\/span> <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:Content-(?:Type:(?&gt;\\\\s*)[\\\\w-]+\/[\\\\w-]+|Disposition:(?&gt;\\\\s*)attachment);(?&gt;\\\\s*)(?:file)?name=|begin(?&gt;\\\\s+)[0-7]{3,4}(?&gt;\\\\s+))(\\\\S+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc]))[\\\\s;]\"<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>To unblock an extension, remove it from those regular expressions.<\/p>\n<\/p><\/div>\n<\/div>\n<p>For example, if you blocked the <code>.foo<\/code> extension, your changes would resemble the following example:<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">4\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">5\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">6\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">7\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">header_content<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#66d9ef\">type<\/span>: <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:file)?name=(\"[^\"]+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|foo|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc])\")\"<\/span>\n\n<span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">header_content<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#66d9ef\">type<\/span>: <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:file)?name=(\\\\S+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|foo|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc]))\"<\/span>\n\n<span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">message_body<\/span> <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:Content-(?:Type:(?&gt;\\\\s*)[\\\\w-]+\/[\\\\w-]+|Disposition:(?&gt;\\\\s*)attachment);(?&gt;\\\\s*)(?:file)?name=|begin(?&gt;\\\\s+)[0-7]{3,4}(?&gt;\\\\s+))(\"[^\"]+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|foo|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc])\")[\\\\s;]\"<\/span>\n\n<span style=\"color:#66d9ef\">if<\/span> <span style=\"color:#960050;background-color:#1e0010\">$<\/span><span style=\"color:#a6e22e\">message_body<\/span> <span style=\"color:#a6e22e\">matches<\/span> <span style=\"color:#e6db74\">\"(?:Content-(?:Type:(?&gt;\\\\s*)[\\\\w-]+\/[\\\\w-]+|Disposition:(?&gt;\\\\s*)attachment);(?&gt;\\\\s*)(?:file)?name=|begin(?&gt;\\\\s+)[0-7]{3,4}(?&gt;\\\\s+))(\\\\S+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|foo|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc]))[\\\\s;]\"<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p>Log in to WHM as the <code>root<\/code> user.<\/p>\n<\/li>\n<li>\n<p>Navigate to the Filters section of WHM\u2019s <em>Exim Configuration Manager<\/em> interface (<em>WHM &gt;&gt; Home &gt;&gt; Service Configuration &gt;&gt; Exim Configuration Manager<\/em>).<\/p>\n<\/li>\n<li>\n<p>Enter the new filter file\u2019s filepath in the <em>System Filter File<\/em> option\u2019s text box.<\/p>\n<\/li>\n<li>\n<p>Click <em>Save<\/em>.<\/p>\n<\/li>\n<\/ol><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview Warning: The steps in this document are for advanced users only. The Exim system filter file scans messages that your server has received, but that it has not yet delivered. To add custom filter rules to your Exim configuration, you may either create custom filter rule files for Exim to include in its configuration, &hellip;<\/p>\n","protected":false},"author":1,"featured_media":447,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/446"}],"collection":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/comments?post=446"}],"version-history":[{"count":0,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/446\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media\/447"}],"wp:attachment":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media?parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/categories?post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/tags?post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}