From 14d5bf4a6b7ba7cce2ba84cb5d49c7f1b0b80625 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Sun, 15 Nov 2026 12:02:13 +0100 Subject: [PATCH 1/6] Add share type --- nxc/protocols/smb.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/nxc/protocols/smb.py b/nxc/protocols/smb.py index 6e5f70dece..9a745312f1 100755 --- a/nxc/protocols/smb.py +++ b/nxc/protocols/smb.py @@ -28,7 +28,11 @@ ) from impacket.nmb import NetBIOSError, NetBIOSTimeout from impacket.dcerpc.v5 import lsat, lsad, scmr, rrp, srvs, wkst -from impacket.dcerpc.v5.srvs import STYPE_DISKTREE, STYPE_MASK +from impacket.dcerpc.v5.srvs import ( + STYPE_DISKTREE, STYPE_PRINTQ, STYPE_DEVICE, STYPE_IPC, + STYPE_CLUSTER_FS, STYPE_CLUSTER_SOFS, STYPE_CLUSTER_DFS, + STYPE_SPECIAL, STYPE_TEMPORARY, STYPE_MASK, +) from impacket.dcerpc.v5.rpcrt import DCERPCException from impacket.dcerpc.v5.transport import DCERPCTransportFactory from impacket.dcerpc.v5.rpcrt import RPC_C_AUTHN_GSS_NEGOTIATE @@ -1616,15 +1620,25 @@ def shares(self): self.logger.debug(f"Skipping excluded share: {share_name}") continue - # Mask off STYPE_SPECIAL/STYPE_TEMPORARY flags; only the base type - # (DISKTREE/PRINTQ/DEVICE/IPC) determines whether write checks apply. + # Keep the base type for write checks and display cluster types and the temporary flag. share_remark = share["shi1_remark"].rstrip("\x00") share_info = { "name": share_name, "remark": share_remark, "type": share["shi1_type"] & STYPE_MASK, + "type_name": { + STYPE_DISKTREE: "DISKTREE", + STYPE_PRINTQ: "PRINTQ", + STYPE_DEVICE: "DEVICE", + STYPE_IPC: "IPC", + STYPE_CLUSTER_FS: "CLUSTER_FS", + STYPE_CLUSTER_SOFS: "CLUSTER_SOFS", + STYPE_CLUSTER_DFS: "CLUSTER_DFS", + }.get(share["shi1_type"] & ~(STYPE_SPECIAL | STYPE_TEMPORARY), "UNKNOWN"), "access": [], } + if share["shi1_type"] & STYPE_TEMPORARY: + share_info["type_name"] += ",TEMPORARY" read = False write = False try: @@ -1750,8 +1764,8 @@ def shares(self): self.logger.display("[REMOVED] Use the --shares read,write options instead.") self.logger.display("Enumerated shares") - self.logger.highlight(f"{'Share':<15} {'Permissions':<22} {'Remark'}") - self.logger.highlight(f"{'-----':<15} {'-----------':<22} {'------'}") + self.logger.highlight(f"{'Share':<15} {'Permissions':<15} {'Type':<10} {'Remark'}") + self.logger.highlight(f"{'-----':<15} {'-----------':<15} {'----':<10} {'------'}") for share in permissions: name = share["name"] @@ -1759,7 +1773,7 @@ def shares(self): perms = ",".join(share["access"]) if self.args.shares and self.args.shares.lower() not in perms.lower(): continue - self.logger.highlight(f"{name:<15} {perms:<22} {remark}") + self.logger.highlight(f"{name:<15} {perms:<15} {share['type_name']:<10} {remark}") return permissions def dir(self): From b24f9b504dba9043c2b5251f5d16b36fb9861b3a Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Sun, 15 Nov 2026 23:32:00 +0100 Subject: [PATCH 2/6] Add share type to nxcdb --- nxc/nxcdb.py | 7 ++++--- nxc/protocols/smb/database.py | 25 +++++++++++++------------ nxc/protocols/smb/db_navigator.py | 7 ++++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/nxc/nxcdb.py b/nxc/nxcdb.py index 34ec1676c8..c7518cfee1 100644 --- a/nxc/nxcdb.py +++ b/nxc/nxcdb.py @@ -202,11 +202,11 @@ def do_export(self, line): return shares = self.db.get_shares() - csv_header = ("id", "host", "userid", "name", "remark", "read", "write") + csv_header = ("id", "host", "userid", "name", "read", "write", "type", "remark") filename = line[2] if line[1].lower() == "simple": - write_csv(filename, csv_header, shares) + write_csv(filename, csv_header, [(share.id, share.hostid, share.userid, share.name, share.read, share.write, share.type, share.remark) for share in shares]) print("[+] shares exported") # Detailed view gets hostname, usernames, and true false statement elif line[1].lower() == "detailed": @@ -220,9 +220,10 @@ def do_export(self, line): share_host, # hosts f"{user[1]}\\{user[2]}", # userID share[3], # name - share[4], # remark bool(share[5]), # read bool(share[6]), # write + share.type, + share[4], # remark ) formatted_shares.append(entry) write_csv(filename, csv_header, formatted_shares) diff --git a/nxc/protocols/smb/database.py b/nxc/protocols/smb/database.py index 665aa2565f..6edfdc0563 100755 --- a/nxc/protocols/smb/database.py +++ b/nxc/protocols/smb/database.py @@ -142,6 +142,7 @@ class Share(BaseTable): remark = Column(String) read = Column(Boolean) write = Column(Boolean) + type = Column(String) __table_args__ = ( PrimaryKeyConstraint("id"), @@ -655,19 +656,19 @@ def is_share_valid(self, share_id): nxc_logger.debug(f"is_share_valid(shareID={share_id}) => {len(results) > 0}") return len(results) > 0 - def add_share(self, host_id, user_id, name, remark, read, write): - share_data = { - "hostid": host_id, - "userid": user_id, - "name": name, - "remark": remark, - "read": read, - "write": write, - } + def add_share(self, host_id, user_id, name, remark, read, write, share_type): self.db_execute( - Insert(self.SharesTable).on_conflict_do_nothing(), # .returning(self.SharesTable.c.id), - share_data, - ) # .scalar_one() + Insert(self.SharesTable).on_conflict_do_update(index_elements=["hostid", "userid", "name"], set_={"type": share_type}), + { + "hostid": host_id, + "userid": user_id, + "name": name, + "remark": remark, + "read": read, + "write": write, + "type": share_type, + }, + ) def get_shares(self, filter_term=None): if self.is_share_valid(filter_term): diff --git a/nxc/protocols/smb/db_navigator.py b/nxc/protocols/smb/db_navigator.py index 404c8538b7..f0acb7a095 100644 --- a/nxc/protocols/smb/db_navigator.py +++ b/nxc/protocols/smb/db_navigator.py @@ -117,7 +117,7 @@ def display_hosts(self, hosts): print_table(data, title="Hosts") def display_shares(self, shares): - data = [["ShareID", "host", "Name", "Remark", "Read Access", "Write Access"]] + data = [["ShareID", "host", "Name", "Read Access", "Write Access", "Type", "Remark"]] for share in shares: share_id = share[0] @@ -132,9 +132,10 @@ def display_shares(self, shares): share_id, host_id, name, - remark, f"{len(users_r_access)} User(s)", f"{len(users_w_access)} Users", + share.type, + remark, ] ) print_table(data) @@ -163,7 +164,7 @@ def do_shares(self, line): users_r_access = self.db.get_users_with_share_access(host_id=host_id, share_name=name, permissions="r") users_w_access = self.db.get_users_with_share_access(host_id=host_id, share_name=name, permissions="w") - data = [["ShareID", "Name", "Remark"], [share_id, name, remark]] + data = [["ShareID", "Name", "Type", "Remark"], [share_id, name, share.type, remark]] print_table(data, title="Share") host = self.db.get_hosts(filter_term=host_id)[0] data = [ From cecbf602284dab0da735245b9793996d6335e0e3 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Sun, 15 Nov 2026 23:32:13 +0100 Subject: [PATCH 3/6] Improve shares logic --- nxc/protocols/smb.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/nxc/protocols/smb.py b/nxc/protocols/smb.py index 9a745312f1..329911acf2 100755 --- a/nxc/protocols/smb.py +++ b/nxc/protocols/smb.py @@ -1639,11 +1639,8 @@ def shares(self): } if share["shi1_type"] & STYPE_TEMPORARY: share_info["type_name"] += ",TEMPORARY" - read = False - write = False try: self.conn.listPath(share_name, "*") - read = True share_info["access"].append("READ") except SessionError as e: error = get_error_string(e) @@ -1703,7 +1700,6 @@ def shares(self): # If we either can create a file or a directory we add the write privs to the output. Agreed on in https://github.com/Pennyw0rth/NetExec/pull/404 if write_dir or write_file: - write = True share_info["access"].append("WRITE") else: # ACL-based write check (default) — opens share root with FILE_OPEN + @@ -1745,21 +1741,10 @@ def shares(self): if "WRITE" in write_labels: write_labels = ["WRITE"] - for lbl in write_labels: - share_info["access"].append(lbl) - if not write: - write = True + share_info["access"].extend(write_labels) permissions.append(share_info) - if share_name != "IPC$": - try: - # TODO: check if this already exists in DB before adding - self.db.add_share(self.hostname, user_id, share_name, share_remark, read, write) - except Exception as e: - error = get_error_string(e) - self.logger.debug(f"Error adding share: {error}") - if self.args.filter_shares: self.logger.display("[REMOVED] Use the --shares read,write options instead.") @@ -1768,6 +1753,11 @@ def shares(self): self.logger.highlight(f"{'-----':<15} {'-----------':<15} {'----':<10} {'------'}") for share in permissions: + if share["name"] != "IPC$": + try: + self.db.add_share(self.hostname, user_id, share["name"], share["remark"], "READ" in share["access"], any(access.startswith("WRITE") for access in share["access"]), share["type_name"]) + except Exception as e: + self.logger.debug(f"Error adding share: {get_error_string(e)}") name = share["name"] remark = share["remark"] perms = ",".join(share["access"]) From bfc8373c6fc37902f53da3412bafef2bdb810052 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Wed, 18 Nov 2026 17:12:07 +0100 Subject: [PATCH 4/6] Extract share type dict --- nxc/protocols/smb.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/nxc/protocols/smb.py b/nxc/protocols/smb.py index 329911acf2..ac11ae16e4 100755 --- a/nxc/protocols/smb.py +++ b/nxc/protocols/smb.py @@ -1580,6 +1580,15 @@ def shares(self): (WRITE_DAC, "WRITE (ACL)"), (WRITE_OWNER, "WRITE (ACL)"), ] + SMB_SHARE_TYPES = { + STYPE_DISKTREE: "DISKTREE", + STYPE_PRINTQ: "PRINTQ", + STYPE_DEVICE: "DEVICE", + STYPE_IPC: "IPC", + STYPE_CLUSTER_FS: "CLUSTER_FS", + STYPE_CLUSTER_SOFS: "CLUSTER_SOFS", + STYPE_CLUSTER_DFS: "CLUSTER_DFS", + } try: self.logger.debug(f"domain: {self.domain}") @@ -1626,15 +1635,7 @@ def shares(self): "name": share_name, "remark": share_remark, "type": share["shi1_type"] & STYPE_MASK, - "type_name": { - STYPE_DISKTREE: "DISKTREE", - STYPE_PRINTQ: "PRINTQ", - STYPE_DEVICE: "DEVICE", - STYPE_IPC: "IPC", - STYPE_CLUSTER_FS: "CLUSTER_FS", - STYPE_CLUSTER_SOFS: "CLUSTER_SOFS", - STYPE_CLUSTER_DFS: "CLUSTER_DFS", - }.get(share["shi1_type"] & ~(STYPE_SPECIAL | STYPE_TEMPORARY), "UNKNOWN"), + "type_name": SMB_SHARE_TYPES.get(share["shi1_type"] & ~(STYPE_SPECIAL | STYPE_TEMPORARY), "UNKNOWN"), "access": [], } if share["shi1_type"] & STYPE_TEMPORARY: From 2682974e9089570fec5772fd3a011bef18f219f0 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Wed, 18 Nov 2026 17:14:21 +0100 Subject: [PATCH 5/6] Update all relevant vars on conflict --- nxc/protocols/smb/database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nxc/protocols/smb/database.py b/nxc/protocols/smb/database.py index 6edfdc0563..d51ab356ba 100755 --- a/nxc/protocols/smb/database.py +++ b/nxc/protocols/smb/database.py @@ -658,7 +658,7 @@ def is_share_valid(self, share_id): def add_share(self, host_id, user_id, name, remark, read, write, share_type): self.db_execute( - Insert(self.SharesTable).on_conflict_do_update(index_elements=["hostid", "userid", "name"], set_={"type": share_type}), + Insert(self.SharesTable).on_conflict_do_update(index_elements=["hostid", "userid", "name"], set_={"remark": remark, "read": read, "write": write, "type": share_type}), { "hostid": host_id, "userid": user_id, From d49da3fbd2109949aba21c0e4864acea0dfa47d0 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Wed, 18 Nov 2026 17:20:26 +0100 Subject: [PATCH 6/6] Stick to one syntax --- nxc/nxcdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nxc/nxcdb.py b/nxc/nxcdb.py index c7518cfee1..80a82eaeb7 100644 --- a/nxc/nxcdb.py +++ b/nxc/nxcdb.py @@ -222,7 +222,7 @@ def do_export(self, line): share[3], # name bool(share[5]), # read bool(share[6]), # write - share.type, + share[7], # type share[4], # remark ) formatted_shares.append(entry)