diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 2c9ed500..da15cff6 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -8,7 +8,7 @@ jobs: - uses: actions/setup-python@v5 - run: pip install --upgrade pip setuptools wheel - run: pip install codespell mypy pytest ruff safety - - run: ruff check --output-format=github --ignore=E501,E701,E713,E722,F401,F403,F405,F841 --line-length=263 . + - run: ruff check --output-format=github --ignore=E701,F401,F403,F405,F841 --line-length=263 - run: ruff format || true - run: codespell --ignore-words-list="datas" --skip="./.git/*" - run: pip install -r requirements.txt diff --git a/lib/helpers.py b/lib/helpers.py index da23a40c..c72bb192 100644 --- a/lib/helpers.py +++ b/lib/helpers.py @@ -32,27 +32,23 @@ def is_ip(string): if netaddr.valid_ipv6(string): return True return False - except: + except Exception: traceback.print_exc() return False def is_cidr(string): try: - if netaddr.IPNetwork(string) and "/" in string: - return True - return False - except: + return netaddr.IPNetwork(string) and "/" in string + except Exception: return False def ip_in_net(ip, network): try: # print "Checking if ip %s is in network %s" % (ip, network) - if netaddr.IPAddress(ip) in netaddr.IPNetwork(network): - return True - return False - except: + return netaddr.IPAddress(ip) in netaddr.IPNetwork(network) + except Exception: return False diff --git a/loki.py b/loki.py index c22f8d3c..b7b97752 100644 --- a/loki.py +++ b/loki.py @@ -565,7 +565,7 @@ def get_string_matches(self, strings): string_value = string_value[:140] + " ... (truncated)" matching_strings.append("{0}: '{1}'".format(string.identifier, string_value)) return matching_strings - except: + except Exception: traceback.print_exc() def check_svchost_owner(self, owner): diff --git a/plugins/loki-plugin-wmi.py b/plugins/loki-plugin-wmi.py index 31fa9121..54b61471 100644 --- a/plugins/loki-plugin-wmi.py +++ b/plugins/loki-plugin-wmi.py @@ -30,19 +30,19 @@ def ScanWMI(): lActiveScriptEventConsumer = [] try: leventFilter = oWMI.__eventFilter() - except: + except Exception: logger.log("WARNING", "WMIScan", 'Error retrieving __eventFilter') try: lFilterToConsumerBinding = oWMI.__FilterToConsumerBinding() - except: + except Exception: logger.log("WARNING", "WMIScan", 'Error retrieving __FilterToConsumerBinding') try: lCommandLineEventConsumer = oWMI.CommandLineEventConsumer() - except: + except Exception: logger.log("WARNING", "WMIScan", 'Error retrieving CommandLineEventConsumer') try: lActiveScriptEventConsumer = oWMI.ActiveScriptEventConsumer() - except: + except Exception: logger.log("WARNING", "WMIScan", 'Error retrieving ActiveScriptEventConsumer') for eventFilter in leventFilter: @@ -50,21 +50,21 @@ def ScanWMI(): hashEntry = hashlib.md5(str(eventFilter)).hexdigest() if hashEntry not in knownHashes: logger.log("WARNING", "WMIScan", 'CLASS: __eventFilter MD5: %s NAME: %s QUERY: %s' % (hashEntry, eventFilter.wmi_property('Name').value, eventFilter.wmi_property('Query').value)) - except: + except Exception: logger.log("INFO", "WMIScan", repr(str(eventFilter))) for FilterToConsumerBinding in lFilterToConsumerBinding: try: hashEntry = hashlib.md5(str(FilterToConsumerBinding)).hexdigest() if hashEntry not in knownHashes: logger.log("WARNING", "WMIScan", 'CLASS: __FilterToConsumerBinding MD5: %s CONSUMER: %s FILTER: %s' % (hashEntry, FilterToConsumerBinding.wmi_property('Consumer').value, FilterToConsumerBinding.wmi_property('Filter').value)) - except: + except Exception: logger.log("INFO", "WMIScan", repr(str(FilterToConsumerBinding))) for CommandLineEventConsumer in lCommandLineEventConsumer: try: hashEntry = hashlib.md5(str(CommandLineEventConsumer)).hexdigest() if hashEntry not in knownHashes: logger.log("WARNING", "WMIScan", 'CLASS: CommandLineEventConsumer MD5: %s NAME: %s COMMANDLINETEMPLATE: %s' % (hashEntry, CommandLineEventConsumer.wmi_property('Name').value, CommandLineEventConsumer.wmi_property('CommandLineTemplate').value)) - except: + except Exception: logger.log("INFO", "WMIScan", repr(str(CommandLineEventConsumer))) for ActiveScriptEventConsumer in lActiveScriptEventConsumer: logger.log("INFO", "WMIScan", repr(str(ActiveScriptEventConsumer)))