Skip to content

Commit 2bf95cc

Browse files
author
y0no
committed
Move from --enum-share to --dir
1 parent c3f10ef commit 2bf95cc

2 files changed

Lines changed: 16 additions & 47 deletions

File tree

nxc/protocols/smb.py

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -904,63 +904,32 @@ def shares(self):
904904
return permissions
905905

906906

907-
def enum_shares(self):
908-
try:
909-
shares = self.conn.listShares()
910-
self.logger.info(f"Shares returned: {shares}")
911-
except SessionError as e:
912-
error = get_error_string(e)
913-
self.logger.fail(
914-
f"Error enumerating shares: {error}",
915-
color="magenta" if error in smb_error_status else "red",
916-
)
917-
return
918-
except Exception as e:
919-
error = get_error_string(e)
920-
self.logger.fail(
921-
f"Error enumerating shares: {error}",
922-
color="magenta" if error in smb_error_status else "red",
923-
)
907+
def dir(self):
908+
# Seems defined by default, do we have to keep this check ?
909+
if not self.args.share:
910+
self.logger.error("You must define --share option")
924911
return
925-
926-
self.logger.display("Enumerating SMB Shares Directories")
927-
for share in shares:
928-
share_name = share["shi1_netname"][:-1]
929-
depth = 1
930-
contents = self.conn.listPath(share_name, "*")
931-
932-
self.logger.success(share_name)
933-
934-
if contents and depth == 1:
935-
self.logger.highlight(f"{'Perms':<9}{'File Size':<15}{'Date':<30}{'File Path':<45}")
936-
self.logger.highlight(f"{'-----':<9}{'---------':<15}{'----':<30}{'---------':<45}")
937-
self.list_share(share_name, "")
938-
939-
940-
def list_share(self, share_name, path_dir, depth=1):
941-
search_path = ntpath.join(path_dir, "*")
942-
943-
try:
944-
contents = self.conn.listPath(share_name, search_path)
912+
913+
search_path = ntpath.join(self.args.dir, "*")
914+
try:
915+
contents = self.conn.listPath(self.args.share, search_path)
945916
except SessionError as e:
946917
error = get_error_string(e)
947918
self.logger.fail(
948919
f"Error enumerating '{search_path}': {error}",
949920
color="magenta" if error in smb_error_status else "red",
950921
)
951922
return
923+
924+
if not contents:
925+
return
952926

927+
self.logger.highlight(f"{'Perms':<9}{'File Size':<15}{'Date':<30}{'File Path':<45}")
928+
self.logger.highlight(f"{'-----':<9}{'---------':<15}{'----':<30}{'---------':<45}")
953929
for content in contents:
954-
path_name = content.get_longname()
955-
full_path = ntpath.join(path_dir, path_name)
956-
957-
if path_name in [".", ".."]:
958-
continue
930+
full_path = ntpath.join(self.args.dir, content.get_longname())
931+
self.logger.highlight(f"{'d' if content.is_directory() else 'f'}{'rw-' if content.is_readonly() > 0 else 'r--':<8}{content.get_filesize():<15}{ctime(float(content.get_mtime_epoch())):<30}{full_path:<45}")
959932

960-
if path_name != path_dir:
961-
self.logger.highlight(f"{'d' if content.is_directory() else 'f'}{'rw-' if content.is_readonly() > 0 else 'r--':<8}{content.get_filesize():<15}{ctime(float(content.get_mtime_epoch())):<30}{full_path:<45}")
962-
if content.is_directory() and depth < self.args.enum_shares and path_name not in [ ".", ".."]:
963-
self.list_share(share_name, full_path, depth+1)
964933

965934
@requires_admin
966935
def interfaces(self):

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def proto_args(parser, parents):
3434

3535
mapping_enum_group = smb_parser.add_argument_group("Mapping/Enumeration", "Options for Mapping/Enumerating")
3636
mapping_enum_group.add_argument("--shares", action="store_true", help="enumerate shares and access")
37-
mapping_enum_group.add_argument("--enum-shares", nargs="?", type=int, const=3, help="Authenticate and enumerate exposed shares recursively (default depth: %(const)s)")
37+
mapping_enum_group.add_argument("--dir", nargs="?", type=str, const="", help="List the content of a path (default path: '%(const)s')")
3838
mapping_enum_group.add_argument("--interfaces", action="store_true", help="enumerate network interfaces")
3939
mapping_enum_group.add_argument("--no-write-check", action="store_true", help="Skip write check on shares (avoid leaving traces when missing delete permissions)")
4040
mapping_enum_group.add_argument("--filter-shares", nargs="+", help="Filter share by access, option 'read' 'write' or 'read,write'")

0 commit comments

Comments
 (0)