@@ -245,18 +245,6 @@ def enum_shares(self):
245245 finally :
246246 self .nfs3 .disconnect ()
247247
248- def uid_brute (self ):
249- nfs_port = self .portmap .getport (NFS_PROGRAM , NFS_V3 )
250- self .nfs3 = NFSv3 (self .host , nfs_port , self .args .nfs_timeout , self .auth )
251- self .nfs3 .connect ()
252-
253- # Mounting NFS Shares
254- output_export = str (self .mount .export ())
255- reg = re .compile (r"ex_dir=b'([^']*)'" )
256- shares = list (reg .findall (output_export ))
257-
258- self .list_exported_shares (self .args .uid_brute , shares )
259-
260248 def list_exported_shares (self , max_uid , shares ):
261249 self .logger .display (f"Enumerating NFS Shares up to UID { max_uid } " )
262250 white_list = []
@@ -279,6 +267,92 @@ def list_exported_shares(self, max_uid, shares):
279267 continue
280268 self .logger .exception (f"{ share } - { e } " )
281269
270+ def get_file_single (self , remote_file , local_file ):
271+ local_file_path = local_file
272+ remote_file_path = remote_file
273+ self .logger .display (f"Downloading { local_file_path } to { remote_file_path } " )
274+ try :
275+ # Connect to NFS
276+ nfs_port = self .portmap .getport (NFS_PROGRAM , NFS_V3 )
277+ self .nfs3 = NFSv3 (self .host , nfs_port , self .args .nfs_timeout , self .auth )
278+ self .nfs3 .connect ()
279+
280+ # Mount the NFS share
281+ mnt_info = self .mount .mnt (remote_file_path , self .auth )
282+ file_handle = mnt_info ["mountinfo" ]["fhandle" ]
283+ file_data = self .nfs3 .read (file_handle , auth = self .auth )
284+
285+ if "resfail" in file_data :
286+ raise Exception ("Insufficient Permissions" )
287+ else :
288+ entries = file_data ["resok" ]["data" ]
289+
290+ # Write the data to the local file
291+ with open (local_file_path , "wb+" ) as local_file :
292+ local_file .write (entries )
293+
294+ self .logger .highlight (f"File successfully downloaded to { local_file_path } from { remote_file_path } " )
295+
296+ # Unmount the share
297+ self .mount .umnt (self .auth )
298+
299+ except Exception as e :
300+ self .logger .fail (f'Error writing file "{ remote_file_path } " from share "{ local_file_path } ": { e } ' )
301+ if os .path .getsize (local_file_path ) == 0 :
302+ os .remove (local_file_path )
303+
304+ def get_file (self ):
305+ self .get_file_single (self .args .get_file [0 ], self .args .get_file [1 ])
306+
307+ def put_file_single (self , local_file , remote_file ):
308+ local_file_path = local_file
309+ remote_file_path = remote_file
310+ if not remote_file_path .endswith ("/" ):
311+ remote_file_path += "/"
312+ self .logger .display (f"Uploading { local_file_path } to { remote_file_path } " )
313+ try :
314+ # Connect to NFS
315+ nfs_port = self .portmap .getport (NFS_PROGRAM , NFS_V3 )
316+ self .nfs3 = NFSv3 (self .host , nfs_port , self .args .nfs_timeout , self .auth )
317+ self .nfs3 .connect ()
318+
319+ try :
320+ # Mount the NFS share for create file
321+ mnt_info = self .mount .mnt (remote_file_path , self .auth )
322+ dir_handle = mnt_info ["mountinfo" ]["fhandle" ]
323+ attrs = self .nfs3 .getattr (dir_handle , auth = self .auth )
324+ self .auth ["uid" ] = attrs ["attributes" ]["uid" ]
325+ self .logger .display (f"Trying to create { remote_file_path } { local_file_path } " )
326+ self .nfs3 .create (dir_handle , local_file_path , 1 , auth = self .auth )
327+ self .logger .success (f"{ local_file_path } successfully created." )
328+ except Exception as e :
329+ self .logger .fail (f"{ local_file_path } was not created." )
330+ self .logger .debug (f"Error while creating remote file: { e } " )
331+
332+ try :
333+ # Mount the NFS share for mount created file
334+ mnt_info = self .mount .mnt (remote_file_path + local_file , self .auth )
335+ file_handle = mnt_info ["mountinfo" ]["fhandle" ]
336+ attrs = self .nfs3 .getattr (file_handle , auth = self .auth )
337+ self .auth ["uid" ] = attrs ["attributes" ]["uid" ]
338+ with open (local_file_path , "rb" ) as file :
339+ file_data = file .read ().decode ()
340+
341+ self .logger .display (f"Trying to write data from { local_file_path } " )
342+ self .nfs3 .write (file_handle , 0 , len (file_data ), file_data , 1 , auth = self .auth )
343+
344+ self .logger .highlight (f"File { local_file_path } successfully uploaded on { remote_file_path } " )
345+ except Exception as e :
346+ self .logger .fail (f"{ local_file_path } was not writed." )
347+ self .logger .debug (f"Error while creating remote file: { e } " )
348+
349+ # Unmount the share
350+ self .mount .umnt (self .auth )
351+ except Exception as e :
352+ self .logger .fail (f"Error writing file to share { remote_file_path } : { e } " )
353+
354+ def put_file (self ):
355+ self .put_file_single (self .args .put_file [0 ], self .args .put_file [1 ])
282356
283357def convert_size (size_bytes ):
284358 if size_bytes == 0 :
0 commit comments