Hacked By AnonymousFox

Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/cleanup/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/cleanup/__pycache__/storage.cpython-311.pyc

�

��gf��T�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZm
Z
ddlmZmZddlmZdd	lmZmZdd
lmZmZddlmZddlmZdd
lmZ ddl!m"Z"ddl#m$Z$ej%e&��Z'eGd�d����Z(Gd�d��Z)ddede
e*fd�Z+dS)u

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.


This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
See the GNU General Public License for more details.


You should have received a copy of the GNU General Public License
 along with this program.  If not, see <https://www.gnu.org/licenses/>.

Copyright © 2019 Cloud Linux Software Inc.

This software is also available under ImunifyAV commercial license,
see <https://www.imunify360.com/legal/eula>
�N)�suppress)�asdict�	dataclass)�Path)�List�Optional)�Malware�UserType)�TheSink)�antivirus_mode�safe_fileops)�MalwareHitStatus�MalwareScanResourceType)�
MalwareHit)�
is_crontab)�restore)�
MalwareAction��	hash_pathc��eZdZUeed<eed<eed<ejZeed<dZe	ed<dZ
e	ed<dZeed	<dZeed
<dZ
e	ed<dZe	ed<dZe	ed
<dZe	ed<eZdS)�
RestoreReport�file�scan_id�owner�	initiator����
cleaned_at�reverted_at��hash_before_revert�hash_after_revert�mtime_before_revert�mtime_after_revert�size_before_revert�size_after_revertN)�__name__�
__module__�__qualname__�str�__annotations__r
�ROOTrr�floatrr r!r"r#r$r%r�to_dict���T/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/cleanup/storage.pyrr.s��������

�I�I�I�
�L�L�L��J�J�J��]�I�s�"�"�"��J������K����� ��� � � ���s����!#���#�#�#� "���"�"�"� "���"�"�"�!��u�!�!�!��G�G�Gr/rc�b�eZdZUdZeej��Zeed<e	ddedefd���Z
ededefd	���Z
ed
���Zed���Zed���Zed
edefd���Ze	ddeedeefd���Zedededefd���Zededefd���ZdS)�CleanupStoragez@
    Store files before cleanup and restore them by request
    �pathF�src�dstc��~K�tjt|��t|��dd||����d{V��dS)NFT)�
src_unlink�
dst_overwrite�safe_src�safe_dst)r
�	safe_mover))r4r5r9r:s    r0�_copyzCleanupStorage._copyGsf�����$���H�H���H�H�����

�
�
�	
�	
�	
�	
�	
�	
�	
�	
�	
r/�filename�returnc� �t|��S)zN
        Get file name for cleanup storage
        :return: file name
        r)�clsr=s  r0�storage_namezCleanupStorage.storage_nameRs����"�"�"r/c�F�|j|�|j��zS�N)r3rA�	orig_file)r@�hits  r0�get_hit_store_pathz!CleanupStorage.get_hit_store_pathZs���x�#�*�*�3�=�9�9�9�9r/c��K�|j}|�|��}t|��}|�|||d����d{V��dS�NT)r9r:)�orig_file_pathrFrr<)r@rEr4r5r9s     r0�storezCleanupStorage.store^s^����� ���$�$�S�)�)���c�?�?���i�i��S�8�d�i�C�C�C�C�C�C�C�C�C�C�Cr/c��K�|j���s|j�d��t��t��t��}}}|D]�}	|�|���d{V��|�|���4#t$r|�|��Y�Uttj	f$rt}t�dt|��|��|�|��tj|j|j|j����d{V��Yd}~��d}~wwxYw|||fS)N�z-Failed to store file before cleanup: %r -- %s�r3�
file_owner�	file_user)r3�exists�mkdir�setrJ�add�FileNotFoundError�OSErrorr
�UnsafeFileOperation�logger�warningr)r�cleanup_failed_storerDr�user)r@�hits�	succeeded�	not_exist�failedrE�es       r0�	store_allzCleanupStorage.store_alles������x��� � �	"��H�N�N�5�!�!�!�'*�u�u�c�e�e�S�U�U�f�9�	��	�	�C�
��i�i��n�n�$�$�$�$�$�$�$��
�
�c�"�"�"�"��$�
#�
#�
#��
�
�c�"�"�"�"�"��\�=�>�
�
�
����C���H�H�����
�
�
�3����#�8���"�y�!�h��������������������
�����&�)�+�+s�%0B�E�7E�A*D;�;ErEc��K�t|j|j|j��}|�|��}|j}t
|��}tt��5|�	��j
|_ddd��n#1swxYwYtt��5|�	��}|j
|_|j
|_tj|��������}||_ddd��n#1swxYwY|�||d|����d{V��t+j��|_tt��5|�	��}|j
|_|j
|_tj|��������}	|	|_ddd��n#1swxYwY|SrH)rrD�	scanid_idrZrFrIrrrT�stat�st_mtimerr"�st_sizer$�hashlib�sha256�
read_bytes�	hexdigestr r<�timerr#r%r!)
r@rE�reportr4r5r:�	st_before�hash_before�st_after�
hash_afters
          r0rzCleanupStorage.restore�sg�����s�}�c�m�S�X�F�F���$�$�S�)�)��� ���c�?�?��
