diff --git a/nettacker/api/engine.py b/nettacker/api/engine.py index 9979e05ba..4bf6a535b 100644 --- a/nettacker/api/engine.py +++ b/nettacker/api/engine.py @@ -5,6 +5,7 @@ import random import string import time +from pathlib import Path from threading import Thread from types import SimpleNamespace @@ -392,7 +393,7 @@ def get_result_content(): return Response( file_content, mimetype=mime_types().get(os.path.splitext(filename)[1], "text/plain"), - headers={"Content-Disposition": "attachment;filename=" + filename.split("/")[-1]}, + headers={"Content-Disposition": "attachment;filename=" + Path(filename).name}, ) diff --git a/nettacker/core/app.py b/nettacker/core/app.py index 5cd47a98b..4d9051a95 100644 --- a/nettacker/core/app.py +++ b/nettacker/core/app.py @@ -27,7 +27,7 @@ from nettacker.core.module import Module from nettacker.core.socks_proxy import set_socks_proxy from nettacker.core.utils import common as common_utils -from nettacker.core.utils.common import wait_for_threads_to_finish +from nettacker.core.utils.common import wait_for_threads_to_finish, is_running_with_privileges from nettacker.database.db import find_events, remove_old_logs from nettacker.database.mysql import mysql_create_database, mysql_create_tables from nettacker.database.postgresql import postgres_create_database @@ -66,7 +66,7 @@ def print_logo(): log.reset_color() def check_dependencies(self): - if sys.platform not in {"darwin", "freebsd13", "freebsd14", "freebsd15", "linux"}: + if sys.platform not in {"darwin", "freebsd13", "freebsd14", "freebsd15", "linux", "win32"}: die_failure(_("error_platform")) try: @@ -165,7 +165,7 @@ def expand_targets(self, scan_id): self.arguments.targets.append(sub_domain) # icmp_scan if self.arguments.ping_before_scan: - if os.geteuid() == 0: + if is_running_with_privileges(): selected_modules = self.arguments.selected_modules self.arguments.selected_modules = ["icmp_scan"] self.start_scan(scan_id) diff --git a/nettacker/core/arg_parser.py b/nettacker/core/arg_parser.py index e8aed1218..9240eec26 100644 --- a/nettacker/core/arg_parser.py +++ b/nettacker/core/arg_parser.py @@ -1,6 +1,7 @@ import json import sys from argparse import ArgumentParser +from pathlib import Path import yaml @@ -48,10 +49,9 @@ def load_graphs(): Returns: an array of graph names """ - graph_names = [] for graph_library in Config.path.graph_dir.glob("*/engine.py"): - graph_names.append(str(graph_library).split("/")[-2] + "_graph") + graph_names.append(graph_library.parent.name + "_graph") return list(set(graph_names)) @staticmethod @@ -65,8 +65,7 @@ def load_languages(): languages_list = [] for language in Config.path.locale_dir.glob("*.yaml"): - languages_list.append(str(language).split("/")[-1].split(".")[0]) - + languages_list.append(Path(language).stem) return list(set(languages_list)) @staticmethod @@ -83,8 +82,9 @@ def load_modules(limit=-1, full_details=False): # Search for Modules module_names = {} for module_name in sorted(Config.path.modules_dir.glob("**/*.yaml")): - library = str(module_name).split("/")[-1].split(".")[0] - category = str(module_name).split("/")[-2] + module_path = Path(module_name) + library = module_path.stem + category = module_path.parent.name module = f"{library}_{category}" contents = yaml.safe_load(TemplateLoader(module).open().split("payload:")[0]) module_names[module] = contents["info"] if full_details else None diff --git a/nettacker/core/template.py b/nettacker/core/template.py index ab6207237..d88bc2bf3 100644 --- a/nettacker/core/template.py +++ b/nettacker/core/template.py @@ -32,7 +32,9 @@ def open(self): action = module_name_parts[-1] library = "_".join(module_name_parts[:-1]) - with open(Config.path.modules_dir / action / f"{library}.yaml") as yaml_file: + with open( + Config.path.modules_dir / action / f"{library}.yaml", encoding="utf-8" + ) as yaml_file: return yaml_file.read() def format(self): diff --git a/nettacker/core/utils/common.py b/nettacker/core/utils/common.py index 6418bbb90..0dd09e3c7 100644 --- a/nettacker/core/utils/common.py +++ b/nettacker/core/utils/common.py @@ -5,6 +5,7 @@ import importlib import math import multiprocessing +import os import random import re import string @@ -450,3 +451,19 @@ def generate_compare_filepath(scan_id): date_time=now(format="%Y_%m_%d_%H_%M_%S"), scan_id=scan_id, ) + + +def is_running_with_privileges(): + """ + Check if running with elevated privileges (root/admin) + + Returns: + bool: True if running as root (Unix) or Administrator (Windows) + """ + if sys.platform == "win32": + try: + return ctypes.windll.shell32.IsUserAnAdmin() != 0 + except Exception: + return False + else: + return os.geteuid() == 0 diff --git a/pyproject.toml b/pyproject.toml index e6939b9b5..f69393774 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ requests = "^2.32.3" sqlalchemy = "^2.0.22" texttable = "^1.7.0" zipp = "^3.19.1" -uvloop = "^0.21.0" +uvloop = {version = "^0.21.0", markers = "sys_platform != 'win32'"} pymysql = "^1.1.1" impacket = "^0.11.0"