Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nettacker/api/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import random
import string
import time
from pathlib import Path
from threading import Thread
from types import SimpleNamespace

Expand Down Expand Up @@ -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},
)


Expand Down
6 changes: 3 additions & 3 deletions nettacker/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions nettacker/core/arg_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import sys
from argparse import ArgumentParser
from pathlib import Path

import yaml

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion nettacker/core/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions nettacker/core/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import importlib
import math
import multiprocessing
import os
import random
import re
import string
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading