Skip to content

Commit

Permalink
[SMB] Allow force to use smbv2
Browse files Browse the repository at this point in the history
Signed-off-by: XiaoliChan <[email protected]>
  • Loading branch information
XiaoliChan committed Dec 26, 2024
1 parent 32b20cd commit b58133a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions nxc/protocols/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,22 +583,22 @@ def create_smbv3_conn(self):
return False
return True

def create_conn_obj(self, no_smbv1=False):
def create_conn_obj(self):
"""
Tries to create a connection object to the target host.
On first try, it will try to create a SMBv1 connection.
On further tries, it will remember which SMB version is supported and create a connection object accordingly.
:param no_smbv1: If True, it will not try to create a SMBv1 connection
"""
# Initial negotiation
if not no_smbv1 and self.smbv1 is None:
if self.args.force_smbv2:
return self.create_smbv3_conn()

if self.smbv1 is None:
self.smbv1 = self.create_smbv1_conn()
if self.smbv1:
return True
elif not self.is_timeouted:
return self.create_smbv3_conn()
elif not no_smbv1 and self.smbv1:
elif self.smbv1:
return self.create_smbv1_conn()
else:
return self.create_smbv3_conn()
Expand Down Expand Up @@ -879,8 +879,10 @@ def shares(self):
write = False
write_dir = False
write_file = False
pwd = ntpath.join("\\", "*")
pwd = ntpath.normpath(pwd)
try:
self.conn.listPath(share_name, "*")
self.conn.listPath(share_name, pwd)
read = True
share_info["access"].append("READ")
except SessionError as e:
Expand Down
1 change: 1 addition & 0 deletions nxc/protocols/smb/proto_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def proto_args(parser, parents):
smb_parser.add_argument("--port", type=int, default=445, help="SMB port")
smb_parser.add_argument("--share", metavar="SHARE", default="C$", help="specify a share")
smb_parser.add_argument("--smb-server-port", default="445", help="specify a server port for SMB", type=int)
smb_parser.add_argument("--force-smbv2", action="store_true", help="Force to use SMBv2 in connection")
smb_parser.add_argument("--gen-relay-list", metavar="OUTPUT_FILE", help="outputs all hosts that don't require SMB signing to the specified file")
smb_parser.add_argument("--smb-timeout", help="SMB connection timeout", type=int, default=2)
smb_parser.add_argument("--laps", dest="laps", metavar="LAPS", type=str, help="LAPS authentification", nargs="?", const="administrator")
Expand Down

0 comments on commit b58133a

Please sign in to comment.