Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SMB] Allow force to disable SMBv1 #523

Merged
merged 4 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions nxc/protocols/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,22 +583,23 @@ def create_smbv3_conn(self):
return False
return True

def create_conn_obj(self, no_smbv1=False):
def create_conn_obj(self):
XiaoliChan marked this conversation as resolved.
Show resolved Hide resolved
"""
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
"""
if self.args.force_smbv2:
return self.create_smbv3_conn()

# Initial negotiation
if not no_smbv1 and self.smbv1 is None:
XiaoliChan marked this conversation as resolved.
Show resolved Hide resolved
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 +880,10 @@ def shares(self):
write = False
write_dir = False
write_file = False
pwd = ntpath.join("\\", "*")
XiaoliChan marked this conversation as resolved.
Show resolved Hide resolved
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