Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazet committed Oct 18, 2023
1 parent 82b72ba commit abf747a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 2 additions & 4 deletions artemis/module_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,10 @@ def _is_blocklisted(self, task: Task) -> bool:

if ip_addresses:
for ip in ip_addresses:
if should_block_scanning(
domain=host, ip=ip, karton_name=self.identity, blocklist=self._blocklist
):
if should_block_scanning(domain=host, ip=ip, karton_name=self.identity, blocklist=self._blocklist):
return True
else:
if should_block_scanning(domain=domain, ip=None, karton_name=self.identity, blocklist=self._blocklist):
if should_block_scanning(domain=host, ip=None, karton_name=self.identity, blocklist=self._blocklist):
return True
elif is_ip_address(host):
domain = task.payload.get("last_domain", None)
Expand Down
14 changes: 9 additions & 5 deletions test/unit/test_blocklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import ipaddress
import unittest

from artemis.blocklist import BlocklistItem, BlocklistMode, blocklist_reports
from artemis.blocklist import (
BlocklistItem,
BlocklistMode,
blocklist_reports,
should_block_scanning,
)
from artemis.reporting.base.report import Report
from artemis.reporting.base.report_type import ReportType



class ScanningBlocklistTest(unittest.TestCase):
def test_ip_range_matching(self) -> None:
blocklist_item1 = BlocklistItem(
Expand All @@ -18,7 +22,7 @@ def test_ip_range_matching(self) -> None:
self.assertEqual(should_block_scanning(None, "1.1.1.1", "karton-name", [blocklist_item1]), True)

def test_domain_matching(self) -> None:
blocklist_item = BlocklistItem(
blocklist_item1 = BlocklistItem(
mode=BlocklistMode.BLOCK_SCANNING_AND_REPORTING,
domain="example.com",
)
Expand All @@ -27,7 +31,7 @@ def test_domain_matching(self) -> None:
self.assertEqual(should_block_scanning("www.example.com", None, "karton-name", [blocklist_item1]), True)

def test_karton_name_matching(self) -> None:
blocklist_item = BlocklistItem(
blocklist_item1 = BlocklistItem(
mode=BlocklistMode.BLOCK_SCANNING_AND_REPORTING,
karton_name="bruter",
)
Expand All @@ -40,7 +44,7 @@ def test_expiry(self) -> None:
until=datetime.datetime(2023, 1, 9),
)
self.assertEqual(should_block_scanning("domain.com", "1.1.1.1", "nuclei", [blocklist_item1]), False)
blocklist_item1 = BlocklistItem(
blocklist_item2 = BlocklistItem(
mode=BlocklistMode.BLOCK_SCANNING_AND_REPORTING,
until=datetime.datetime(2999, 1, 9),
)
Expand Down

0 comments on commit abf747a

Please sign in to comment.