�'�
(�
(�	4�	4� #���
�
� 3�F��	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4��'�
(�
(�	4�	4����
�
�I�)2�);�F�&�(1�(9�F�%�!�.����)9�)9�:�:�D�D�F�F�K�(3�F�%�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4��i�i��S�4�(�i�C�C�C�C�C�C�C�C�C�!�Y�[�[���
�'�
(�
(�	2�	2��x�x�z�z�H�(0�(9�F�%�'/�'7�F�$� �����(8�(8�9�9�C�C�E�E�J�'1�F�$�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2����	2�	2�	2�	2��
s8�"B
�
B�B�,A,D$�$D(�+D(�:A,G2�2G6�9G6Nr[rc��(K�t��t��}}|D]�}	|�|���d{V��}tj|j|j|j||����d{V��|�|���b#ttj
f$rt}tj|j|j|j����d{V��t�
dt|��|��|�|��Yd}~��d}~wwxYw||fS)N)r3rNrOrrkrMz Failed to restore file: %r -- %s)rRrr�cleanup_restored_originalrDrrZrSrUr
rV�cleanup_failed_restorerWrXr))r@r[rr\r^rErkr_s        r0�restore_allzCleanupStorage.restore_all�sg���� �E�E�3�5�5�6�	��	 �	 �C�
 �"�{�{�3�/�/�/�/�/�/�/�/��#�=���"�y�!�h�'�!������������
�
�c�"�"�"�"���\�=�>�
 �
 �
 �#�:���"�y�!�h�����������
���A�3�s�8�8�Q�O�O�O��
�
�3�������������
 �����&� � s�AB�D
�A*D�D
�keepc��tK�|���}|j|kr|���dSdS)NTF)rcrd�unlink)r@r3rt�sts    r0�_clearzCleanupStorage._clear�s7����
�Y�Y�[�[��
�;�����K�K�M�M�M��4��ur/c��K�|j�dd���d}|j���D]#}|�||���d{V��r|dz
}�$|S)zj
        Clear storage
        :param keep: keep files after specified timestamp
        :return:
        rLT)�exist_okrN�)r3rQ�iterdirrx)r@rt�clearedr3s    r0�clearzCleanupStorage.clear�sy����	����u�t��,�,�,����H�$�$�&�&�	�	�D��Z�Z��d�+�+�+�+�+�+�+�+�
��1�����r/)FFrC)r&r'r(�__doc__r�Config�CLEANUP_STORAGEr3r*�staticmethodr<�classmethodr)rArFrJr`rrrrrrsr,�boolrx�intr~r.r/r0r2r2@s������������f�,�-�-�D�$�-�-�-��
�
��
�D�
�
�
��\�
��#�C�#�C�#�#�#��[�#��:�:��[�:��D�D��[�D��,�,��[�,�6��
��}�����[��<�@D�!�!��
�#�!�08��
�!�!�!��[�!�6����E��d�����[����u�������[���r/r2�sinkrc��K�d�|D��}t�||���d{V��\}}tj|tj��tjrtj	||���d{V��||fS)Nc�F�g|]}|jtjjk�|��Sr.)�
resource_typer�FILE�value)�.0rEs  r0�
<listcomp>z restore_hits.<locals>.<listcomp>�s7�������� 7� <� B�B�B�	�B�B�Br/)
r2rsr�
set_statusr�FOUNDr�disabled�mds_restore�restore_hits)r[r�r�	file_hitsr\r^s      r0r�r��s�����������I�
-�8�8��I�N�N�N�N�N�N�N�N��I�v���)�%5�%;�<�<�<���3��&�t�T�2�2�2�2�2�2�2�2�2��f��r/rC),rrf�loggingrj�
contextlibr�dataclassesrr�pathlibr�typingrr� defence360agent.contracts.configr	r�r
�"defence360agent.internals.the_sinkr�defence360agent.utilsrr
�imav.malwarelib.configrr�imav.malwarelib.modelr�imav.malwarelib.scan.crontabr�imav.malwarelib.scan.mdsrr��imav.malwarelib.subsys.malwarer�imav.malwarelib.utilsr�	getLoggerr&rWrr2r)r�r.r/r0�<module>r�s�����*������������������)�)�)�)�)�)�)�)�������!�!�!�!�!�!�!�!�H�H�H�H�H�H�H�H�6�6�6�6�6�6�>�>�>�>�>�>�>�>���������-�,�,�,�,�,�3�3�3�3�3�3�;�;�;�;�;�;�8�8�8�8�8�8�+�+�+�+�+�+�	��	�8�	$�	$�������������"Q�Q�Q�Q�Q�Q�Q�Q�h
�
�7�
�x��}�
�
�
�
�
�
r/

Hacked By AnonymousFox1.0, Coded By AnonymousFox