Example #1
0
        public void TestWildcardStar()
        {
            WhiteListAddresses obAddresses = _antiSpam.WhiteListAddresses;

            WhiteListAddress obAddress = obAddresses.Add();

            obAddress.EmailAddress   = "white*@microsoft.com";
            obAddress.LowerIPAddress = "0.0.0.0";
            obAddress.UpperIPAddress = "255.255.255.255";
            obAddress.Description    = "Test";
            obAddress.Save();

            // Enable SURBL.
            SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account.
            SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match",
                                           "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-");
            CustomAsserts.Throws <DeliveryFailedException>(() => SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match",
                                                                                                "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"));
            SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**",
                                           "SURBL-Match",
                                           "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-");
            CustomAsserts.Throws <DeliveryFailedException>(() => SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**",
                                                                                                "SURBL-Match",
                                                                                                "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"));

            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 2);
        }
Example #2
0
        public void TestSpamMultipleHits()
        {
            CustomAsserts.AssertSpamAssassinIsRunning();

            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "mult'*****@*****.**", "test");

            _settings.AntiSpam.SpamMarkThreshold   = 1;
            _settings.AntiSpam.SpamDeleteThreshold = 2;

            _settings.AntiSpam.AddHeaderReason    = true;
            _settings.AntiSpam.AddHeaderSpam      = true;
            _settings.AntiSpam.PrependSubject     = true;
            _settings.AntiSpam.PrependSubjectText = "ThisIsSpam";

            // Enable SpamAssassin
            _settings.AntiSpam.SpamAssassinEnabled    = true;
            _settings.AntiSpam.SpamAssassinHost       = "localhost";
            _settings.AntiSpam.SpamAssassinPort       = 783;
            _settings.AntiSpam.SpamAssassinMergeScore = false;
            _settings.AntiSpam.SpamAssassinScore      = 5;


            // Enable SURBL.
            SURBLServer oSURBLServer = _settings.AntiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account, containing both incorrect MX records an SURBL-hits.
            // We should only detect one of these two:
            var smtpClientSimulator = new SmtpClientSimulator();

            _settings.Logging.LogSMTP  = true;
            _settings.Logging.LogDebug = true;
            _settings.Logging.Enabled  = true;
            _settings.Logging.EnableLiveLogging(true);

            // Access the log once to make sure it's cleared.
            string liveLog = _settings.Logging.LiveLog;

            // Should not be possible to send this email since it's results in a spam
            // score over the delete threshold.
            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "INBOX",
                                                                                          "This is a test message. It contains incorrect MX records and a SURBL string: http://surbl-org-permanent-test-point.com/ SpamAssassinString: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"));

            liveLog = _settings.Logging.LiveLog;

            _settings.Logging.EnableLiveLogging(false);

            int iFirst = liveLog.IndexOf("Spam test:");
            int iLast  = liveLog.LastIndexOf("Spam test:");

            Assert.AreNotEqual(-1, iFirst);

            // there should only be one spam test, since any spam match
            // should result in a spam score over the delete threshold.
            Assert.AreEqual(iFirst, iLast);
        }
Example #3
0
        private void SetupSURBLServers()
        {
            SURBLServer black = _application.Settings.AntiSpam.SURBLServers.Add();

            black.Active        = true;
            black.DNSHost       = "127.0.0.1";
            black.RejectMessage = "Test";
            black.Score         = 4;
            black.Save();

            black               = _application.Settings.AntiSpam.SURBLServers.Add();
            black.Active        = true;
            black.DNSHost       = "127.0.0.2";
            black.RejectMessage = "Test2";
            black.Score         = 5;
            black.Save();
        }
Example #4
0
        public void TestSURBLCombinedWithSignature()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            // Create a test account
            // Fetch the default domain

            _domain.SignatureEnabled         = true;
            _domain.SignaturePlainText       = "MyDomainSignature";
            _domain.AddSignaturesToLocalMail = true;
            _domain.Save();

            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Disallow incorrect line endings.
            _antiSpam.SpamMarkThreshold   = 1;
            _antiSpam.SpamDeleteThreshold = 100;
            _antiSpam.AddHeaderReason     = true;
            _antiSpam.AddHeaderSpam       = true;
            _antiSpam.PrependSubject      = true;
            _antiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SURBL.
            SURBLServer surblServer = _antiSpam.SURBLServers[0];

            surblServer.Active = true;
            surblServer.Score  = 5;
            surblServer.Save();

            // Send a messages to this account.
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match",
                                     "This is a test message without a SURBL url.");

            string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");

            if (sMessageContents.Length == 0 ||
                sMessageContents.Contains("X-hMailServer-Spam") ||
                sMessageContents.Contains("ThisIsSpam"))
            {
                throw new Exception("Non-Spam message detected as spam");
            }

            Assert.IsTrue(sMessageContents.Contains(_domain.SignaturePlainText));

            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match",
                                     "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-");

            sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
            if (!sMessageContents.Contains("X-hMailServer-Spam") ||
                !sMessageContents.Contains("ThisIsSpam"))
            {
                throw new Exception("Spam message not detected as spam");
            }

            Assert.IsTrue(sMessageContents.Contains(_domain.SignaturePlainText));
        }
