-
-
Notifications
You must be signed in to change notification settings - Fork 915
Fixed windows compatibility issue #1142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
12d3511
4e9ce13
304e786
a30f91d
6e18045
8d39d1f
489afa6
94332c2
fcb3c7c
b41f6d9
6259f72
4f8cae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,23 +51,17 @@ def load_graphs(): | |
|
||
graph_names = [] | ||
for graph_library in Config.path.graph_dir.glob("*/engine.py"): | ||
graph_names.append(str(graph_library).split("/")[-2] + "_graph") | ||
import os | ||
graph_names.append(os.path.basename(os.path.dirname(str(graph_library))) + "_graph") | ||
return list(set(graph_names)) | ||
|
||
@staticmethod | ||
def load_languages(): | ||
""" | ||
Get available languages | ||
|
||
Returns: | ||
an array of languages | ||
""" | ||
languages_list = [] | ||
|
||
for language in Config.path.locale_dir.glob("*.yaml"): | ||
languages_list.append(str(language).split("/")[-1].split(".")[0]) | ||
|
||
return list(set(languages_list)) | ||
from os.path import basename, splitext | ||
return [ | ||
splitext(basename(str(path)))[0] | ||
for path in Config.path.locale_dir.glob("*.yaml") | ||
] | ||
|
||
@staticmethod | ||
def load_modules(limit=-1, full_details=False): | ||
|
@@ -83,8 +77,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] | ||
import os | ||
library = os.path.splitext(os.path.basename(str(module_name)))[0] | ||
category = os.path.basename(os.path.dirname(str(module_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 | ||
|
@@ -145,7 +140,7 @@ def add_arguments(self): | |
engine_options.add_argument( | ||
"-v", | ||
"--verbose", | ||
action="store_true", | ||
type=int, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this related to windows compatibility? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not! |
||
dest="verbose_mode", | ||
default=Config.settings.verbose_mode, | ||
help=_("verbose_mode"), | ||
|
@@ -210,7 +205,7 @@ def add_arguments(self): | |
|
||
# Exclude Module Name | ||
exclude_modules = sorted(self.modules.keys())[:10] | ||
exclude_modules.remove("all") | ||
exclude_modules = [m for m in exclude_modules if m != "all"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change related to windows compatibility? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not! |
||
|
||
# Method Options | ||
method_options = self.add_argument_group(_("Method"), _("scan_method_options")) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import sys | ||
import os | ||
from io import StringIO | ||
|
||
import logging | ||
log = logging.getLogger(__name__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we use our own logger at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood, made the necessary changes! |
||
|
||
import yaml | ||
|
||
from nettacker.config import Config | ||
from nettacker.core.utils.common import find_args_value | ||
|
||
|
||
def application_language(): | ||
if "-L" in sys.argv: | ||
language = find_args_value("-L") or "en" | ||
|
@@ -20,52 +23,49 @@ def application_language(): | |
|
||
|
||
def load_yaml(filename): | ||
return yaml.load(StringIO(open(filename, "r").read()), Loader=yaml.FullLoader) | ||
with open(filename, "r", encoding="utf-8") as f: | ||
return yaml.safe_load(f) | ||
|
||
|
||
def get_languages(): | ||
""" | ||
Get available languages | ||
|
||
Returns: | ||
an array of languages | ||
""" | ||
languages_list = [] | ||
|
||
for language in Config.path.locale_dir.glob("*.yaml"): | ||
languages_list.append(str(language).split("/")[-1].split(".")[0]) | ||
languages_list.append(os.path.splitext(os.path.basename(str(language)))[0]) | ||
return list(set(languages_list)) | ||
|
||
|
||
class load_message: | ||
def __init__(self): | ||
self.language = application_language() | ||
self.messages = load_yaml( | ||
"{messages_path}/{language}.yaml".format( | ||
messages_path=Config.path.locale_dir, language=self.language | ||
) | ||
) | ||
log.debug(f"Selected language: {self.language}") | ||
log.debug(f"Available languages: {get_languages()}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have a .debug() in our logger There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ThankYou! for letting me know that, I'll use log.info in accordance with Nettacker logger. |
||
|
||
# Build path safely | ||
language_file = os.path.join(Config.path.locale_dir, f"{self.language}.yaml") | ||
self.messages = load_yaml(language_file) | ||
|
||
if self.language != "en": | ||
self.messages_en = load_yaml( | ||
"{messages_path}/en.yaml".format(messages_path=Config.path.locale_dir) | ||
) | ||
fallback_file = os.path.join(Config.path.locale_dir, "en.yaml") | ||
self.messages_en = load_yaml(fallback_file) | ||
|
||
for message_id in self.messages_en: | ||
if message_id not in self.messages: | ||
self.messages[message_id] = self.messages_en[message_id] | ||
|
||
|
||
message_cache = load_message().messages | ||
|
||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If unrelated to OS compatibility, please don't include them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood, made the necessary changes. |
||
message_cache = load_message().messages | ||
except (OSError, yaml.YAMLError) as exc: | ||
log.exception("Failed to load messages during initialization") | ||
message_cache = {} | ||
|
||
def messages(msg_id): | ||
""" | ||
load a message from message library with specified language | ||
Load a message from the message library with the selected language. | ||
|
||
Args: | ||
msg_id: message id | ||
msg_id: message ID | ||
|
||
Returns: | ||
the message content in the selected language if | ||
message found otherwise return message in English | ||
The message content in the selected language if found, | ||
otherwise returns the message ID itself as a fallback. | ||
""" | ||
return message_cache[str(msg_id)] | ||
return message_cache.get(str(msg_id), str(msg_id)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
+-------------------+-----------------+-------------+-------+------------------+ | ||
| date | target | module_name | port | logs | | ||
+===================+=================+=============+=======+==================+ | ||
| 2025-09-27 | scanme.nmap.org | port_scan | 80 | {'running_servic | | ||
| 02:47:03.217353 | | | | e': 'http', | | ||
| | | | | 'matched_regex': | | ||
| | | | | ['HTTP/1.1 400', | | ||
| | | | | 'Content-Type: | | ||
| | | | | ', 'Content- | | ||
| | | | | Length: 306', | | ||
| | | | | 'Server: '], 'de | | ||
| | | | | fault_service': | | ||
| | | | | 'http', | | ||
| | | | | 'ssl_flag': | | ||
| | | | | False} | | ||
+-------------------+-----------------+-------------+-------+------------------+ | ||
| 2025-09-27 | scanme.nmap.org | port_scan | 22 | {'running_servic | | ||
| 02:47:03.221971 | | | | e': 'open_port', | | ||
| | | | | 'matched_regex': | | ||
| | | | | ['22'], 'default | | ||
| | | | | _service': | | ||
| | | | | 'ssh', | | ||
| | | | | 'ssl_flag': | | ||
| | | | | False} | | ||
+-------------------+-----------------+-------------+-------+------------------+ | ||
| 2025-09-27 | scanme.nmap.org | port_scan | 9929 | {'running_servic | | ||
| 02:47:29.738556 | | | | e': 'open_port', | | ||
| | | | | 'matched_regex': | | ||
| | | | | ['9929'], 'defau | | ||
| | | | | lt_service': | | ||
| | | | | 'unknown', | | ||
| | | | | 'ssl_flag': | | ||
| | | | | False} | | ||
+-------------------+-----------------+-------------+-------+------------------+ | ||
| 2025-09-27 | scanme.nmap.org | port_scan | 31337 | {'running_servic | | ||
| 02:47:31.377412 | | | | e': 'open_port', | | ||
| | | | | 'matched_regex': | | ||
| | | | | ['31337'], 'defa | | ||
| | | | | ult_service': | | ||
| | | | | 'unknown', | | ||
| | | | | 'ssl_flag': | | ||
| | | | | False} | | ||
+-------------------+-----------------+-------------+-------+------------------+ | ||
|
||
Software Details: OWASP Nettacker version 0.4.0 [QUIN] in 2025-09-27 02:47:37 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import sys | ||
from os.path import abspath, dirname, join | ||
from pathlib import Path | ||
|
||
project_root = dirname(dirname(__file__)) | ||
nettacker_dir = abspath(join(project_root, "nettacker")) | ||
tests_dir = abspath(join(project_root, "tests")) | ||
project_root = Path(__file__).parent.parent | ||
nettacker_dir = (project_root / "nettacker").resolve() | ||
tests_dir = (project_root / "tests").resolve() | ||
|
||
sys.path.insert(0, nettacker_dir) | ||
sys.path.insert(1, tests_dir) | ||
sys.path.insert(0, str(nettacker_dir)) | ||
sys.path.insert(1, str(tests_dir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right. You're basically saying all platforms are supported (we're close but we don't want to make that statement yet). Please just add win32 to the set, should be good enough
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the advise! Honestly I don't have much knowledge about it and I'm constantly learning while doing it! I've been using AI at instances to understand the code better in order to contribute efficiently! I'll stick to path for path management and try to refactor the code using only path. I've done the necessary changes u asked for such as adding only windows compatibility and removing every other improvements not related to it.
After refactoring the code to using only path now I need to check whether it is windows compatible or not.
In order to do that, I ran a test
pytest -v
Now solving the errors and debugging!
Any suggestions for what I'm doing!