hddZddlmZddlZddlmZmZddlmZm Z ddl m Z ddl m Z mZddlmZdd lmZdd lmZdd lmZdd lmZmZmZdd lmZddlmZe rddl m!Z!ee"e#e!fZ$e e%Z&GddeeZ'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 . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see ) annotationsN)CancelledErrorQueue) ExitStacksuppress) getLogger) TYPE_CHECKINGList) inactivity)Malware) LicenseError) MessageType) MessageSink MessageSourceexpect)recurring_check)malware_response)MalwareMRSUploadceZdZdZejdZdZdZdZ dZ dd Z e e jd Zed d ZddZe e jddZdS) MRSUploaderzFailed to submit a filez-(?:suspicious\..+|[CS]MW-SUS-.+|SMW-HEUR-ELF)c,t|_dSN)r _upload_queueselfs Y/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/plugins/mrs_uploader.py__init__zMRSUploader.__init__6s,1GGc~K||_||_|||_dSr)_sink_loop create_taskupload _upload_task)rloopsinks r create_sourcezMRSUploader.create_source9s8   ,,T[[]];;rc KdSr)rr%s r create_sinkzMRSUploader.create_sink>s  rcK|jtt5|jd{VddddS#1swxYwYdSr)r$cancelrrrs rshutdownzMRSUploader.shutdownAs   """ n % % $ $# # # # # # # # $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $sA  AAreturntuplec g}g}g}|D]\}}d}d}d} |dD]_} || ddz}|t| do|j| dz}| | d z} `t j||d} |r|| |r|| | r|| |||fS)NFhitsextended_suspicious suspiciousmatcheshash)itemsgetbool SUSP_PATTERNmatchrHitInfoappend) rresults maliciousr3r2filedatais_extended_suspicious is_suspicious is_malicioushithit_infos r_separate_hits_by_typez"MRSUploader._separate_hits_by_typeFs;   !--// + +JD$%* "!M LF| 6 6&#''2G*O*OO& %@)//I??"" C $5 55 '/d6lCCH% +#**84444 +!!(++++ +  ****&999rcK|d}|dStjstddS||\}}}|r4|jtj|dd{V|r4|jtj|dd{V|r4|jtj|dd{V|d d}|rBd |D}|jtj|d d{VdSdS) Nr=z"Uploading files to MRS is disabledr>)r1 upload_reasonr3zextended-suspicioussummaryerrorscPg|]#}tj|d|d$S)r?r5)rr;.0rDs r z,MRSUploader.process_scan..s=!(Vc&kBBr scan_error) Config SEND_FILESloggerinforFr process_messagerrr7)rmessager=malicious_hitssuspicious_hitsextended_suspicious_hitsrJ error_hitss r process_scanzMRSUploader.process_scan^s)$ ? F   KK< = = = F  ' ' 0 0    $  *,,,'{         *,,,(         $ *,,,1"7        #''11  !J*,,,#<           rrc\ K|jd{V\}}|d}tj|jd|D|}d}t 5}||jj|23d{V fd|D}|rXd} ||||d{V8#tj $r%}t d|Yd}~gd}~wwxYwp6 dddn #1swxYwY|rt ddSdS)Nr1c3$K|] }|jV dSr)r5rLs r z%MRSUploader.upload..s$22c222222rTc0g|]}|jv |jSr))r5r?)rMrDunknown_hashess rrNz&MRSUploader.upload..s.!$N0J0JCH0J0J0JrFzFailed to upload files: %sz1All files are known to MRS. Skipping uploading...) rr7rcheck_known_hashesr!rcallback task_done _upload_files UploadFailurerRerrorrS) rrHrUr1hashes_generator no_new_hashesstackfileser_s @rr#zMRSUploader.uploads $((** * * * * * *  07v+> J22T222M   [[ FE NN4-7 8 8 8(8 F F F F F F Fn(,F$)MF"00 wOOOOOOOOOO+9FFF %A1EEEEEEEEF F )9(8 F F F F F F F F F F F F F F F  M KKK L L L L L M MsH#"DC5 DB=<D=C1 C,'D,C11DD Dri list[str]rHstrrUrcKtjd5|D]} tj||d{V #t $r'}t d||Yd}~n[d}~wt$rK}d |j |j }t d||j Yd}~d}~wwxYwddddS#1swxYwYdS)N mrs_upload)rHzCannot process message %s: %sz{}. {}z%s: %s) r tracktaskrupload_with_retriesr rRwarningFileNotFoundErrorformatERR_MSGstrerrorfilename)rrirHrUr?rjerrs rrczMRSUploader._upload_filessr  " "< 0 0 > > > > >*>M$NN#BGQOOOEEEEE(>>>"//$, CCCNN8S!*========> > > > > > > > > > > > > > > > > > >sMCAC C A1+C1 C >AC?CC  CC CcnK|dd}|j||fdS)NrHr3)r7r put_nowait)rrUrHs r process_hitszMRSUploader.process_hitss; O\BB  %%}g&>?????rN)r.r/)rirkrHrlrUr)rUr)__name__ __module__ __qualname__rurecompiler9rr'r*r-rFrr MalwareScanrZrr#rcrr{r)rrrr2s'G2:NOOL444<<<    $$$ ::::0 VK #$$++%$+Z_QMMM8>>>>  VK ())@@@*)@@@rr)(__doc__ __future__rrasynciorr contextlibrrloggingrtypingr r defence360agent.apir defence360agent.contracts.configr rP!defence360agent.contracts.licenser "defence360agent.contracts.messagesr!defence360agent.contracts.pluginsrrrdefence360agent.utilsrimav.malwarelib.utilsrimav.contracts.messagesrr/rl UploaderQueuer|rRrr)rrrs*#""""" ))))))))********&&&&&&&&******>>>>>>:::::::::::: 2111112222228888888%%5 567M 8  J@J@J@J@J@+}J@J@J@J@J@r