Example #5
0
        public void SurblTestRealWorldBody1()
        {
            TestSetup.DeleteCurrentDefaultLog();

            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Disallow incorrect line endings.
            _antiSpam.SpamMarkThreshold   = 1;
            _antiSpam.SpamDeleteThreshold = 100;
            _antiSpam.AddHeaderReason     = true;
            _antiSpam.AddHeaderSpam       = true;
            _antiSpam.PrependSubject      = true;
            _antiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SURBL.
            SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account.
            var oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", TestResources.SecuniaBody1);

            string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            CustomAssert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam");

            oSURBLServer.Active = false;
            oSURBLServer.Save();


            CustomAssert.IsTrue(TestSetup.DefaultLogContains("SURBL: 2 unique addresses found."));
            CustomAssert.IsTrue(TestSetup.DefaultLogContains("SURBL: Found URL: secunia.com"));
            CustomAssert.IsFalse(TestSetup.DefaultLogContains("SURBL: Found URL: ecunia.com"));
            CustomAssert.IsTrue(TestSetup.DefaultLogContains("SURBL: Lookup: secunia.com.multi.surbl.org"));
            CustomAssert.IsTrue(TestSetup.DefaultLogContains("SURBL: Lookup: ubuntu.com.multi.surbl.org"));
        }
Example #6
0
        public void TestSurblMultipleNegatives()
        {
            TestSetup.DeleteCurrentDefaultLog();

            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Disallow incorrect line endings.
            _antiSpam.SpamMarkThreshold   = 1;
            _antiSpam.SpamDeleteThreshold = 100;
            _antiSpam.AddHeaderReason     = true;
            _antiSpam.AddHeaderSpam       = true;
            _antiSpam.PrependSubject      = true;
            _antiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SURBL.
            SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account.
            var oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match",
                       "Wrapped URL - <a href=3D\"http://test.example1fdafdsfds.com\">Test</a>\r\nWrapped URL - <a href=3D\"http://test.example2fdafdsfds.com\">Test</a>\r\nWrapped URL - <a href=3D\"http://test.example3fdafdsfds.com\">Test</a>\r\n");

            string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            CustomAssert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam");

            oSURBLServer.Active = false;
            oSURBLServer.Save();

            CustomAssert.IsTrue(TestSetup.DefaultLogContains("SURBL: Lookup: example1fdafdsfds.com.multi.surbl.org"));
            CustomAssert.IsTrue(TestSetup.DefaultLogContains("SURBL: Lookup: example2fdafdsfds.com.multi.surbl.org"));
            CustomAssert.IsTrue(TestSetup.DefaultLogContains("SURBL: Lookup: example3fdafdsfds.com.multi.surbl.org"));
        }
Example #7
0
        public void TestSurblAddressEndingWithSingleQuote()
        {
            TestSetup.DeleteCurrentDefaultLog();


            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Disallow incorrect line endings.
            _antiSpam.SpamMarkThreshold   = 1;
            _antiSpam.SpamDeleteThreshold = 100;
            _antiSpam.AddHeaderReason     = true;
            _antiSpam.AddHeaderSpam       = true;
            _antiSpam.PrependSubject      = true;
            _antiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SURBL.
            SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account.
            var oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match",
                       "Wrapped URL - <a href=3D'http://surbl-org-permanent-test-point.com'>Test</a>\r\n");

            oSURBLServer.Active = false;
            oSURBLServer.Save();

            CustomAssert.IsFalse(TestSetup.DefaultLogContains("Lookup: surbl-org-permanent-test-point.com'.multi.surbl.org"));
            CustomAssert.IsTrue(TestSetup.DefaultLogContains("Lookup: surbl-org-permanent-test-point.com.multi.surbl.org"));
        }
