hIdZddlmZddlmZddlmZddlmZ ddl m Z ddl m Z ddlmZmZmZdd lmZdd lmZdd lmZdd lmZmZeeZGd deeZdS)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 . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see ) defaultdict) getLogger)List)Malware) LicenseError) MessageType) MessageSink MessageSourceexpect)get_results_iterable_expression) MalwareHit)malware_response)FileTooLargeError UploadFailureceZdZdZdZeejdZde fdZ e dZ e de de efdZd S) MalwareResponsePluginc&K||_||_dSN)_loop_sink)selfloopsinks ]/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/plugins/malware_response.py create_sourcez#MalwareResponsePlugin.create_source.s  cK||_dSr)r)rrs r create_sinkz!MalwareResponsePlugin.create_sink2s rcK||j}|tjj}|r||d{VdSdSr)_collect_hashesfilesrMalwareResponseUNKNOWNlower_process_unknown_hash)rmessagehashesunknown_hashess r process_message_malware_responsez6MalwareResponsePlugin.process_message_malware_response5su%%gm44 ; C I I K KL  =,,^<< < < < < < < < < < = =rr'chKtjstddS||}|D]}td| t j|d{V9#t$r(}td||Yd}~dSd}~wt$r&}t d||Yd}~d}~wt$rtd|Yt$r&}td||Yd}~d}~wwxYwdS)z If there is no such file with given hash in database, Imunify360 Client should upload file using API endpoint /api/v1/upload. z)Sending unknown files to MRS is disabled.Nz"Unknown file %s. Uploading to MRS.z/Cannot upload the following files to MRS %r: %szFile %s uploading failed. %s.z#File %s not found, skipping upload.) Config SEND_FILESloggerinfo_get_orig_filesrupload_with_retriesrwarningrerrorFileNotFoundErrorr)rr' orig_files orig_filees rr%z+MalwareResponsePlugin._process_unknown_hash<s    KKC D D D F))&11 # N NI KK 1MMMMMMMM N# N Ns6 A;; D/B(( D/5C(D/ D/ D**D/ctt}|D]2\}}|||3|Sr)rsetitemsr$add)r! type_to_hash file_hash hash_types rr z%MalwareResponsePlugin._collect_hashes[sW"3'' $)KKMM ; ; Iy ** + / / : : : :rreturncg}d}t||D]M} ||j#t$r#td|jYJwxYw|S)Nctjtj|Sr)r selectwherehashin_)r's r expressionz9MalwareResponsePlugin._get_orig_files..expressionfs/$&&,,Z_-@-@-H-HII IrzFile %s not found, skipping.)r appendr5r3r-r1)r'resultrEhits rr/z%MalwareResponsePlugin._get_orig_filesbs J J J3:vFF N NC N cm,,,,$ N N N=s}MMMMM N s4*A! A!N)__name__ __module__ __qualname__rrr rr"r)r8r% staticmethodr rstrr/rrrr-s VK '((==)(= N#NNNN>\   S   \   rrN)__doc__ collectionsrloggingrtypingr defence360agent.contracts.configrr+!defence360agent.contracts.licenser"defence360agent.contracts.messagesr!defence360agent.contracts.pluginsr r r defence360agent.utilsr imav.malwarelib.modelr imav.malwarelib.utilsr&imav.malwarelib.utils.malware_responserrrIr-rrNrrr[sa*$#####>>>>>>:::::::::::: BAAAAA,,,,,,222222 8  AAAAAKAAAAAr