Skip to content

Commit a6baa22

Browse files
committed
PEP8: Do not use bare except
1 parent 687e211 commit a6baa22

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

.github/workflows/lint_python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- uses: actions/setup-python@v5
99
- run: pip install --upgrade pip setuptools wheel
1010
- run: pip install codespell mypy pytest ruff safety
11-
- run: ruff check --output-format=github --ignore=E501,E701,E713,E722,F401,F403,F405,F841 --line-length=263 .
11+
- run: ruff check --output-format=github --ignore=E701,F401,F403,F405,F841 --line-length=263
1212
- run: ruff format || true
1313
- run: codespell --ignore-words-list="datas" --skip="./.git/*"
1414
- run: pip install -r requirements.txt

lib/helpers.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,23 @@ def is_ip(string):
3232
if netaddr.valid_ipv6(string):
3333
return True
3434
return False
35-
except:
35+
except Exception:
3636
traceback.print_exc()
3737
return False
3838

3939

4040
def is_cidr(string):
4141
try:
42-
if netaddr.IPNetwork(string) and "/" in string:
43-
return True
44-
return False
45-
except:
42+
return netaddr.IPNetwork(string) and "/" in string
43+
except Exception:
4644
return False
4745

4846

4947
def ip_in_net(ip, network):
5048
try:
5149
# print "Checking if ip %s is in network %s" % (ip, network)
52-
if netaddr.IPAddress(ip) in netaddr.IPNetwork(network):
53-
return True
54-
return False
55-
except:
50+
return netaddr.IPAddress(ip) in netaddr.IPNetwork(network)
51+
except Exception:
5652
return False
5753

5854

loki.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def get_string_matches(self, strings):
565565
string_value = string_value[:140] + " ... (truncated)"
566566
matching_strings.append("{0}: '{1}'".format(string.identifier, string_value))
567567
return matching_strings
568-
except:
568+
except Exception:
569569
traceback.print_exc()
570570

571571
def check_svchost_owner(self, owner):

plugins/loki-plugin-wmi.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,41 @@ def ScanWMI():
3030
lActiveScriptEventConsumer = []
3131
try:
3232
leventFilter = oWMI.__eventFilter()
33-
except:
33+
except Exception:
3434
logger.log("WARNING", "WMIScan", 'Error retrieving __eventFilter')
3535
try:
3636
lFilterToConsumerBinding = oWMI.__FilterToConsumerBinding()
37-
except:
37+
except Exception:
3838
logger.log("WARNING", "WMIScan", 'Error retrieving __FilterToConsumerBinding')
3939
try:
4040
lCommandLineEventConsumer = oWMI.CommandLineEventConsumer()
41-
except:
41+
except Exception:
4242
logger.log("WARNING", "WMIScan", 'Error retrieving CommandLineEventConsumer')
4343
try:
4444
lActiveScriptEventConsumer = oWMI.ActiveScriptEventConsumer()
45-
except:
45+
except Exception:
4646
logger.log("WARNING", "WMIScan", 'Error retrieving ActiveScriptEventConsumer')
4747

4848
for eventFilter in leventFilter:
4949
try:
5050
hashEntry = hashlib.md5(str(eventFilter)).hexdigest()
5151
if hashEntry not in knownHashes:
5252
logger.log("WARNING", "WMIScan", 'CLASS: __eventFilter MD5: %s NAME: %s QUERY: %s' % (hashEntry, eventFilter.wmi_property('Name').value, eventFilter.wmi_property('Query').value))
53-
except:
53+
except Exception:
5454
logger.log("INFO", "WMIScan", repr(str(eventFilter)))
5555
for FilterToConsumerBinding in lFilterToConsumerBinding:
5656
try:
5757
hashEntry = hashlib.md5(str(FilterToConsumerBinding)).hexdigest()
5858
if hashEntry not in knownHashes:
5959
logger.log("WARNING", "WMIScan", 'CLASS: __FilterToConsumerBinding MD5: %s CONSUMER: %s FILTER: %s' % (hashEntry, FilterToConsumerBinding.wmi_property('Consumer').value, FilterToConsumerBinding.wmi_property('Filter').value))
60-
except:
60+
except Exception:
6161
logger.log("INFO", "WMIScan", repr(str(FilterToConsumerBinding)))
6262
for CommandLineEventConsumer in lCommandLineEventConsumer:
6363
try:
6464
hashEntry = hashlib.md5(str(CommandLineEventConsumer)).hexdigest()
6565
if hashEntry not in knownHashes:
6666
logger.log("WARNING", "WMIScan", 'CLASS: CommandLineEventConsumer MD5: %s NAME: %s COMMANDLINETEMPLATE: %s' % (hashEntry, CommandLineEventConsumer.wmi_property('Name').value, CommandLineEventConsumer.wmi_property('CommandLineTemplate').value))
67-
except:
67+
except Exception:
6868
logger.log("INFO", "WMIScan", repr(str(CommandLineEventConsumer)))
6969
for ActiveScriptEventConsumer in lActiveScriptEventConsumer:
7070
logger.log("INFO", "WMIScan", repr(str(ActiveScriptEventConsumer)))

0 commit comments

Comments
 (0)