Skip to content

Commit e76d4e9

Browse files
authored
Merge pull request Pennyw0rth#390 from Pennyw0rth/neff-fix-mssql_priv
Fix admin check in mssql_priv
2 parents a28c441 + 41a21ee commit e76d4e9

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

nxc/modules/mssql_priv.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def update_priv(self, user: User, exec_as=""):
219219
"""
220220
if self.is_admin_user(user.username):
221221
user.is_sysadmin = True
222+
self.context.log.debug(f"Updated {user.username} to is_sysadmin")
222223
return True
223224
user.dbowner = self.check_dbowner_privesc(exec_as)
224225
return user.dbowner
@@ -249,11 +250,15 @@ def is_admin(self, exec_as="") -> bool:
249250
self.revert_context(exec_as)
250251
is_admin = res[0][""]
251252
self.context.log.debug(f"IsAdmin Result: {is_admin}")
252-
if is_admin:
253-
self.context.log.debug("User is admin!")
254-
self.admin_privs = True
255-
return True
256-
else:
253+
try:
254+
if int(is_admin):
255+
self.context.log.debug("User is admin!")
256+
self.admin_privs = True
257+
return True
258+
else:
259+
return False
260+
except ValueError:
261+
self.logger.fail(f"Error checking if user is admin, got {is_admin} as response. Expected 0 or 1.")
257262
return False
258263

259264
def get_databases(self, exec_as="") -> list:
@@ -442,10 +447,15 @@ def is_admin_user(self, username) -> bool:
442447
"""
443448
res = self.query_and_get_output(f"SELECT IS_SRVROLEMEMBER('sysadmin', '{username}')")
444449
is_admin = res[0][""]
445-
if is_admin:
446-
self.admin_privs = True
447-
return True
448-
else:
450+
try:
451+
if is_admin != "NULL" and int(is_admin):
452+
self.admin_privs = True
453+
self.context.log.debug(f"Updated: {username} is admin!")
454+
return True
455+
else:
456+
return False
457+
except ValueError:
458+
self.context.log.fail(f"Error checking if user is admin, got {is_admin} as response. Expected 0 or 1.")
449459
return False
450460

451461
def revert_context(self, exec_as):

0 commit comments

Comments
 (0)