Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mssqlshell: switch back to current db after enum_impersonate #1609

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions impacket/examples/mssqlshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -232,6 +233,8 @@ def do_enum_impersonate(self, line):
self.sql.printRows()
except:
pass
gabrielg5 marked this conversation as resolved.
Show resolved Hide resolved
finally:
self.sql_query("use " + old_db)

def do_enum_logins(self, line):
try:
Expand All @@ -256,4 +259,4 @@ def emptyline(self):
pass

def do_exit(self, line):
return True
return True