Skip to content

Commit 35c39c1

Browse files
authored
Merge pull request Pennyw0rth#681 from Pennyw0rth/neff-fix-db-schema
Add a check if the database scheme contains the unique attribute
2 parents 413e5eb + f335cd7 commit 35c39c1

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

nxc/protocols/smb/database.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ def reflect_tables(self):
177177
self.DpapiBackupkey = Table("dpapi_backupkey", self.metadata, autoload_with=self.db_engine)
178178
self.ConfChecksTable = Table("conf_checks", self.metadata, autoload_with=self.db_engine)
179179
self.ConfChecksResultsTable = Table("conf_checks_results", self.metadata, autoload_with=self.db_engine)
180+
181+
# Check if Database Schema is correct, due to hanging issues reported on discord introduced by https://github.com/Pennyw0rth/NetExec/pull/658
182+
from sqlalchemy.schema import UniqueConstraint
183+
ip_is_unique = False
184+
for constraint in self.HostsTable.constraints:
185+
if isinstance(constraint, UniqueConstraint) and constraint.columns[0].name == "ip":
186+
ip_is_unique = True
187+
break
188+
if not ip_is_unique:
189+
raise NoSuchTableError("ip is not unique in hosts table")
180190
except (NoInspectionAvailable, NoSuchTableError):
181191
print(
182192
f"""

0 commit comments

Comments
 (0)