Example #8
0
        public void TestSURBLServer()
        {
            Settings oSettings = SingletonProvider <TestSetup> .Instance.GetApp().Settings;

            SURBLServer surblServer = oSettings.AntiSpam.SURBLServers.Add();

            surblServer.DNSHost       = "somehost.com";
            surblServer.RejectMessage = "somerejectmessage";
            surblServer.Score         = 5;

            surblServer.Save();

            if (surblServer.ID == 0)
            {
                throw new Exception("SURBL server not saved properly");
            }

            oSettings.AntiSpam.SURBLServers.DeleteByDBID(surblServer.ID);
        }
Example #9
0
        public void TestDeleteThresholdLowerThanMarkThreshold()
        {
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;

            antiSpam.SpamMarkThreshold   = 15;
            antiSpam.SpamDeleteThreshold = 0;

            antiSpam.AddHeaderReason    = true;
            antiSpam.AddHeaderSpam      = true;
            antiSpam.PrependSubject     = true;
            antiSpam.PrependSubjectText = "ThisIsSpam";

            antiSpam.CheckHostInHelo      = true;
            antiSpam.CheckHostInHeloScore = 10;

            // Enable SURBL.
            SURBLServer oSURBLServer = antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 10;
            oSURBLServer.Save();

            // Send a messages to this account, containing both incorrect MX records an SURBL-hits.
            // We should only detect one of these two:
            var smtpClientSimulator = new SmtpClientSimulator();

            // Should not be possible to send this email since it's results in a spam
            // score over the delete threshold.
            smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "INBOX",
                                     "Test http://surbl-org-permanent-test-point.com/ Test 2");

            string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:"));
            Assert.IsTrue(message.Contains("X-hMailServer-Reason-2:"));
        }
Example #10
0
        public void TestOneFailOnePass()
        {
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            _settings.AntiSpam.SpamMarkThreshold   = 1;
            _settings.AntiSpam.SpamDeleteThreshold = 100;

            _settings.AntiSpam.AddHeaderReason    = true;
            _settings.AntiSpam.AddHeaderSpam      = true;
            _settings.AntiSpam.PrependSubject     = true;
            _settings.AntiSpam.PrependSubjectText = "ThisIsSpam";

            _settings.AntiSpam.CheckHostInHelo      = true;
            _settings.AntiSpam.CheckHostInHeloScore = 5;

            // Enable SURBL.
            SURBLServer oSURBLServer = _settings.AntiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account, containing both incorrect MX records an SURBL-hits.
            // We should only detect one of these two:
            var smtpClientSimulator = new SmtpClientSimulator();

            // Should not be possible to send this email since it's results in a spam
            // score over the delete threshold.
            smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "INBOX",
                                     "This is a test message.");

            string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:"));
            Assert.IsFalse(message.Contains("X-hMailServer-Reason-2:"));
        }
Example #11
0
        public void DisableSpamProtection()
        {
            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;

            if (antiSpam.SpamMarkThreshold != 10000)
            {
                antiSpam.SpamMarkThreshold = 10000;
            }

            if (antiSpam.SpamDeleteThreshold != 10000)
            {
                antiSpam.SpamDeleteThreshold = 10000;
            }

            if (antiSpam.CheckHostInHelo)
            {
                antiSpam.CheckHostInHelo = false;
            }

            if (antiSpam.GreyListingEnabled)
            {
                antiSpam.GreyListingEnabled = false;
            }

            if (antiSpam.BypassGreylistingOnMailFromMX)
            {
                antiSpam.BypassGreylistingOnMailFromMX = false;
            }

            if (antiSpam.SpamAssassinEnabled)
            {
                antiSpam.SpamAssassinEnabled = false;
            }

            if (antiSpam.TarpitCount != 0)
            {
                antiSpam.TarpitCount = 0;
            }

            if (antiSpam.TarpitDelay != 0)
            {
                antiSpam.TarpitDelay = 0;
            }

            if (antiSpam.UseMXChecks)
            {
                antiSpam.UseMXChecks = false;
            }

            if (antiSpam.UseSPF)
            {
                antiSpam.UseSPF = false;
            }

            if (antiSpam.MaximumMessageSize != 1024)
            {
                antiSpam.MaximumMessageSize = 1024;
            }

            if (antiSpam.DKIMVerificationEnabled)
            {
                antiSpam.DKIMVerificationEnabled = false;
            }

            antiSpam.WhiteListAddresses.Clear();

            for (int i = 0; i < antiSpam.DNSBlackLists.Count; i++)
            {
                DNSBlackList list = antiSpam.DNSBlackLists[i];
                if (list.Active)
                {
                    list.Active = false;
                    list.Save();
                }
            }

            DNSBlackLists dnsBlackLists = antiSpam.DNSBlackLists;

            while (dnsBlackLists.Count > 0)
            {
                dnsBlackLists.DeleteByDBID(dnsBlackLists[0].ID);
            }

            SURBLServers surblServers = antiSpam.SURBLServers;

            for (int i = surblServers.Count - 1; i >= 0; i--)
            {
                if (surblServers[i].DNSHost != "multi.surbl.org")
                {
                    surblServers.DeleteByDBID(surblServers[i].ID);
                }
                else
                {
                    surblServers[i].Active = false;
                }
            }

            if (surblServers.Count == 0)
            {
                SURBLServer surblServer = surblServers.Add();
                surblServer.Active        = false;
                surblServer.DNSHost       = "multi.surbl.org";
                surblServer.RejectMessage = "Nope";
                surblServer.Score         = 5;
                surblServer.Save();
            }

            IncomingRelays incomingRelays = _settings.IncomingRelays;

            while (incomingRelays.Count > 0)
            {
                incomingRelays.DeleteByDBID(incomingRelays[0].ID);
            }

            antiSpam.ClearGreyListingTriplets();
        }
