Hacked By AnonymousFox

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

�

��g>���dZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZmZmZmZdd
lmZddlmZddlmZmZdd
lm Z ddl!m"Z"m#Z#ddl$m%Z%m&Z&ddl'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ej;e<��Z=e&e%e=j>���e=j?��Z@dddd�dddd�dddd�d �ZAGd!�d"e��ZBGd#�d$eB��ZCGd%�d&eB��ZDe-ZEeCZFe(ejGd'�(��ZHe+jIjJeCe+jKjJeDiZLGd)�d*��ZMd+�ZNdS),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)�ABC�abstractmethod)�	b64encode)�cached_property)�iglob)�fsencode��Path)�ClassVar�Deque�List�Optional)�uuid4)�
inactivity)�Malware�MalwareScanIntensity)�g)�antivirus_mode�create_task_and_log_exceptions)�HOUR�
rate_limit)�serialize_attr�unserialize)�MalwareScanResourceType�MalwareScanType�QueuedScanState)�AiBolitDetachedScan)�AVDExecutionError�AppVersionDetector)�DetachedScan)�MDSDetachedScan)�MalwareDatabaseScanner)�panel_users)�period�on_drop�i��
intensity_cpu�intensity_io�
intensity_ram�i�i)�low�moderate�highc��eZdZUeeed<eed<dZdej	dddddddddd�de
dedee
dee
fd	�Zed
���Zeed�����Zd�Zd
�Zd�Zd�Zd�Zd�ZdZd�Zed���ZdS)�QueuedScanBase�
resource_type�
detached_scanN��scanid�	scan_type�created�started�	intensity�	home_dirsr(r)r*�	initiator�stater6r7r8r<c��||_|rt|}n$tjtjtjd�}|p|d|	p|d|
p|d|d�|_|pg}|tjkrt|��|vrtj
}|pt��j|_
||_|ptt!j����|_|�t$jnt%|��|_||_d|_dS)Nr'r(r)r*)r(r)r*r;)�path�INTENSITY_FALLBACKr�CPU�IO�RAM�argsr�	ON_DEMANDr
�USERr�hexr5r6�int�timer7r�queuedr<r8�scanner_task)�selfr>r5r6r7r8r9r:r(r)r*r;r<�_�intensity_fallbacks               �O/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/scan/queue.py�__init__zQueuedScanBase.__init__]s��"��	��	�!3�I�!>���"6�!9� 4� 7�!5�!9�"�"��+�3�!�/�2�(�N�,>�~�,N�*�3�!�/�2�"�

�
��	��O��	���1�1�1�d�4�j�j�I�6M�6M�'�,�I��+�������"����2�#�d�i�k�k�"2�"2���&+�m�O�"�"���9O�9O�	
�
���� �����c��
K�dS�N��rKs rN�startzQueuedScanBase.start�s�����rPc��dSrRrSrTs rN�total_resourceszQueuedScanBase.total_resources�s	��	
�rPc�J�|jr|j���dSdSrR�rJ�cancelrTs rN�stopzQueuedScanBase.stop��2����	'���$�$�&�&�&�&�&�	'�	'rPc���|jj|j|j|j|j|j|jjd�|j�}|jtj
kr|jj|d<|jj
|d<|S)N)�statusr>r5r8r7r6r2�phase�progress)r<�valuer>r5r8r7r6r2rCr�runningr3r_r`)rK�results  rNr^zQueuedScanBase.status�sz���j�&��I��k��|��|���!�/�5�	
�	
��i�	
���:��0�0�0�"�0�6�F�7�O�!%�!3�!<�F�:���
rPc�D�|j���}|d=|d=|S)Nr3rJ)�__dict__�copy�rKr<s  rN�__getstate__zQueuedScanBase.__getstate__�s*���
�"�"�$�$���/�"��.�!��rPc�H�|j�|��d|_dSrR)re�updaterJrgs  rN�__setstate__zQueuedScanBase.__setstate__�s&���
���U�#�#�#� ����rPc�B�|j|jko|j|jkSrR)r2r>)rK�others  rN�__eq__zQueuedScanBase.__eq__�s&����%�"5�5�
(��	�U�Z�'�	
rPc�X�d�|jj|j|j��S)Nz<{}({!r}, scanid={})>)�format�	__class__�__qualname__r>r5rTs rN�__repr__zQueuedScanBase.__repr__�s*��&�-�-��N�'���D�K�
�
�	
rPc	�|�|j|j|j|j|j|j|jj|jjd�S)N)r>r5r6r7r8rCr2r<)	r>r5r6r7r8rCr2rar<rTs rN�to_dictzQueuedScanBase.to_dict�s@���I��k����|��|��I�!�/�5��Z�%�	
�	
�		
rPc�x�|�di�����D]
\}}|||<�|di|��S)NrCrS)�pop�items)�cls�kwargs�argras    rN�	from_dictzQueuedScanBase.from_dict�sL�� �*�*�V�R�0�0�6�6�8�8�	 �	 �J�C���F�3�K�K��s�}�}�V�}�}�rP)�__name__�
__module__rrrr�__annotations__r r<rrD�strrGr�floatrOrrU�propertyrWr[r^rhrkrnrs�__hash__ru�classmethodr|rSrPrNr1r1Xsy��������3�4�4�4�4������E��(�2��#'�������#�0!�0!�0!�
�0!��
0!��%��0!���}�0!�0!�0!�0!�d�
�
��^�
���
�
��^��X�
�'�'�'���� ���!�!�!�
�
�
�
�
�
��H�

�

�

�����[���rPr1c���eZdZejZdejdddddddddddddd�dede	de
ef�fd�Z�fd�Z
d�Zd	�Zed
���Z�xZS)�QueuedFileScanN)r5r6r7r8r9r:r(r)r*�
file_patterns�exclude_patterns�follow_symlinks�
detect_elfr;r<r6r7r8c����t���|||||||||	|
||���|j�|pd|pd|
pd|���t	|j��|_dS)Nr4F)r�r�r�r�)�superrOrCrjrr5r3)rKr>r5r6r7r8r9r:r(r)r*r�r�r�r�r;r<rLrqs                  �rNrOzQueuedFileScan.__init__�s����*	������������'�%�'���	�
	
�
	
�
	
�	
�	���'�/�4�-�5��+�4�u�!�		�	
�	
�	
�1���=�=����rPc�|��t���|��t|j��|_dSrR)r�rkrr5r3�rKr<rqs  �rNrkzQueuedFileScan.__setstate__s5���	�����U�#�#�#�0���=�=����rPc���K�tj��|_ddlm}|tjd���}|j|jf|j|j	|jd�|j
��|_|����d{V��}|�2t�d|j��tj|_n?tj|_|j
�d��pt)|dd��|d<|S)	Nr)�MalwareScannerT)�sink�hooks)�scan_idr6r8zScan cancelled for %sr;�	undefined)rHr8�imav.malwarelib.scan.scannerr�rr�rUr>r5r6rCrJ�
async_wait�logger�infor�stoppedr<rb�get�getattr)rKr��scanner�	scan_datas    rNrUzQueuedFileScan.starts�����y�{�{���?�?�?�?�?�?� �.�a�f�D�9�9�9��)�G�M��I�
��K��n��L�	
�
�
�i�
�
���"�,�,�.�.�.�.�.�.�.�.�	����K�K�/���;�;�;�(�0�D�J�J�(�0�D�J��	�
�
�k�*�*�;��4��k�:�:�	
�k�"��rPc�J�|jr|j���dSdSrRrYrTs rNr[zQueuedFileScan.stop(r\rPc��|jjSrR�r3rWrTs rNrWzQueuedFileScan.total_resources,����!�1�1rP)r}r~rrr�FILEr2rrDr�rGrr�rOrkrUr[r�rW�
__classcell__�rqs@rNr�r��s��������+�0�M��(�2��#'������������%)>�)>�)>�
�)>��
)>��%��)>�)>�)>�)>�)>�)>�V>�>�>�>�>����:'�'�'��2�2��X�2�2�2�2�2rPr�c���eZdZejZdejddddddddf
dede	edede
de	ede	ef�fd�
Z�fd	�Z
ed
e
fd���Zd�Zdd
�Z�xZS)�QueuedDbScanNr>r5r6r7r8r9c
���t���|||||||||	|
|���t|j��|_dS)N)r>r5r6r7r8r9r:r(r)r*r<)r�rOr!r5r3)rKr>r5r6r7r8r9r:r(r)r*r<rLrqs             �rNrOzQueuedDbScan.__init__4sa��� 	������������'�%�'��	�	
�	
�	
�-�T�[�9�9����rPc�|��t���|��t|j��|_dSrR)r�rkr!r5r3r�s  �rNrkzQueuedDbScan.__setstate__Ss3���
�����U�#�#�#�,�T�[�9�9����rP�returnc��|jjSrRr�rTs rNrWzQueuedDbScan.total_resourcesWr�rPc
���K�|j�d��r|j�d��n|j}d�t|��D��}	tj�d��5t���|���d{V��ddd��n#1swxYwYt|j|jgfi|j
�|j|jd����
|j���d{V��dS#t$rZ}|j�t$j|j|j|j|j|j|j����d{V��Yd}~dSd}~wwxYw)Nz/*�*c�F�g|]}tt|������SrS)rr)�.0�ds  rN�
<listcomp>z&QueuedDbScan._scan.<locals>.<listcomp>cs&��L�L�L�a�9�X�a�[�[�1�1�L�L�LrP�AVD_scan)r6r�)r��	scan_pathr6�scan_started�cmd�out�err)r>�endswith�rstriprr�track�taskrrUr"rCr6r5�scanr8rr3�handle_aborted_processrr��commandr�r�)rK�	apps_path�unglobbed_paths�excs    rN�_scanzQueuedDbScan._scan[s-����&*�Y�%7�%7��%=�%=�L�D�I���S�!�!�!�4�9�	�M�L�5��;K�;K�L�L�L��	!��!�&�&�z�2�2�
B�
B�(�*�*�0�0��A�A�A�A�A�A�A�A�A�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B����
B�
B�
B�
B�)��	�������)���.��������d�4�<� � �

!�
!�
!�
!�
!�
!�
!�
!�
!��!�		�		�		��$�;�;��V��)��.�!�\��K��G��G�<���
�
�
�
�
�
�
�
�
�
�
�
�
�����		���s=�D�7(B+�D�+B/�/D�2B/�3D�
E'�
AE"�"E'c��K�tj��|_ttj��|j��|_dSrR)rHr8r�asyncio�get_event_loopr�rJrTs rNrUzQueuedDbScan.startzs;�����y�{�{���:��"�$�$�d�j�
�
����rP�r�N)r}r~rrr�DBr2rrDr�rrGr�rOrkr�rWr�rUr�r�s@rNr�r�1s�������+�.�M�
!%�(�2��#'�#'������:�:��:���
�:�
�:��
:��%��:��C�=�:�:�:�:�:�:�>:�:�:�:�:��2��2�2�2��X�2�!�!�!�>
�
�
�
�
�
�
�
rPr��_scans_info)r>�attrc��eZdZed���Zedeefd���Zed���Z	e
	ddefd���Ze
dd	���Z
d
�Zd�Zdeefd�Zdd
�Zd�Zdd�Zed���Zd�Zd�Zd�ZdS)�	ScanQueuec�H�tjd�|jD����S)Nc3�>K�|]}|���V��dSrR)ru)r��items  rN�	<genexpr>z(ScanQueue._scans_info.<locals>.<genexpr>�s*���� H� H�D������ H� H� H� H� H� HrP)�collections�deque�_scansrTs rNr�zScanQueue._scans_info�s$��� � H� H�D�K� H� H� H�H�H�HrPr�c�D�tj��}ttjtj���D]f}	t
|d}|�|�|�����?#t$r}td||��Yd}~�_d}~wwxYw|S)N)r>�fallbackr2z%Can't get scan class for %s due to %s)
r�r�r�Config�
SCANS_PATH�SCAN_TYPE_CLASSES�appendr|�	Exception�throttled_log_error)rK�scans�	scan_inforyr�s     rNr�zScanQueue._scans�s����!�#�#��$��"�[�->�
�
�
�
	�
	�I�
�'�	�/�(B�C�����S�]�]�9�5�5�6�6�6�6���
�
�
�#�;�Y��������������
����
�s�;A8�8
B�B�Bc�,�|�d��S�Nr)�peekrTs rN�current_scanzScanQueue.current_scan�s���y�y��|�|�rPFr2c��(��K�d�t���d{V��D���|tjkr��fd�|D��}nPtjr"|tjkrt
|����}n"td�|�����|rc|j	r\|j	�
��}|j	�t|����|j	�
|��dS|j	�|��dS)Nc�8�g|]}t|d����S)�homer	)r��users  rNr�z!ScanQueue.put.<locals>.<listcomp>�s$��H�H�H�D�T�$�v�,�'�'�H�H�HrPc�.��g|]}t|fd�i�����S�r:)r��r�r>r:�	scan_argss  ��rNr�z!ScanQueue.put.<locals>.<listcomp>�s>���2�2�2���t�F�F�y�F�I�F�F�2�2�2rPzUnknown resource_type: {})r#rr�r�disabledr��db_scans�
ValueErrorrpr��popleft�
extendleft�reversed�
appendleft�extend)rK�pathsr2�
prioritizer��scans_to_addrbr:s    `  @rN�putz
ScanQueue.put�s9������I�H�+�-�-�4G�4G�4G�4G�4G�4G�H�H�H�	��3�8�8�8�2�2�2�2�2�!�2�2�2�L�L�

