Skip to content

Commit f17a61f

Browse files
committed
Change write privs of a share to True if we can either create a file OR a directory
1 parent 675480c commit f17a61f

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

nxc/protocols/smb.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def ps_execute(self, payload=None, get_output=False, methods=None, force_ps32=Fa
775775

776776
def shares(self):
777777
temp_dir = ntpath.normpath("\\" + gen_random_string())
778-
temp_file = ntpath.normpath("\\" + gen_random_string()+ ".txt")
778+
temp_file = ntpath.normpath("\\" + gen_random_string() + ".txt")
779779
permissions = []
780780

781781
try:
@@ -814,6 +814,8 @@ def shares(self):
814814
share_info = {"name": share_name, "remark": share_remark, "access": []}
815815
read = False
816816
write = False
817+
write_dir = False
818+
write_file = False
817819
try:
818820
self.conn.listPath(share_name, "*")
819821
read = True
@@ -825,13 +827,12 @@ def shares(self):
825827
if not self.args.no_write_check:
826828
try:
827829
self.conn.createDirectory(share_name, temp_dir)
828-
write = True
829-
share_info["access"].append("WRITE")
830+
write_dir = True
830831
try:
831832
self.conn.deleteDirectory(share_name, temp_dir)
832833
except SessionError as e:
833834
error = get_error_string(e)
834-
if error == 'STATUS_OBJECT_NAME_NOT_FOUND':
835+
if error == "STATUS_OBJECT_NAME_NOT_FOUND":
835836
pass
836837
else:
837838
self.logger.debug(f"Error DELETING created temp dir {temp_dir} on share {share_name}: {error}")
@@ -843,20 +844,24 @@ def shares(self):
843844
tid = self.conn.connectTree(share_name)
844845
fid = self.conn.createFile(tid, temp_file, desiredAccess=FILE_SHARE_WRITE, shareMode=FILE_SHARE_DELETE)
845846
self.conn.closeFile(tid, fid)
846-
write = True
847-
share_info["access"].append("WRITE")
847+
write_file = True
848848
try:
849849
self.conn.deleteFile(share_name, temp_file)
850850
except SessionError as e:
851851
error = get_error_string(e)
852-
if error == 'STATUS_OBJECT_NAME_NOT_FOUND':
852+
if error == "STATUS_OBJECT_NAME_NOT_FOUND":
853853
pass
854854
else:
855855
self.logger.debug(f"Error DELETING created temp file {temp_file} on share {share_name}")
856856
except SessionError as e:
857857
error = get_error_string(e)
858858
self.logger.debug(f"Error checking WRITE access with file on share {share_name}: {error}")
859859

860+
# If we either can create a file or a directory we add the write privs to the output. Agreed on in https://github.com/Pennyw0rth/NetExec/pull/404
861+
if write_dir or write_file:
862+
write = True
863+
share_info["access"].append("WRITE")
864+
860865
permissions.append(share_info)
861866

862867
if share_name != "IPC$":

0 commit comments

Comments
 (0)