h>dZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddlmZddlmZmZmZdd lmZmZmZdd lmZdd lmZdd lmZmZdd lm Z ej!e"Z#GddZ$GddeeZ%GddeZ&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 N) defaultdict)Hashable)suppress) inactivity) MessageType) MessageSink MessageSourceexpect)batched nice_iteratorrecurring_check)VulnerabilityHitStatus)VulnerabilityHit) PatchResultVulnerabilityPatcher) PatchStoragecLeZdZdZdedefdZdeeeffdZde fdZ dS) PatchQueuec8tt|_dSN)rset_queueselfs b/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/plugins/patch_vulnerabilities.py__init__zPatchQueue.__init__3s!#&& keyvaluesc0|j|xx|zcc<dSr)r)rrrs rputzPatchQueue.put6s& CF"rreturnc |jS#t$r}tj|d}~wwxYwr)rpopitemKeyErrorqueueEmpty)rexcs rgetzPatchQueue.get9sH );&&(( ( ) ) )+--S ( )s >9>c,t|j Sr)boolrrs remptyzPatchQueue.empty?s $$$$rN) __name__ __module__ __qualname__rrrr!tupler)r+r,rrrr2s'''#x#####)U8S=))))) %t%%%%%%rrceZdZfdZdZdZdZeej de fdZ dZ e dd ZxZS) Patchctj|i|t|_d|_d|_d|_d|_dSr)superrrr_loop_sink_patcher _patch_task)rargskwargs __class__s rrzPatch.__init__DsM$)&))) ll    rc KdSrr1rloops r create_sinkzPatch.create_sinkL  rcK||_||_t|||_|||_dS)N)r?sink)r6r7rr8 create_taskrecurring_patchr9)rr?rCs r create_sourcezPatch.create_sourceOsP  ,$TBBB ++D,@,@,B,BCCrcK|jrZ|jttj5|jd{VddddS#1swxYwYdSdSr)r9cancelrasyncioCancelledErrorrs rshutdownzPatch.shutdownUs   '   # # % % %'011 ' '&&&&&&&& ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'sAAAmessagecK|d|d|ddf}|dg}|j|t|dS)Ncause initiatormanualFfilelist)r)rr!r)rrLsourcefiles_to_patchs rprocess_patch_taskzPatch.process_patch_task[sw KK KK $ $ KK% ( (  !Z44 N 3 344444rcK|js|j\\}}}}t|dD]g}tjd5tjg}|r| tj tj tj|tj|}t#j|d{V\}} } | rz| D]w} |jt+jd| jt"jt3t5jd{Vx| rtjd| Dtj|d} | D]\} }t5j}d |D}tj|tj|j !| |d{V\}}}|jt+j"||tGj$j%||||| d{V dddn #1swxYwYi|jdSdS) Ni')npatch_vulnerabilitiesz*Failed to store the original from {} to {})rL timestampcg|] }|j Sr1 orig_file.0hits r z0Patch._patch_vulnerabilities..s@@@sS]@@@rowner) attributecg|] }|j Sr1rZr\s rr_z0Patch._patch_vulnerabilities..s ? ? ?3 ? ? ?r)hitsresult cleanup_idstartederrorrNrOr:)&rr,r)r rtracktaskr VULNERABLEappendREVERTEDrselectwherer[in_statusr store_allr7process_messagerVulnerabilityPatchFailedformatpathinttime delete_hitsgroup_by_attributeitems set_statusPATCH_IN_PROGRESSr8startVulnerabilityPatchuuiduuid4hex)rrNrOrPrS files_batchvulnerable_statusesrc succeededfailed not_existr^ user_hitsuserrffilesrdrgcmds r_patch_vulnerabilitieszPatch._patch_vulnerabilitieses+##%%< 9=9J9J 6 &UIv&~@@@: :  %**+BCC99+A+L*M'+222;,244::(266{CC(/334GHHD+4T:::::::: !! #)  C"&*"<"< + D)117,/M<;L2*2*/2$)++.>.>!"!"!" # #        !(4@@i@@@!1 C!")!!!I'0oo&7&7 d"&)++ ? ?$ ? ? ?(3 "8"J48=3F3F %44......*s#j88':%)'-+/:<<+;(/&+&+*3%(             I999999999999999+##%%< < < < < s0H-J**J. 1J. ctK|js|d{VdSdSr)rr,rrs rrEzPatch.recurring_patchsP{  "" 0--// / / / / / / / / / 0 0r)r-r.r/rr@rFrKr rVulnerabilityPatchTaskdictrTrr rE __classcell__)r<s@rr3r3Cs        DDD '''  VK .//55550/5===~_Q0000000rr3c|eZdZdZe ddeedefdZe e j de fdZ dS) PatchResultProcessorc KdSrr1r>s rr@z PatchResultProcessor.create_sinkrArNrcrpcXtj||||D]}||_||_dSr)rr{rp patched_at)rcrprr^s r_set_hit_statusz$PatchResultProcessor._set_hit_statussB #D&*=== ( (CCJ'CNN ( (rrLc K|d}|d tj} fd|D} fd|D}g}t|d23d{V} |rD|jr||P||f6|rt jd|Dgg} }|D]G} |r||2| |H| |tj ||| zx} r"| | tj dSdS)Nrcrdcg|]}|v| Sr1r1r]r^rds rr_z=PatchResultProcessor.process_patch_result..s:::SC6MMSMMMrcg|]}|v| Sr1r1rs rr_z=PatchResultProcessor.process_patch_result..s#@@@sc.?.?s.?.?.?rd) chunk_sizecg|] }|j Sr1rZr\s rr_z=PatchResultProcessor.process_patch_result..s)M)M)MC#-)M)M)Mr) rwr rorig_file_pathexistsrkrrx is_patchedrrPATCHEDrj) rrLrcnow processed unprocessedrr^patchedrunable_to_pathrds @rprocess_patch_resultz)PatchResultProcessor.process_patch_results'.v%h/ikk::::D::: @@@@d@@@  &ySAAA * * * * * * *#c{$$&& *%,,..*&&s++++$$S)))B  O  ()M)M9)M)M)M N N Nb # #Cc{%%'' #s#### c"""" W&<&DcJJJ(61 1>    6 A       sB<r)r-r.r/r@ staticmethodlistrstrrr rr~rrr1rrrrs   >B((#$(.1(((\( VK *++$,+rr)'__doc__rIloggingrwr&r collectionsrcollections.abcr contextlibrdefence360agent.apir"defence360agent.contracts.messagesr!defence360agent.contracts.pluginsrr r defence360agent.utilsr r r imav.malwarelib.configrimav.malwarelib.modelr'imav.malwarelib.vulnerabilities.patcherrr'imav.malwarelib.vulnerabilities.storager getLoggerr-loggerrr3rr1rrrs* ######$$$$$$******:::::: JIIIIIIIII999999222222A@@@@@  8 $ $%%%%%%%%"d0d0d0d0d0Kd0d0d0N-----;-----r