Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions nxc/protocols/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,21 @@ def handle_mssql_reply(self):
_type = f"{key['Type']:d}"
return f"(ENVCHANGE({_type}): Old Value: {record['OldValue'].decode('utf-16le')}, New Value: {record['NewValue'].decode('utf-16le')})"

def get_sid(self):
try:
query_output = self.conn.sql_query("SELECT DEFAULT_DOMAIN()")
self.logger.debug(f"get_sid: DEFAULT_DOMAIN() result: {query_output}")
domain = query_output[0][""]

raw_sid = self.conn.sql_query(f"SELECT SUSER_SID('{domain}\\Domain Admins')")[0][""]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick comment;

  • it only work for english system
  • what if it's local (no domain join)

self.logger.debug(f"get_sid: raw SID bytes: {raw_sid}")
domain_sid = SID(bytes.fromhex(raw_sid.decode())).formatCanonical()
domain_sid = "-".join(domain_sid.split("-")[:-1])
self.logger.highlight(f"Domain SID {domain_sid}")
except Exception as e:
self.logger.fail(f"Failed to get domain SID: {e}")
self.logger.debug("get_sid error", exc_info=True)

def rid_brute(self, max_rid=None):
entries = []
if not max_rid:
Expand Down
1 change: 1 addition & 0 deletions nxc/protocols/mssql/proto_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ def proto_args(parser, parents):

mapping_enum_group = mssql_parser.add_argument_group("Mapping/Enumeration")
mapping_enum_group.add_argument("--rid-brute", nargs="?", type=int, const=4000, metavar="MAX_RID", help="enumerate users by bruteforcing RIDs")
mapping_enum_group.add_argument("--get-sid", action="store_true", help="Get domain sid")
return parser
1 change: 1 addition & 0 deletions tests/e2e_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ netexec winrm TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M aws-cr
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # Need a space at the end for kerb regex
netexec {DNS} mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # Need a space at the end for kerb regex
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --rid-brute
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --get-sid
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --database
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --sam
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --lsa
Expand Down