@@ -904,63 +904,32 @@ def shares(self):
904904 return permissions
905905
906906
907- def enum_shares (self ):
908- try :
909- shares = self .conn .listShares ()
910- self .logger .info (f"Shares returned: { shares } " )
911- except SessionError as e :
912- error = get_error_string (e )
913- self .logger .fail (
914- f"Error enumerating shares: { error } " ,
915- color = "magenta" if error in smb_error_status else "red" ,
916- )
917- return
918- except Exception as e :
919- error = get_error_string (e )
920- self .logger .fail (
921- f"Error enumerating shares: { error } " ,
922- color = "magenta" if error in smb_error_status else "red" ,
923- )
907+ def dir (self ):
908+ # Seems defined by default, do we have to keep this check ?
909+ if not self .args .share :
910+ self .logger .error ("You must define --share option" )
924911 return
925-
926- self .logger .display ("Enumerating SMB Shares Directories" )
927- for share in shares :
928- share_name = share ["shi1_netname" ][:- 1 ]
929- depth = 1
930- contents = self .conn .listPath (share_name , "*" )
931-
932- self .logger .success (share_name )
933-
934- if contents and depth == 1 :
935- self .logger .highlight (f"{ 'Perms' :<9} { 'File Size' :<15} { 'Date' :<30} { 'File Path' :<45} " )
936- self .logger .highlight (f"{ '-----' :<9} { '---------' :<15} { '----' :<30} { '---------' :<45} " )
937- self .list_share (share_name , "" )
938-
939-
940- def list_share (self , share_name , path_dir , depth = 1 ):
941- search_path = ntpath .join (path_dir , "*" )
942-
943- try :
944- contents = self .conn .listPath (share_name , search_path )
912+
913+ search_path = ntpath .join (self .args .dir , "*" )
914+ try :
915+ contents = self .conn .listPath (self .args .share , search_path )
945916 except SessionError as e :
946917 error = get_error_string (e )
947918 self .logger .fail (
948919 f"Error enumerating '{ search_path } ': { error } " ,
949920 color = "magenta" if error in smb_error_status else "red" ,
950921 )
951922 return
923+
924+ if not contents :
925+ return
952926
927+ self .logger .highlight (f"{ 'Perms' :<9} { 'File Size' :<15} { 'Date' :<30} { 'File Path' :<45} " )
928+ self .logger .highlight (f"{ '-----' :<9} { '---------' :<15} { '----' :<30} { '---------' :<45} " )
953929 for content in contents :
954- path_name = content .get_longname ()
955- full_path = ntpath .join (path_dir , path_name )
956-
957- if path_name in ["." , ".." ]:
958- continue
930+ full_path = ntpath .join (self .args .dir , content .get_longname ())
931+ self .logger .highlight (f"{ 'd' if content .is_directory () else 'f' } { 'rw-' if content .is_readonly () > 0 else 'r--' :<8} { content .get_filesize ():<15} { ctime (float (content .get_mtime_epoch ())):<30} { full_path :<45} " )
959932
960- if path_name != path_dir :
961- self .logger .highlight (f"{ 'd' if content .is_directory () else 'f' } { 'rw-' if content .is_readonly () > 0 else 'r--' :<8} { content .get_filesize ():<15} { ctime (float (content .get_mtime_epoch ())):<30} { full_path :<45} " )
962- if content .is_directory () and depth < self .args .enum_shares and path_name not in [ "." , ".." ]:
963- self .list_share (share_name , full_path , depth + 1 )
964933
965934 @requires_admin
966935 def interfaces (self ):
0 commit comments