관리-도구
편집 파일: mrs_uploader.cpython-311.opt-1.pyc
� ��g� � �� � d Z ddlZddlmZmZ ddlmZ ddlmZ ddl m Z ddlmZ ddl mZ dd lmZ dd lmZ ddlmZmZmZ ddlmZ dd lmZ ee� � Z G d� dee� � ZdS )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)�CancelledError�Queue)�suppress)� getLogger)�List)� inactivity)�Malware)�LicenseError)�MessageType)�MessageSink� MessageSource�expect)�recurring_check)�malware_responsec �� � e Zd ZdZ ej d� � Zd� Zd� Zd� Z d� Z defd�Z e ej � � d � � � Z ed � � d� � � Zd� Z e ej � � d � � � ZdS )�MRSUploaderzFailed to submit a filez-(?:suspicious\..+|[CS]MW-SUS-.+|SMW-HEUR-ELF)c �, � t � � | _ d S �N)r � _upload_queue��selfs �Y/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/plugins/mrs_uploader.py�__init__zMRSUploader.__init__/ s � �"�W�W����� c � �~ K � || _ || _ |� | � � � � � | _ d S r )�_sink�_loop�create_task�upload�_upload_task)r �loop�sinks r � create_sourcezMRSUploader.create_source2 s8 � � � ��� ��� � �,�,�T�[�[�]�]�;�;����r c � � K � d S r � )r r! s r �create_sinkzMRSUploader.create_sink7 s � � � ��r c � � K � | j � � � t t � � 5 | j � d {V �� d d d � � d S # 1 swxY w Y d S r )r �cancelr r r s r �shutdownzMRSUploader.shutdown: s� � � � ��� � �"�"�"� �n� %� %� $� $��#�#�#�#�#�#�#�#� $� $� $� $� $� $� $� $� $� $� $� $���� $� $� $� $� $� $s �A�A�A�returnc �� � g }g }g }|� � � D ]�\ }}d}d}d} |d D ]_} || � dd� � z }|t | d o| j � | d � � � � z }| | d z } �`t j ||d � � }|r|� |� � ��|r|� |� � ��| r|� |� � ��|||fS )NF�hits�extended_suspicious� suspicious�matches�hash)�items�get�bool�SUSP_PATTERN�matchr �HitInfo�append)r �results� maliciousr. r- �file�data�is_extended_suspicious� is_suspicious�is_malicious�hit�hit_infos r �_separate_hits_by_typez"MRSUploader._separate_hits_by_type? s; � �� �� � ��!�-�-�/�/� +� +�J�D�$�%*�"�!�M� �L��F�|� 6� 6��&�#�'�'�2G��*O�*O�O�&�����%� @��)�/�/��I��?�?�"� "� � � �C��$5� 5�5���'�/��d�6�l�C�C�H�%� +�#�*�*�8�4�4�4�4�� +��!�!�(�+�+�+�+�� +�� � ��*�*�*���*�&9�9�9r c � � K � |d }|�d S t j st � d� � d S | � |� � \ }}}|r4| j � t j |d�� � � � � d {V �� |r4| j � t j |d�� � � � � d {V �� |r4| j � t j |d�� � � � � d {V �� |d � d� � }|rBd � |D � � }| j � t j |d �� � � � � d {V �� d S d S )Nr8 z"Uploading files to MRS is disabledr9 )r, � upload_reasonr. zextended-suspicious�summary�errorsc �P � g | ]#}t j |d |d � � ��$S )r: r0 )r r6 ��.0r? s r � <listcomp>z,MRSUploader.process_scan.<locals>.<listcomp>{ s= � � � � �� !�(��V��c�&�k�B�B�� � r � scan_error) �Config� SEND_FILES�logger�inforA r �process_messager �MalwareMRSUploadr2 )r �messager8 �malicious_hits�suspicious_hits�extended_suspicious_hitsrE � error_hitss r �process_scanzMRSUploader.process_scanW s � � � ��)�$���?��F�� � ��K�K�<�=�=�=��F� �'�'��0�0� ���$�� ��*�,�,��,�'�{�� � �� � � � � � � � � � ��*�,�,��,�(��� � �� � � � � � � � � $� ��*�,�,��,�1�"7�� � �� � � � � � � � � ��#�'�'��1�1��� �� �!�� � �J� �*�,�,��,�#�<�� � �� � � � � � � � � � � � r r c � � K � | j � � � � d {V ��\ }}} | � |||� � � d {V �� | j � � � n# | j � � � w xY w�zr )r r2 � _upload_files� task_done)r �filesrC rQ s r r zMRSUploader.upload� s� � � � � /�26�2D�2H�2H�2J�2J�,J�,J�,J�,J�,J�,J�)�E�=�'� /��(�(�� �w�G�G�G�G�G�G�G�G�G��"�,�,�.�.�.�.���"�,�,�.�.�.�.���� /s �A �A:c � �� K � t j � d� � 5 |D ]�} t j ||�� � � d {V �� � # t $ r'}t � d||� � Y d }~ n[d }~wt $ rK}d� | j |j � � }t � d||j � � Y d }~��d }~ww xY wd d d � � d S # 1 swxY w Y d S )N� mrs_upload)rC zCannot process message %s: %sz{}. {}z%s: %s) r �track�taskr �upload_with_retriesr rM �warning�FileNotFoundError�format�ERR_MSG�strerror�filename)r rZ rC rQ r: �e�errs r rX zMRSUploader._upload_files� sp � � � � � � "� "�<� 0� 0� >� >�� >� >�� >�*�>��M�� � � � � � � � � � �� $� � � ��N�N�#B�G�Q�O�O�O��E�E�E�E�E�����(� >� >� >�"�/�/�$�,�� �C�C�C��N�N�8�S�!�*�=�=�=�=�=�=�=�=�����>���� >� >� >� >� >� >� >� >� >� >� >� >���� >� >� >� >� >� >sM �C�A�C� C �A1�+C�1 C �>AC�?C�C � C�C� Cc � �0 �K � |d }|� dd� � }t j | j d� |D � � |� � � d {V ����st � d� � d S �fd�|D � � }| j � |||f� � d S )Nr, rC r. c 3 �$ K � | ]}|j V � �d S r )r0 rG s r � <genexpr>z+MRSUploader.process_hits.<locals>.<genexpr>� s$ � � � �2�2�c���2�2�2�2�2�2r z1All files are known to MRS. Skipping uploading...c 3 �8 �K � | ]}|j �v �|j V � �d S r )r0 r: )rH r? �unknown_hashess �r rj z+MRSUploader.process_hits.<locals>.<genexpr>� s1 �� � � �H�H�c�S�X��-G�-G���-G�-G�-G�-G�H�Hr )r2 r �check_known_hashesr rM rN r � put_nowait)r rQ r, rC rZ rl s @r �process_hitszMRSUploader.process_hits� s� �� � � �/6�v������O�\�B�B� �/�B��J�2�2�T�2�2�2�M� � � � � � � � �� � ��K�K�K�L�L�L��F�H�H�H�H�T�H�H�H����%�%�u�m�W�&E�F�F�F�F�Fr N)�__name__� __module__�__qualname__rc �re�compiler4 r r# r&