Skip to content

Commit

Permalink
PEP8: Do not use bare except
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Nov 25, 2024
1 parent 687e211 commit a6baa22
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion loki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions plugins/loki-plugin-wmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,41 @@ 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:
try:
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)))
Expand Down

0 comments on commit a6baa22

Please sign in to comment.