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