def test_drop_noalert(self): """ Test the rules with "noalert" are not marked as drop. """ rule_without_noalert = """alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"ET TROJAN [CrowdStrike] ANCHOR PANDA Torn RAT Beacon Message Header Local"; flow:established, to_server; dsize:16; content:"|00 00 00 11 c8 00 00 00 00 00 00 00 00 00 00 00|"; depth:16; flowbits:set,ET.Torn.toread_header; reference:url,blog.crowdstrike.com/whois-anchor-panda/index.html; classtype:trojan-activity; sid:2016659; rev:2; metadata:created_at 2013_03_22, updated_at 2013_03_22;)""" rule_with_noalert = """alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"ET TROJAN [CrowdStrike] ANCHOR PANDA Torn RAT Beacon Message Header Local"; flow:established, to_server; dsize:16; content:"|00 00 00 11 c8 00 00 00 00 00 00 00 00 00 00 00|"; depth:16; flowbits:set,ET.Torn.toread_header; flowbits: noalert; reference:url,blog.crowdstrike.com/whois-anchor-panda/index.html; classtype:trojan-activity; sid:2016659; rev:2; metadata:created_at 2013_03_22, updated_at 2013_03_22;)""" rule = suricata.update.rule.parse(rule_without_noalert) matcher = main.IdRuleMatcher.parse("2016659") rule_filter = main.DropRuleFilter(matcher) self.assertTrue(rule_filter.match(rule)) rule = suricata.update.rule.parse(rule_with_noalert) matcher = main.IdRuleMatcher.parse("2016659") rule_filter = main.DropRuleFilter(matcher) self.assertFalse(rule_filter.match(rule))
def test_enabled_rule(self): rule0 = suricata.update.rule.parse(self.rule_string, "rules/malware.rules") id_matcher = main.IdRuleMatcher.parse("2020757") self.assertTrue(id_matcher.match(rule0)) drop_filter = main.DropRuleFilter(id_matcher) rule1 = drop_filter.filter(rule0) self.assertEquals("drop", rule1.action) self.assertTrue(rule1.enabled) self.assertTrue(str(rule1).startswith("drop"))