Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit dc95b51

Browse files
author
mpgn
authored
Merge pull request #419 from Dliv3/master
Fix mssql execute command error
2 parents fc04fd9 + 50bebac commit dc95b51

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

cme/helpers/powershell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_ps_script(path):
1919
return os.path.join(os.path.dirname(cme.__file__), 'data', path)
2020

2121
def encode_ps_command(command):
22-
return b64encode(command.encode('UTF-16LE'))
22+
return b64encode(command.encode('UTF-16LE')).decode()
2323

2424
def is_powershell_installed():
2525
if which('powershell'):

cme/protocols/mssql.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def enum_host_info(self):
8383
try:
8484
smb_conn.login('', '')
8585
except SessionError as e:
86-
if "STATUS_ACCESS_DENIED" in e.message:
86+
if "STATUS_ACCESS_DENIED" in e.getErrorString():
8787
pass
8888

8989
self.domain = smb_conn.getServerDNSDomainName()
@@ -135,20 +135,12 @@ def create_conn_obj(self):
135135

136136
def check_if_admin(self, auth):
137137
try:
138-
# I'm pretty sure there has to be a better way of doing this.
139-
# Currently we are just searching for our user in the sysadmin group
140-
141-
self.conn.sql_query("EXEC sp_helpsrvrolemember 'sysadmin'")
138+
self.conn.sql_query("SELECT IS_SRVROLEMEMBER('sysadmin')")
142139
self.conn.printRows()
143140
query_output = self.conn._MSSQL__rowsPrinter.getMessage()
144-
logging.debug("'sysadmin' group members:\n{}".format(query_output))
145-
146-
if not auth:
147-
search_string = '{}\\{}'.format(self.domain, self.username)
148-
else:
149-
search_string = self.username
141+
query_output = query_output.strip("\n-")
150142

151-
if re.search(r'\b'+search_string+'\W', query_output):
143+
if int(query_output):
152144
self.admin_privs = True
153145
else:
154146
return False

0 commit comments

Comments
 (0)