From c6d5e9950af75fa974dbc72410eb49369cc8e6d1 Mon Sep 17 00:00:00 2001 From: David B <44925796+TH3xACE@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:22:12 +0100 Subject: [PATCH 1/2] Update common_func.py --- web/reNgine/common_func.py | 56 ++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/web/reNgine/common_func.py b/web/reNgine/common_func.py index 2c7bdbd8..ae147ced 100644 --- a/web/reNgine/common_func.py +++ b/web/reNgine/common_func.py @@ -34,38 +34,36 @@ DISCORD_WEBHOOKS_CACHE = redis.Redis.from_url(CELERY_BROKER_URL) # EngineType utils # #------------------# def dump_custom_scan_engines(results_dir): - """Dump custom scan engines to YAML files. - - Args: - results_dir (str): Results directory (will be created if non-existent). - """ - custom_engines = EngineType.objects.filter(default_engine=False) - if not os.path.exists(results_dir): - os.makedirs(results_dir, exist_ok=True) - for engine in custom_engines: - with open(f'{results_dir}/{engine.engine_name}.yaml', 'w') as f: - config = yaml.safe_load(engine.yaml_configuration) - yaml.dump(config, f, indent=4) + """Dump custom scan engines to YAML files. + Args: + results_dir (str): Results directory (will be created if non-existent). + """ + custom_engines = EngineType.objects.filter(default_engine=False) + if not os.path.exists(results_dir): + os.makedirs(results_dir, exist_ok=True) + for engine in custom_engines: + with open(os.path.join(results_dir, f"{engine.engine_name}.yaml"), 'w') as f: + f.write(engine.yaml_configuration) def load_custom_scan_engines(results_dir): - """Load custom scan engines from YAML files. The filename without .yaml will - be used as the engine name. + """Load custom scan engines from YAML files. The filename without .yaml will + be used as the engine name. + Args: + results_dir (str): Results directory containing engines configs. + """ + config_paths = [ + f for f in os.listdir(results_dir) + if os.path.isfile(os.path.join(results_dir, f)) and f.endswith('.yaml') + ] + for path in config_paths: + engine_name = os.path.splitext(os.path.basename(path))[0] + full_path = os.path.join(results_dir, path) + with open(full_path, 'r') as f: + yaml_configuration = f.read() - Args: - results_dir (str): Results directory containing engines configs. - """ - config_paths = [ - f for f in os.listdir(results_dir) - if os.path.isfile(os.path.join(results_dir, f)) - ] - for path in config_paths: - engine_name = path.replace('.yaml', '').split('/')[-1] - full_path = os.path.join(results_dir, path) - with open(full_path, 'r') as f: - yaml_configuration = yaml.safe_load(f) - engine, _ = EngineType.objects.get_or_create(engine_name=engine_name) - engine.yaml_configuration = yaml.dump(yaml_configuration) - engine.save() + engine, _ = EngineType.objects.get_or_create(engine_name=engine_name) + engine.yaml_configuration = yaml_configuration + engine.save() #--------------------------------# From e372f7af3d0de6dcbef08bfacd58e2ce2d5f938b Mon Sep 17 00:00:00 2001 From: David B <44925796+TH3xACE@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:00:55 +0100 Subject: [PATCH 2/2] Bug Correction : custom scan engine dump and load python3 manage.py loadcustomengines python3 manage.py dumpcustomengines When using these functions the dumped/loaded custom engines format is not preserved. The new code now dumped the custom engines in the right format and when loading also. --- web/reNgine/common_func.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/reNgine/common_func.py b/web/reNgine/common_func.py index ae147ced..2ca61c0a 100644 --- a/web/reNgine/common_func.py +++ b/web/reNgine/common_func.py @@ -35,6 +35,7 @@ DISCORD_WEBHOOKS_CACHE = redis.Redis.from_url(CELERY_BROKER_URL) #------------------# def dump_custom_scan_engines(results_dir): """Dump custom scan engines to YAML files. + Args: results_dir (str): Results directory (will be created if non-existent). """ @@ -48,6 +49,7 @@ def dump_custom_scan_engines(results_dir): def load_custom_scan_engines(results_dir): """Load custom scan engines from YAML files. The filename without .yaml will be used as the engine name. + Args: results_dir (str): Results directory containing engines configs. """