�#�	P��!8�!;�;�;�#�E�9�i�@�@�L�L��8�?�?�
�N�N�O�O�O��	-�$�+�	-��k�)�)�+�+�G��K�"�"�8�L�#9�#9�:�:�:��K�"�"�7�+�+�+�+�+��K���|�,�,�,�,�,rPNc���t|��dkrdS|p|j}|j�|��|���t
�dt|����dS)NrzScans pending: %d)�lenr�r��remover[r�r��rKr�s  rNr�zScanQueue.remove�sg���t�9�9��>�>��F��(�t�(������4� � � ��	�	�������'��T���3�3�3�3�3rPc�\�d|cxkrt|��krndS|j|SdS)N����r�r�)rK�prioritys  rNr�zScanQueue.peek�sB��
��$�$�$�$�3�t�9�9�$�$�$�$�$�$��;�x�(�(�%�$rPc�*���fd�|jD��S)Nc�&��g|]
}|j�v�|��SrS)r5)r�r��scan_idss  �rNr�z&ScanQueue.find_all.<locals>.<listcomp>�s%���H�H�H����x�0G�0G��0G�0G�0GrP�r�)rKr�s `rN�find_allzScanQueue.find_all�s���H�H�H�H���H�H�H�HrPc�~��|jD]3�t�fd�|���D����r�cS�4dS)Nc�>��g|]\}}t�|��|k��SrS)r�)r��k�vr�s   �rNr�z"ScanQueue.find.<locals>.<listcomp>�s,���E�E�E�d�a��G�D�!�$�$��)�E�E�ErP)r��allrx)rKrzr�s  @rN�findzScanQueue.find�sT����K�	�	�D��E�E�E�E�f�l�l�n�n�E�E�E�F�F�
�����
��trPc�:�|jD]}|j|vr||_�dSrR)r�r5r<)rKr�r^r�s    rNrjzScanQueue.update�s2���K�	$�	$�D��{�h�&�&�#��
��	$�	$rPc#�PK�|jD]}|j|vr||jjfV��dSrR)r�r>r<ra)rKr�r�s   rN�get_scans_from_pathszScanQueue.get_scans_from_paths�sE�����J�	-�	-�D��y�E�!�!��D�J�,�,�,�,�,��	-�	-rPc�P�|p|j}tjd�|D����S)Nc3�K�|]D}|j|j|jj|j|j|jd|jd|jjd�	fV��EdS)Nr)	r>�scan_statusr6r8r7�errorrW�total_maliciousr2)	r5r>r<rar6r8r7rWr2)r�r�s  rNr�z+ScanQueue.scan_summaries.<locals>.<genexpr>�sz����'
�'
���� �I�#'�:�#3�!%��#�|�#�|�!�'+�';�'(�%)�%7�%=�
�
�

�'
�'
�'
�'
�'
�'
rP)r�r��OrderedDict)rKr�s  rN�scan_summarieszScanQueue.scan_summaries�sA���$�����&�'
�'
��'
�'
�'
�
�
�	
rPc�*�t|j��SrR)�listr�rTs rNr�zScanQueue.scans�s���D�K� � � rPc�2�t|j��dkSr�r�rTs rN�__bool__zScanQueue.__bool__�s���4�;���!�#�#rPc��||jvSrRr�r�s  rN�__contains__zScanQueue.__contains__s���t�{�"�"rPc�*�t|j��SrRr�rTs rN�__len__zScanQueue.__len__s���4�;���rP)FrRr�)r}r~rrr�r�rrr1r�r��serialize_scansrr�r�r�rrrrjr	rr�rrrrSrPrNr�r��s�������
�I�I��X�I����n�-�����_�� ����X���
�	-�-�/�-�-�-��_�-�:�4�4�4��_�4�)�)�)�I�I�I���� 8�����$�$�$�$�
-�-�-�

�
�
�
�(�!�!��X�!�$�$�$�#�#�#� � � � � rPr�c�$�����fd�|D��S)Nc�.��g|]}t|fd�i�����Sr�)r�r�s  ��rNr�zdb_scans.<locals>.<listcomp>s;������AE��T�<�<�Y�<�)�<�<���rPrS)r�r:r�s ``rNr�r�s4���������IN����rP)O�__doc__r�r��loggingrH�abcrr�base64r�	functoolsr�globr�osr�pathlibr
�typingrrr
r�uuidr�defence360agent.apir� defence360agent.contracts.configrr�r�&defence360agent.internals.global_scoper�defence360agent.utilsrr�defence360agent.utils.commonrr�#defence360agent.utils.serializationrr�imav.malwarelib.configrrr�&imav.malwarelib.scan.ai_bolit.detachedr�)imav.malwarelib.scan.app_version_detectorrr�imav.malwarelib.scan.detachedr �!imav.malwarelib.scan.mds.detachedr!� imav.malwarelib.scan.mds.scannerr"�imav.malwarelib.utils.user_listr#�	getLoggerr}r��warningr
r�r?r1r�r��State�
QueuedScanr�rr�rar�r�r�r�rSrPrN�<module>r7s�����*����������������#�#�#�#�#�#�#�#�������%�%�%�%�%�%�������������������2�2�2�2�2�2�2�2�2�2�2�2�������*�*�*�*�*�*���������5�4�4�4�4�4���������:�9�9�9�9�9�9�9�K�K�K�K�K�K�K�K�����������
��������������7�6�6�6�6�6�=�=�=�=�=�=�C�C�C�C�C�C�7�7�7�7�7�7�	��	�8�	$�	$��E�j�j��f�n�E�E�E�
�L�����������������
�
����&|�|�|�|�|�S�|�|�|�~W2�W2�W2�W2�W2�^�W2�W2�W2�tM
�M
�M
�M
�M
�>�M
�M
�M
�b	��
�
� �.�f�&7�m�L�L�L��� �&����$�l���x �x �x �x �x �x �x �x �v����rP

Hacked By AnonymousFox1.0, Coded By AnonymousFox