.dZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZmZmZddlmZmZmZmZdd lmZdd lmZdd lmZmZdd lmZeje Z!Gd dZ"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) inactivity) MessageType) MessageSink MessageSourceexpect)batched nice_iteratorrecurring_checksafe_cancel_task)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__5s!#&& keyvaluesc0|j|xx|zcc<dSr)r)rrrs rputzPatchQueue.put8s& CF"rreturnc |jS#t$r}tj|d}~wwxYwr)rpopitemKeyErrorqueueEmpty)rexcs rgetzPatchQueue.get;sH );&&(( ( ) ) )+--S ( )s >9>c,t|j Sr)boolrrs remptyzPatchQueue.emptyAs $$$$rN) __name__ __module__ __qualname__rrrr!tupler)r+r,rrrr4s'''#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__FsM$)&))) ll    rc KdSrr1rloops r create_sinkzPatch.create_sinkN  rcK||_||_t|||_|||_dS)N)r?sink)r6r7rr8 create_taskrecurring_patchr9)rr?rCs r create_sourcezPatch.create_sourceQsP  ,$TBBB ++D,@,@,B,BCCrcPK|jrt|jd{VdSdSr)r9r rs rshutdownzPatch.shutdownWsD   5"4#344 4 4 4 4 4 4 4 4 4 5 5rmessagecK|d|d|ddf}|dg}|j|t|dS)Ncause initiatormanualFfilelist)r)rr!r)rrIsourcefiles_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 {})rI timestampcg|] }|j Sr1 orig_file.0hits r z0Patch._patch_vulnerabilities..s@@@sS]@@@rowner) attributecg|] }|j Sr1rWrYs rr\z0Patch._patch_vulnerabilities..s ? ? ?3 ? ? ?r)hitsresult cleanup_idstartederrorrKrLr:)&rr,r)r rtracktaskr VULNERABLEappendREVERTEDrselectwhererXin_statusr store_allr7process_messagerVulnerabilityPatchFailedformatpathinttime delete_hitsgroup_by_attributeitems set_statusPATCH_IN_PROGRESSr8startVulnerabilityPatchuuiduuid4hex)rrKrLrMrP files_batchvulnerable_statusesr` succeededfailed not_existr[ user_hitsuserrcfilesrardcmds 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@rFrHr rVulnerabilityPatchTaskdictrQrr rE __classcell__)r<s@rr3r3Es        DDD 555 VK .//55550/5===~_Q0000000rr3c|eZdZdZe ddeedefdZe e j de fdZ dS) PatchResultProcessorc KdSrr1r>s rr@z PatchResultProcessor.create_sinkrArNr`rmcXtj||||D]}||_||_dSr)rrxrm patched_at)r`rmrr[s r_set_hit_statusz$PatchResultProcessor._set_hit_statussB #D&*=== ( (CCJ'CNN ( (rrIc 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)Nr`racg|]}|v| Sr1r1rZr[ras rr\z=PatchResultProcessor.process_patch_result..s:::SC6MMSMMMrcg|]}|v| Sr1r1rs rr\z=PatchResultProcessor.process_patch_result..s#@@@sc.?.?s.?.?.?rd) chunk_sizecg|] }|j Sr1rWrYs rr\z=PatchResultProcessor.process_patch_result..s)M)M)MC#-)M)M)Mr) rtr rorig_file_pathexistsrhrru is_patchedrrPATCHEDrg) rrIr`now processed unprocessedrr[patchedrunable_to_pathras @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__loggingrtr&r| collectionsrcollections.abcrdefence360agent.apir"defence360agent.contracts.messagesr!defence360agent.contracts.pluginsrrr defence360agent.utilsr r r r imav.malwarelib.configrimav.malwarelib.modelr'imav.malwarelib.vulnerabilities.patcherrr'imav.malwarelib.vulnerabilities.storager getLoggerr-loggerrr3rr1rrrs* ######$$$$$$******::::::  :99999222222A@@@@@  8 $ $%%%%%%%%"b0b0b0b0b0Kb0b0b0J-----;-----r