From 9d3ce807b83e9a044aa02f47f2923103a40c8c5c Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 20 Mar 2024 20:23:03 +0000 Subject: [PATCH] style: Automatic code formatting --- agent/test_agent.py | 1 + agent/test_python_architecture.py | 1 - .../windows/modules/packages/doc_antivm.py | 1 - lib/cuckoo/common/cape_utils.py | 10 ++++---- lib/cuckoo/common/integrations/mitre.py | 24 +++++++++---------- lib/cuckoo/common/integrations/vba2graph.py | 3 +-- lib/cuckoo/common/mapTTPs.py | 1 + modules/processing/behavior.py | 1 - modules/processing/parsers/CAPE/Blister.py | 2 +- modules/processing/parsers/CAPE/Hancitor.py | 1 + .../parsers/CAPE/deprecated/PredatorPain.py | 1 + .../parsers/CAPE/deprecated/_jRat.py | 1 + .../parsers/malduck/test_malduck.py | 1 - modules/reporting/elasticsearchdb.py | 2 +- modules/reporting/maec5.py | 1 - utils/process.py | 1 + web/web/headers.py | 6 ++--- 17 files changed, 29 insertions(+), 29 deletions(-) diff --git a/agent/test_agent.py b/agent/test_agent.py index 6dbfb76cccb..e58d01a4378 100644 --- a/agent/test_agent.py +++ b/agent/test_agent.py @@ -1,4 +1,5 @@ """Tests for the agent.""" + import base64 import datetime import io diff --git a/agent/test_python_architecture.py b/agent/test_python_architecture.py index f8f1e7dcd3e..9548defe628 100644 --- a/agent/test_python_architecture.py +++ b/agent/test_python_architecture.py @@ -1,6 +1,5 @@ """Ensure our version check and architecture check function as desired.""" - import sys import pytest diff --git a/analyzer/windows/modules/packages/doc_antivm.py b/analyzer/windows/modules/packages/doc_antivm.py index 7d634f44921..92df0aaa35e 100644 --- a/analyzer/windows/modules/packages/doc_antivm.py +++ b/analyzer/windows/modules/packages/doc_antivm.py @@ -8,7 +8,6 @@ class DOC_ANTIVM(Package): - """Word analysis package, with anti-VM technique prevention.""" PATHS = [ diff --git a/lib/cuckoo/common/cape_utils.py b/lib/cuckoo/common/cape_utils.py index adf6e041a39..060ae70588c 100644 --- a/lib/cuckoo/common/cape_utils.py +++ b/lib/cuckoo/common/cape_utils.py @@ -198,14 +198,14 @@ def static_config_parsers(cape_name, file_path, file_data): else: cape_configraw = cape_malware_parsers[cape_name].config(file_data) if isinstance(cape_configraw, list): - for (key, value) in cape_configraw[0].items(): + for key, value in cape_configraw[0].items(): # python3 map object returns iterator by default, not list and not serializeable in JSON. if isinstance(value, map): value = list(value) cape_config[cape_name].update({key: [value]}) parser_loaded = True elif isinstance(cape_configraw, dict): - for (key, value) in cape_configraw.items(): + for key, value in cape_configraw.items(): # python3 map object returns iterator by default, not list and not serializeable in JSON. if isinstance(value, map): value = list(value) @@ -269,10 +269,10 @@ def static_config_parsers(cape_name, file_path, file_data): malwareconfig_config = module.config # ToDo remove if isinstance(malwareconfig_config, list): - for (key, value) in malwareconfig_config[0].items(): + for key, value in malwareconfig_config[0].items(): cape_config[cape_name].update({key: [value]}) elif isinstance(malwareconfig_config, dict): - for (key, value) in malwareconfig_config.items(): + for key, value in malwareconfig_config.items(): cape_config[cape_name].update({key: [value]}) except Exception as e: if "rules" in str(e): @@ -307,7 +307,7 @@ def static_config_parsers(cape_name, file_path, file_data): tmp_config = ext.config del ext if tmp_config: - for (key, value) in tmp_config[0].items(): + for key, value in tmp_config[0].items(): cape_config[cape_name].update({key: [value]}) if not cape_config[cape_name]: diff --git a/lib/cuckoo/common/integrations/mitre.py b/lib/cuckoo/common/integrations/mitre.py index edff814281a..4f56a8e9077 100644 --- a/lib/cuckoo/common/integrations/mitre.py +++ b/lib/cuckoo/common/integrations/mitre.py @@ -61,20 +61,20 @@ def init_mitre_attck(online: bool = False): save_config=False, config_file_path=os.path.join(CUCKOO_ROOT, "data", "mitre", "config.yml"), data_path=os.path.join(CUCKOO_ROOT, "data", "mitre"), - enterprise_attck_json=config.enterprise_attck_json - if online - else os.path.join(CUCKOO_ROOT, "data", "mitre", "enterprise_attck_json.json"), + enterprise_attck_json=( + config.enterprise_attck_json if online else os.path.join(CUCKOO_ROOT, "data", "mitre", "enterprise_attck_json.json") + ), pre_attck_json=config.pre_attck_json if online else os.path.join(CUCKOO_ROOT, "data", "mitre", "pre_attck_json.json"), - mobile_attck_json=config.mobile_attck_json - if online - else os.path.join(CUCKOO_ROOT, "data", "mitre", "mobile_attck_json.json"), + mobile_attck_json=( + config.mobile_attck_json if online else os.path.join(CUCKOO_ROOT, "data", "mitre", "mobile_attck_json.json") + ), ics_attck_json=config.ics_attck_json if online else os.path.join(CUCKOO_ROOT, "data", "mitre", "ics_attck_json.json"), - nist_controls_json=config.nist_controls_json - if online - else os.path.join(CUCKOO_ROOT, "data", "mitre", "nist_controls_json.json"), - generated_nist_json=config.generated_nist_json - if online - else os.path.join(CUCKOO_ROOT, "data", "mitre", "generated_nist_json.json"), + nist_controls_json=( + config.nist_controls_json if online else os.path.join(CUCKOO_ROOT, "data", "mitre", "nist_controls_json.json") + ), + generated_nist_json=( + config.generated_nist_json if online else os.path.join(CUCKOO_ROOT, "data", "mitre", "generated_nist_json.json") + ), ) except Exception as e: log.error("Can't initialize mitre's Attck class: %s", str(e)) diff --git a/lib/cuckoo/common/integrations/vba2graph.py b/lib/cuckoo/common/integrations/vba2graph.py index a4894874857..fcaaf64708a 100644 --- a/lib/cuckoo/common/integrations/vba2graph.py +++ b/lib/cuckoo/common/integrations/vba2graph.py @@ -414,7 +414,7 @@ def vba2graph_from_vba_object(filepath): log.error(e) return False full_vba_code = "" - for (subfilename, stream_path, vba_filename, vba_code) in vba.extract_macros(): + for subfilename, stream_path, vba_filename, vba_code in vba.extract_macros(): full_vba_code += "VBA MACRO %s \n" % vba_filename full_vba_code += "- " * 39 + "\n" # Temporary workaround. Change when oletools 0.56 will be released. @@ -462,7 +462,6 @@ def handle_olevba_input(file_content): def vba2graph_gen(input_vba_content, output_folder="output", input_file_name="vba2graph", color_scheme=color_scheme): - """Generage graph from processed vba macros Args: input_vba_content (string): data generated by handle_olevba_input diff --git a/lib/cuckoo/common/mapTTPs.py b/lib/cuckoo/common/mapTTPs.py index 845cd923751..0aecf218413 100644 --- a/lib/cuckoo/common/mapTTPs.py +++ b/lib/cuckoo/common/mapTTPs.py @@ -12,6 +12,7 @@ except Exception as e: print("Can't load TTPs.json file", e) + # Read the config file def mapTTP(oldTTPs: list, mbcs: list): ttpsList = [] diff --git a/modules/processing/behavior.py b/modules/processing/behavior.py index ae4e83e8e8e..b7ad97fbca6 100644 --- a/modules/processing/behavior.py +++ b/modules/processing/behavior.py @@ -954,7 +954,6 @@ def run(self): class Anomaly: - """Anomaly detected during analysis. For example: a malware tried to remove Cuckoo's hooks. """ diff --git a/modules/processing/parsers/CAPE/Blister.py b/modules/processing/parsers/CAPE/Blister.py index c95a2e62dcd..3207644ff9f 100644 --- a/modules/processing/parsers/CAPE/Blister.py +++ b/modules/processing/parsers/CAPE/Blister.py @@ -413,7 +413,7 @@ def main(): decrypt_memory(file_path) if dir_path and os.path.isdir(dir_path): - for (dirpath, _, filenames) in os.walk(dir_path): + for dirpath, _, filenames in os.walk(dir_path): for file in filenames: decrypt_memory(os.path.join(dirpath, file)) diff --git a/modules/processing/parsers/CAPE/Hancitor.py b/modules/processing/parsers/CAPE/Hancitor.py index e94aec35c69..7cf6a679924 100644 --- a/modules/processing/parsers/CAPE/Hancitor.py +++ b/modules/processing/parsers/CAPE/Hancitor.py @@ -1,6 +1,7 @@ """ Hancitor config extractor """ + import hashlib import logging import re diff --git a/modules/processing/parsers/CAPE/deprecated/PredatorPain.py b/modules/processing/parsers/CAPE/deprecated/PredatorPain.py index 47c796bb8d2..c4a1652b73b 100644 --- a/modules/processing/parsers/CAPE/deprecated/PredatorPain.py +++ b/modules/processing/parsers/CAPE/deprecated/PredatorPain.py @@ -54,6 +54,7 @@ def decrypt_string(key, salt, coded): # except Exception: # return False + # Get a list of strings from a section def get_strings(pe, dir_type): string_list = [] diff --git a/modules/processing/parsers/CAPE/deprecated/_jRat.py b/modules/processing/parsers/CAPE/deprecated/_jRat.py index 34f47e5f57a..3d143a7310e 100644 --- a/modules/processing/parsers/CAPE/deprecated/_jRat.py +++ b/modules/processing/parsers/CAPE/deprecated/_jRat.py @@ -28,6 +28,7 @@ def run(md5, data): # Helper Functions Go Here + # This extracts the Encryption Key and Config File from the Jar and or Dropper def get_parts(data): new_zip = StringIO(data) diff --git a/modules/processing/parsers/malduck/test_malduck.py b/modules/processing/parsers/malduck/test_malduck.py index f77e66a7e76..7d19b9a4bab 100644 --- a/modules/processing/parsers/malduck/test_malduck.py +++ b/modules/processing/parsers/malduck/test_malduck.py @@ -5,7 +5,6 @@ class TEST_MALDUCK(Extractor): - """ TEST Configuration Extractor """ diff --git a/modules/reporting/elasticsearchdb.py b/modules/reporting/elasticsearchdb.py index 309bc46b046..a3da0873ba5 100644 --- a/modules/reporting/elasticsearchdb.py +++ b/modules/reporting/elasticsearchdb.py @@ -137,7 +137,7 @@ def fix_fields(self, report): self.convert_procdump_strings_to_str(report) def date_hook(self, json_dict): - for (key, value) in json_dict.items(): + for key, value in json_dict.items(): with suppress(Exception): json_dict[key] = datetime.strptime(value, "%Y-%m-%d %H:%M:%S") return json_dict diff --git a/modules/reporting/maec5.py b/modules/reporting/maec5.py index 0a932d6dffb..bb237e251c7 100644 --- a/modules/reporting/maec5.py +++ b/modules/reporting/maec5.py @@ -162,7 +162,6 @@ def _get_mime_type(cuckoo_type_desc): class MaecReport(Report): - """ Generates MAEC 5.0 report. """ diff --git a/utils/process.py b/utils/process.py index 1e5474f069e..b1087929d77 100644 --- a/utils/process.py +++ b/utils/process.py @@ -64,6 +64,7 @@ pending_task_id_map = {} original_proctitle = getproctitle() + # https://stackoverflow.com/questions/41105733/limit-ram-usage-to-python-program def memory_limit(percentage: float = 0.8): if platform.system() != "Linux": diff --git a/web/web/headers.py b/web/web/headers.py index 28dfa01ccce..b0ff02479f4 100644 --- a/web/web/headers.py +++ b/web/web/headers.py @@ -31,7 +31,7 @@ def process_response(self, request, response): response["Pragma"] = "no-cache" response["Cache-Control"] = "no-cache" response["Expires"] = "0" - response[ - "Permissions-Policy" - ] = "accelerometer=(); autoplay=(); camera=(); encrypted-media=(); fullscreen=(); geolocation=(); gyroscope=(); magnetometer=(); microphone=(); midi=(); payment=(); picture-in-picture=(); sync-xhr=(); usb=();" + response["Permissions-Policy"] = ( + "accelerometer=(); autoplay=(); camera=(); encrypted-media=(); fullscreen=(); geolocation=(); gyroscope=(); magnetometer=(); microphone=(); midi=(); payment=(); picture-in-picture=(); sync-xhr=(); usb=();" + ) return response