Example #12
0
        public void TestSpamProtectionPostTransmission()
        {
            _application.Settings.AntiSpam.SpamMarkThreshold   = 1;
            _application.Settings.AntiSpam.SpamDeleteThreshold = 100;
            _application.Settings.AntiSpam.AddHeaderReason     = true;
            _application.Settings.AntiSpam.AddHeaderSpam       = true;
            _application.Settings.AntiSpam.PrependSubject      = true;
            _application.Settings.AntiSpam.PrependSubjectText  = "ThisIsSpam";


            SURBLServer oSURBLServer = _application.Settings.AntiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            var messages = new List <string>();

            string message = "Received: from example.com (example.com [1.2.3.4]) by mail.host.edu\r\n" +
                             "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "http://surbl-org-permanent-test-point.com/";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

                Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.DaysToKeepMessages    = -1;
                fa.UseAntiSpam           = true;

                fa.Save();
                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                fa.Delete();

                string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

                Assert.IsTrue(downloadedMessage.Contains("X-hMailServer-Spam: YES"));
            }
        }
Example #13
0
        public void TestWhitelistAllIPv6Addresses()
        {
            var addresses = GetAllLocalAddresses(System.Net.Sockets.AddressFamily.InterNetworkV6);

            if (addresses.Length == 0)
            {
                Assert.Inconclusive("IPv6 not available.");
            }

            var firstAddress = addresses[0];

            // Enable this port
            var tcpIpPort = _application.Settings.TCPIPPorts.Add();

            tcpIpPort.Address    = firstAddress;
            tcpIpPort.Protocol   = eSessionType.eSTSMTP;
            tcpIpPort.PortNumber = 25;
            tcpIpPort.Save();

            // Add an IP range for ALL ipv6 source port.
            foreach (var address in addresses)
            {
                var ipRange = _application.Settings.SecurityRanges.Add();
                ipRange.Name = "IPv6Range" + address;
                ipRange.AllowDeliveryFromLocalToLocal   = true;
                ipRange.AllowDeliveryFromLocalToRemote  = true;
                ipRange.AllowDeliveryFromRemoteToLocal  = true;
                ipRange.AllowDeliveryFromRemoteToRemote = true;
                ipRange.AllowSMTPConnections            = true;
                ipRange.RequireAuthForDeliveryToLocal   = false;
                ipRange.EnableSpamProtection            = true;
                ipRange.LowerIP = address;
                ipRange.UpperIP = address;
                ipRange.Save();
            }

            _application.Stop();
            _application.Start();

            // Enable SURBL.
            SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Make sure we are now blacklisted.
            var smtpClient = new SmtpClientSimulator(false, 25, IPAddress.Parse(firstAddress));

            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody));

            // White list all IPv6 addresses
            var obAddress = _antiSpam.WhiteListAddresses.Add();

            obAddress.EmailAddress   = "*";
            obAddress.LowerIPAddress = "::";
            obAddress.UpperIPAddress = "ffff::ffff";
            obAddress.Description    = "Test";
            obAddress.Save();

            // Make sure we can now send again.
            smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody);

            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1);
        }