Skip to content

Commit 1b7dbe3

Browse files
committed
[SMB] Allow force to use smbv2
Signed-off-by: XiaoliChan <30458572+XiaoliChan@users.noreply.github.com>
1 parent 32b20cd commit 1b7dbe3

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

nxc/protocols/smb.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,22 +583,23 @@ def create_smbv3_conn(self):
583583
return False
584584
return True
585585

586-
def create_conn_obj(self, no_smbv1=False):
586+
def create_conn_obj(self):
587587
"""
588588
Tries to create a connection object to the target host.
589589
On first try, it will try to create a SMBv1 connection.
590590
On further tries, it will remember which SMB version is supported and create a connection object accordingly.
591-
592-
:param no_smbv1: If True, it will not try to create a SMBv1 connection
593591
"""
592+
if self.args.force_smbv2:
593+
return self.create_smbv3_conn()
594+
594595
# Initial negotiation
595-
if not no_smbv1 and self.smbv1 is None:
596+
if self.smbv1 is None:
596597
self.smbv1 = self.create_smbv1_conn()
597598
if self.smbv1:
598599
return True
599600
elif not self.is_timeouted:
600601
return self.create_smbv3_conn()
601-
elif not no_smbv1 and self.smbv1:
602+
elif self.smbv1:
602603
return self.create_smbv1_conn()
603604
else:
604605
return self.create_smbv3_conn()
@@ -879,8 +880,10 @@ def shares(self):
879880
write = False
880881
write_dir = False
881882
write_file = False
883+
pwd = ntpath.join("\\", "*")
884+
pwd = ntpath.normpath(pwd)
882885
try:
883-
self.conn.listPath(share_name, "*")
886+
self.conn.listPath(share_name, pwd)
884887
read = True
885888
share_info["access"].append("READ")
886889
except SessionError as e:

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def proto_args(parser, parents):
1616
smb_parser.add_argument("--port", type=int, default=445, help="SMB port")
1717
smb_parser.add_argument("--share", metavar="SHARE", default="C$", help="specify a share")
1818
smb_parser.add_argument("--smb-server-port", default="445", help="specify a server port for SMB", type=int)
19+
smb_parser.add_argument("--force-smbv2", action="store_true", help="Force to use SMBv2 in connection")
1920
smb_parser.add_argument("--gen-relay-list", metavar="OUTPUT_FILE", help="outputs all hosts that don't require SMB signing to the specified file")
2021
smb_parser.add_argument("--smb-timeout", help="SMB connection timeout", type=int, default=2)
2122
smb_parser.add_argument("--laps", dest="laps", metavar="LAPS", type=str, help="LAPS authentification", nargs="?", const="administrator")

0 commit comments

Comments
 (0)