Skip to content

Commit 0b56dde

Browse files
committed
[SMB] WMI Quqery: Bug fix of while condition
Signed-off-by: XiaoliChan <30458572+XiaoliChan@users.noreply.github.com>
1 parent 28e5fa9 commit 0b56dde

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

nxc/modules/wcc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ def check_laps(self):
399399
return success, reasons
400400

401401
def check_last_successful_update(self):
402-
records = self.connection.wmi_query(wmi_query="Select TimeGenerated FROM Win32_ReliabilityRecords Where EventIdentifier=19", namespace="root\\cimv2")
403-
if isinstance(records, bool) or len(records) == 0:
402+
records = self.connection.wmi_query(wql="Select TimeGenerated FROM Win32_ReliabilityRecords Where EventIdentifier=19", namespace="root\\cimv2")
403+
if not records:
404404
return False, ["No update found"]
405405
most_recent_update_date = records[0]["TimeGenerated"]["value"]
406406
most_recent_update_date = most_recent_update_date.split(".")[0]

nxc/protocols/smb.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,10 +1718,10 @@ def pass_pol(self):
17181718
return PassPolDump(self).dump()
17191719

17201720
@requires_admin
1721-
def wmi_query(self, wmi_query=None, namespace=None, callback_func=None):
1721+
def wmi_query(self, wql=None, namespace=None, callback_func=None):
17221722
records = []
1723-
if not wmi_query:
1724-
wmi_query = self.args.wmi_query.strip("\n")
1723+
if not wql:
1724+
wql = self.args.wmi_query.strip("\n")
17251725

17261726
if not namespace:
17271727
namespace = self.args.wmi_namespace
@@ -1742,31 +1742,29 @@ def wmi_query(self, wmi_query=None, namespace=None, callback_func=None):
17421742
iWbemLevel1Login = IWbemLevel1Login(iInterface)
17431743
iWbemServices = iWbemLevel1Login.NTLMLogin(namespace, NULL, NULL)
17441744
iWbemLevel1Login.RemRelease()
1745-
iEnumWbemClassObject = iWbemServices.ExecQuery(wmi_query)
1745+
iEnumWbemClassObject = iWbemServices.ExecQuery(wql)
17461746
except Exception as e:
17471747
self.logger.fail(f"Execute WQL error: {e}")
17481748
if "iWbemLevel1Login" in locals():
17491749
dcom.disconnect()
17501750
else:
1751-
self.logger.info(f"Executing WQL syntax: {wmi_query}")
1752-
while True:
1753-
try:
1754-
if not callback_func:
1751+
self.logger.info(f"Executing WQL syntax: {wql}")
1752+
try:
1753+
if not callback_func:
1754+
while True:
17551755
wmi_results = iEnumWbemClassObject.Next(0xFFFFFFFF, 1)[0]
17561756
record = wmi_results.getProperties()
17571757
records.append(record)
17581758
for k, v in record.items():
17591759
if k != "TimeGenerated": # from the wcc module, but this is a small hack to get it to stop spamming - TODO: add in method to disable output for this function
17601760
self.logger.highlight(f"{k} => {v['value']}")
1761-
else:
1762-
callback_func(iEnumWbemClassObject, records)
1763-
except Exception as e:
1764-
if str(e).find("S_FALSE") < 0:
1765-
raise e
1766-
else:
1767-
break
1761+
else:
1762+
callback_func(iEnumWbemClassObject, records)
1763+
except Exception as e:
1764+
if str(e).find("S_FALSE") < 0:
1765+
self.logger.debug(e)
17681766
dcom.disconnect()
1769-
return records if records else False
1767+
return records
17701768

17711769
def spider(
17721770
self,

0 commit comments

Comments
 (0)