From af2c05bdb89589c855c9c42a3a8940e935c2eddc Mon Sep 17 00:00:00 2001 From: rusal Date: Sun, 9 Jul 2023 12:12:22 -0400 Subject: [PATCH 1/2] Correct module name --- api/engine.py | 2 +- core/parse.py | 2 +- core/readme.md | 22 ++++++++++------------ core/{scan_targers.py => scan_targets.py} | 0 core/targets.py | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) rename core/{scan_targers.py => scan_targets.py} (100%) diff --git a/api/engine.py b/api/engine.py index 095307450..ca183bb89 100644 --- a/api/engine.py +++ b/api/engine.py @@ -39,7 +39,7 @@ from database.db import search_logs from database.db import logs_to_report_html from config import nettacker_global_config -from core.scan_targers import start_scan_processes +from core.scan_targets import start_scan_processes from core.args_loader import check_all_required app = Flask( diff --git a/core/parse.py b/core/parse.py index 78a4d7adc..b8776834e 100644 --- a/core/parse.py +++ b/core/parse.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- -from core.scan_targers import start_scan_processes +from core.scan_targets import start_scan_processes from core.alert import info from core.alert import write from core.alert import messages diff --git a/core/readme.md b/core/readme.md index c903f55db..b7ea3fa22 100644 --- a/core/readme.md +++ b/core/readme.md @@ -3,20 +3,18 @@ OWASP Nettacker core functions OWASP Nettacker core functions are stored in here. -* `die.py` exit functions -* `time.py` time functions * `alert.py` user alerts and printing functions * `args_loader.py` ARGV commands and apply rules -* `attack.py` start new attacks and multi-processing managements -* `color.py` color founds for windows and linux/mac. +* `color.py` color founds for windows and linux/mac * `compatible.py` compatibility functions -* `config.py` user configs (could be modify by user) -* `config_builder.py` core static configs (same as user configs but should not be change by users) -* `get_input.py` get inputs from users functions +* `die.py` exit functions +* `graph.py` graph representation * `ip.py` IPv4 and IPv6 functions -* `load_modules` load modules, requirements, paths functions -* `log.py` log the scans and generate reports +* `load_modules.py` load modules, requirements, paths functions +* `messages.py` class messages * `parse.py` parse the ARGV and pass it -* `targets.py` process, calculate and count targets -* `update.py` updates functions of the framework -* `wizard.py` wizard mode for the framework \ No newline at end of file +* `scan_targets.py` start new attacks and multi-processing managements +* `socks_proxy.py` use SOCKS5 proxy +* `targets.py` process, calculate and count targets +* `time.py` time functions +* `utility.py` support functions \ No newline at end of file diff --git a/core/scan_targers.py b/core/scan_targets.py similarity index 100% rename from core/scan_targers.py rename to core/scan_targets.py diff --git a/core/targets.py b/core/targets.py index 67f19169a..b7e568628 100644 --- a/core/targets.py +++ b/core/targets.py @@ -32,7 +32,7 @@ def expand_targets(options, scan_unique_id): Returns: a generator """ - from core.scan_targers import multi_processor + from core.scan_targets import multi_processor targets = [] for target in options.targets: if '://' in target: From f93f8613a3ba273da0113f63a3abcc04544fd133 Mon Sep 17 00:00:00 2001 From: rusal Date: Sat, 15 Jul 2023 08:38:12 -0400 Subject: [PATCH 2/2] Disconnect Handling to SQL --- .gitignore | 1 + database/db.py | 57 +++++++++++++++++++++++------------------------- requirements.txt | 2 +- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 20ab7121e..2b13d4e38 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ #ignore IDE settings *.idea* +*.vscode* #setup build/* diff --git a/database/db.py b/database/db.py index fa771d67c..1d643a981 100644 --- a/database/db.py +++ b/database/db.py @@ -25,15 +25,15 @@ def db_inputs(connection_type): """ - a function to determine the type of database the user wants to work with and - selects the corresponding connection to the db + a function to determine the type of database the user wants to work with and + selects the corresponding connection to the db - Args: - connection_type: type of db we are working with + Args: + connection_type: type of db we are working with - Returns: - corresponding command to connect to the db - """ + Returns: + corresponding command to connect to the db + """ return { "postgres": 'postgres+psycopg2://{0}:{1}@{2}:{3}/{4}'.format(USER, PASSWORD, HOST, PORT, DATABASE), "mysql": 'mysql://{0}:{1}@{2}:{3}/{4}'.format(USER, PASSWORD, HOST, PORT, DATABASE), @@ -43,25 +43,22 @@ def db_inputs(connection_type): def create_connection(): """ - a function to create connections to db, it retries 100 times if connection returned an error + a function to create connections to db with pessimistic approach Returns: connection if success otherwise False """ try: - for _ in range(0, 100): - try: - db_engine = create_engine( - db_inputs(DB), - connect_args={ - 'check_same_thread': False - } - ) - Session = sessionmaker(bind=db_engine) - session = Session() - return session - except Exception: - time.sleep(0.1) + db_engine = create_engine( + db_inputs(DB), + connect_args={ + 'check_same_thread': False + }, + pool_pre_ping=True + ) + Session = sessionmaker(bind=db_engine) + session = Session() + return session except Exception: warn(messages("database_connect_fail")) return False @@ -196,17 +193,17 @@ def submit_temp_logs_to_db(log): def find_temp_events(target, module_name, scan_unique_id, event_name): """ - select all events by scan_unique id, target, module_name + select all events by scan_unique id, target, module_name - Args: - target: target - module_name: module name - scan_unique_id: unique scan identifier - event_name: event_name + Args: + target: target + module_name: module name + scan_unique_id: unique scan identifier + event_name: event_name - Returns: - an array with JSON events or an empty array - """ + Returns: + an array with JSON events or an empty array + """ session = create_connection() try: for _ in range(1, 100): diff --git a/requirements.txt b/requirements.txt index 9f0763d4e..e8d126f99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ texttable==1.6.7 PySocks==1.7.1 # library_name=socks # module name is not equal to socks name; this is required to be checked on startup pyOpenSSL==23.2.0 # library_name=OpenSSL flask==2.3.2 -SQLAlchemy>=1.3.0 # library_name=sqlalchemy +SQLAlchemy>=1.4.43 # library_name=sqlalchemy py3DNS==3.2.1 # library_name=DNS numpy==1.24.3 terminable_thread==0.7.1