Skip to content

Commit e78b05a

Browse files
authored
Merge branch 'main' into hosts_file
2 parents d4808ac + a83c412 commit e78b05a

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

nxc/protocols/smb.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
from pywerview.cli.helpers import get_localdisks, get_netsession, get_netgroupmember, get_netgroup, get_netcomputer, get_netloggedon, get_netlocalgroup
6262

63-
from time import time
63+
from time import time, ctime
6464
from datetime import datetime
6565
from functools import wraps
6666
from traceback import format_exc
@@ -947,6 +947,29 @@ def shares(self):
947947
self.logger.highlight(f"{name:<15} {','.join(perms):<15} {remark}")
948948
return permissions
949949

950+
951+
def dir(self): # noqa: A003
952+
search_path = ntpath.join(self.args.dir, "*")
953+
try:
954+
contents = self.conn.listPath(self.args.share, search_path)
955+
except SessionError as e:
956+
error = get_error_string(e)
957+
self.logger.fail(
958+
f"Error enumerating '{search_path}': {error}",
959+
color="magenta" if error in smb_error_status else "red",
960+
)
961+
return
962+
963+
if not contents:
964+
return
965+
966+
self.logger.highlight(f"{'Perms':<9}{'File Size':<15}{'Date':<30}{'File Path':<45}")
967+
self.logger.highlight(f"{'-----':<9}{'---------':<15}{'----':<30}{'---------':<45}")
968+
for content in contents:
969+
full_path = ntpath.join(self.args.dir, content.get_longname())
970+
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}")
971+
972+
950973
@requires_admin
951974
def interfaces(self):
952975
"""

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def proto_args(parser, parents):
3535

3636
mapping_enum_group = smb_parser.add_argument_group("Mapping/Enumeration", "Options for Mapping/Enumerating")
3737
mapping_enum_group.add_argument("--shares", action="store_true", help="enumerate shares and access")
38+
mapping_enum_group.add_argument("--dir", nargs="?", type=str, const="", help="List the content of a path (default path: '%(const)s')")
3839
mapping_enum_group.add_argument("--interfaces", action="store_true", help="enumerate network interfaces")
3940
mapping_enum_group.add_argument("--no-write-check", action="store_true", help="Skip write check on shares (avoid leaving traces when missing delete permissions)")
4041
mapping_enum_group.add_argument("--filter-shares", nargs="+", help="Filter share by access, option 'read' 'write' or 'read,write'")

0 commit comments

Comments
 (0)