{"id":1051,"date":"2016-01-14T13:38:16","date_gmt":"2016-01-14T12:38:16","guid":{"rendered":"http:\/\/vejr.tomas.dk\/ps\/?p=1051"},"modified":"2024-01-05T14:08:22","modified_gmt":"2024-01-05T13:08:22","slug":"autofirewall-for-linux-mta-running-postfix","status":"publish","type":"post","link":"https:\/\/tomas.dk\/ps\/autofirewall-for-linux-mta-running-postfix\/","title":{"rendered":"Autofirewall for Linux MTA running postfix"},"content":{"rendered":"\n<p>I have written a perl program that protects a Linux MTA running postfix.<\/p>\n\n\n\n<p>The program snifs on \/var\/log\/mail. If a host is doing something wrong\/illegal he will be blocked for 24 hours.<\/p>\n\n\n\n<p>Three illegal attemps in 20 minutes triggers a drop action in firewalld.<br \/>Sorry for the comments in the script being in danish.<\/p>\n\n\n\n<p>Installation:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Download the file&nbsp;<a href=\"http:\/\/tomas.dk\/af\/autofirewall.pl\">autofirewall.pl<\/a><\/li>\n\n\n\n<li>Edit user and password for access to mysql in the file.\n<p># ### MAIN LOOP ###<\/p>\n<p># Forbind til database<br \/>$dbh = DBI-&gt;connect(&#8220;dbi:mysql:$firewalldb&#8221;, &#8220;<span style=\"color: #ff0000;\">USER<\/span>&#8220;, &#8220;<span style=\"color: #ff0000;\">PASSWD<\/span>&#8220;) <br \/>or die &#8220;Kunne ikke forbinde til databasen: $firewalldb\\n&#8221;;<\/p>\n<\/li>\n\n\n\n<li>Edit WAN ip and whitelisted ip ranges:<br \/>my $wanaddr = &#8220;aaa.bbb.ccc.ddd&#8221;; #\/32<br \/>my @whitelist = (&#8220;aaa.bbb.ccc&#8221;, &#8220;aaa.bbb.ddd&#8221;); # \/24<\/li>\n\n\n\n<li>Get sql definitions file&nbsp;<a href=\"http:\/\/tomas.dk\/af\/autofirewall.sql\">autofirewall.sql<\/a> and apply it to the autofirewall database.<\/li>\n\n\n\n<li>Do \u201cchmod 555&nbsp;autofirewall.pl\u201d<\/li>\n\n\n\n<li>Do autofirewall.sql in mysql or&nbsp;MariaDB<\/li>\n\n\n\n<li>Add \u201c*\/10 * * * * \/path\/to\/autofirewall.pl &gt;&gt; \/path\/to\/logfile\u201d to roots crontab<\/li>\n\n\n\n<li>Your MTA is now ptrotected against&nbsp;brute force&nbsp;attacks.<\/li>\n<\/ol>\n\n\n\n<p><strong>Update 2016\/01\/14:<\/strong><\/p>\n\n\n\n<p>Minor fixes and new function applied that restores the firewall after firewall flush or system reboot.<\/p>\n\n\n\n<p><strong>Update 2024\/01\/05:<\/strong><\/p>\n\n\n\n<p>Script changed to use firewallcmd. <br \/>Database structure is now on mariadb.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have written a perl program that protects a Linux MTA running postfix. The program snifs on \/var\/log\/mail. If a host is doing something wrong\/illegal he will be blocked for 24 hours. Three illegal attemps in 20 minutes triggers a drop action in firewalld.Sorry for the comments in the script being in danish. Installation: Update&hellip; <a class=\"more-link\" href=\"https:\/\/tomas.dk\/ps\/autofirewall-for-linux-mta-running-postfix\/\">L\u00e6s mere <span class=\"screen-reader-text\">Autofirewall for Linux MTA running postfix<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12237,1,28,6],"tags":[],"class_list":["post-1051","post","type-post","status-publish","format-standard","hentry","category-hobby","category-ikke-kategoriseret","category-linux","category-teknik","entry"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/posts\/1051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/comments?post=1051"}],"version-history":[{"count":3,"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/posts\/1051\/revisions"}],"predecessor-version":[{"id":2543,"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/posts\/1051\/revisions\/2543"}],"wp:attachment":[{"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/media?parent=1051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/categories?post=1051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tomas.dk\/ps\/wp-json\/wp\/v2\/tags?post=1051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}