Skip to content

Commit

Permalink
lookup for NS and A records
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijk4poor committed Jul 17, 2024
1 parent a578fb4 commit 52098dc
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 59 deletions.
49 changes: 0 additions & 49 deletions artemis/modules/dns_resolver.py

This file was deleted.

61 changes: 61 additions & 0 deletions artemis/modules/domain_scanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
from typing import Set
from karton.core import Task
from artemis.resolvers import lookup, ResolutionException

from artemis.binds import TaskStatus, TaskType
from artemis.module_base import ArtemisBase

class DomainScanner(ArtemisBase):
"""
DNS checker to verify if domains exist in the DNS system.
"""

identity = "domain_scanner"
filters = [
{"type": TaskType.DOMAIN.value},
]

def run(self, current_task: Task) -> None:
domain = current_task.get_payload(TaskType.DOMAIN)
domain_exists = self.check_domain_exists(domain)

if domain_exists:
self.db.save_task_result(
task=current_task,
status=TaskStatus.OK,
data={
"domain": domain,
"exists": True
}
)
# Create a new task for the next module
new_task = Task(
{"type": TaskType.DOMAIN},
payload={TaskType.DOMAIN: domain},
payload_persistent={"domain_exists": True}
)
self.add_task(current_task, new_task)
else:
self.db.save_task_result(
task=current_task,
status=TaskStatus.ERROR,
status_reason=f"Domain does not exist: {domain}",
data={"domain": domain, "exists": False}
)

def check_domain_exists(self, domain: str) -> bool:
try:
# Check for NS records
ns_records = lookup(domain, "NS")
if ns_records:
return True

# If no NS records, check for A records
a_records = lookup(domain, "A")
return len(a_records) > 0
except ResolutionException:
return False

if __name__ == "__main__":
DomainScanner().loop()
19 changes: 9 additions & 10 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ services:
restart: always
volumes: ["./docker/karton.ini:/etc/karton/karton.ini", "${DOCKER_COMPOSE_ADDITIONAL_SHARED_DIRECTORY:-./shared}:/shared/"]

karton-dns_resolver:
<<: *artemis-build-or-image
command: "python3 -m artemis.modules.dns_resolver"
depends_on: [karton-system, karton-logger]
env_file: .env
restart: always
volumes: ["./docker/karton.ini:/etc/karton/karton.ini", "${DOCKER_COMPOSE_ADDITIONAL_SHARED_DIRECTORY:-./shared}:/shared/"]

karton-dns_scanner:
<<: *artemis-build-or-image
command: "python3 -m artemis.modules.dns_scanner"
Expand All @@ -159,7 +151,15 @@ services:
env_file: .env
restart: always
volumes: ["./docker/karton.ini:/etc/karton/karton.ini", "${DOCKER_COMPOSE_ADDITIONAL_SHARED_DIRECTORY:-./shared}:/shared/"]


karton-domain_scanner:
<<: *artemis-build-or-image
command: "python3 -m artemis.modules.domain_scanner"
depends_on: [karton-system, karton-logger]
env_file: .env
restart: always
volumes: ["./docker/karton.ini:/etc/karton/karton.ini", "${DOCKER_COMPOSE_ADDITIONAL_SHARED_DIRECTORY:-./shared}:/shared/"]

karton-drupal_scanner:
<<: *artemis-build-or-image
command: "python3 -m artemis.modules.drupal_scanner"
Expand All @@ -184,7 +184,6 @@ services:
restart: always
volumes: ["./docker/karton.ini:/etc/karton/karton.ini", "${DOCKER_COMPOSE_ADDITIONAL_SHARED_DIRECTORY:-./shared}:/shared/"]


karton-http_service_to_url:
<<: *artemis-build-or-image
command: "python3 -m artemis.modules.http_service_to_url"
Expand Down

0 comments on commit 52098dc

Please sign in to comment.