Skip to content

Commit 2a15590

Browse files
authored
Merge pull request Pennyw0rth#523 from XiaoliChan/force-smbv2
[SMB] Allow force to disable SMBv1
2 parents 32b20cd + 281feb3 commit 2a15590

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

nxc/protocols/smb.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ def create_smbv1_conn(self):
549549
preferredDialect=SMB_DIALECT,
550550
timeout=self.args.smb_timeout,
551551
)
552-
self.smbv1 = True
553552
except OSError as e:
554553
if "Connection reset by peer" in str(e):
555554
self.logger.info(f"SMBv1 might be disabled on {self.host}")
@@ -577,7 +576,6 @@ def create_smbv3_conn(self):
577576
self.port,
578577
timeout=self.args.smb_timeout,
579578
)
580-
self.smbv1 = False
581579
except (Exception, NetBIOSTimeout, OSError) as e:
582580
self.logger.info(f"Error creating SMBv3 connection to {self.host}: {e}")
583581
return False
@@ -591,6 +589,8 @@ def create_conn_obj(self, no_smbv1=False):
591589
592590
:param no_smbv1: If True, it will not try to create a SMBv1 connection
593591
"""
592+
no_smbv1 = self.args.no_smbv1 if self.args.no_smbv1 else no_smbv1
593+
594594
# Initial negotiation
595595
if not no_smbv1 and self.smbv1 is None:
596596
self.smbv1 = self.create_smbv1_conn()
@@ -840,6 +840,7 @@ def shares(self):
840840
temp_dir = ntpath.normpath("\\" + gen_random_string())
841841
temp_file = ntpath.normpath("\\" + gen_random_string() + ".txt")
842842
permissions = []
843+
write_check = True if not self.args.no_write_check else False
843844

844845
try:
845846
self.logger.debug(f"domain: {self.domain}")
@@ -886,8 +887,14 @@ def shares(self):
886887
except SessionError as e:
887888
error = get_error_string(e)
888889
self.logger.debug(f"Error checking READ access on share {share_name}: {error}")
890+
except (NetBIOSError, UnicodeEncodeError) as e:
891+
write_check = False
892+
share_info["access"].append("UNKNOWN (try '--no-smbv1')")
893+
error = get_error_string(e)
894+
self.logger.debug(f"Error checking READ access on share {share_name}: {error}. This exception always caused by special character in share name with SMBv1")
895+
self.logger.info(f"Skipping WRITE permission check on share {share_name}")
889896

890-
if not self.args.no_write_check:
897+
if write_check:
891898
try:
892899
self.conn.createDirectory(share_name, temp_dir)
893900
write_dir = True

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("--no-smbv1", action="store_true", help="Force to disable SMBv1 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")

tests/e2e_commands.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ netexec smb TARGET_HOST --generate-hosts-file /tmp/hostsfile
55
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # need an extra space after this command due to regex
66
netexec {DNS} smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS
77
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --shares
8+
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --shares --no-smbv1
89
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --shares --filter-shares READ WRITE
910
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --pass-pol
1011
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --disks

0 commit comments

Comments
 (0)