From b6081a72d598af77d195e059eb117c7459d3d3a4 Mon Sep 17 00:00:00 2001 From: exploide Date: Wed, 13 Sep 2023 18:55:38 +0200 Subject: [PATCH] mssqlshell: ensure enum_impersonate does not permanently change the current DB --- impacket/examples/mssqlshell.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/impacket/examples/mssqlshell.py b/impacket/examples/mssqlshell.py index add152fb11..5c4784cd98 100644 --- a/impacket/examples/mssqlshell.py +++ b/impacket/examples/mssqlshell.py @@ -38,7 +38,7 @@ def do_help(self, line): disable_xp_cmdshell - you know what it means enum_db - enum databases enum_links - enum linked servers - enum_impersonate - check logins that can be impersonate + enum_impersonate - check logins that can be impersonated enum_logins - enum login users enum_users - enum current db users enum_owner - enum db owner @@ -203,6 +203,7 @@ def do_enum_owner(self, line): pass def do_enum_impersonate(self, line): + old_db = self.sql.currentDB try: self.sql_query("select name from sys.databases") result = [] @@ -232,6 +233,8 @@ def do_enum_impersonate(self, line): self.sql.printRows() except: pass + finally: + self.sql_query("use " + old_db) def do_enum_logins(self, line): try: @@ -256,4 +259,4 @@ def emptyline(self): pass def do_exit(self, line): - return True \ No newline at end of file + return True