0M7EdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z ddl m Z mZmZmZddlmZmZmZddlmZdd lmZmZdd lmZdd lmZdd lmZm Z dd l!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ej*e+Z,dZ-e.ej/d0Z1e2e3e fZ4e dGddZ5GddeeZ6GddeeZ7dS)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)AbstractEventLoop) defaultdict) dataclassfield)Any AsyncIteratorIterablecast)Message Reportable ReportTarget)get_myimunify_users) MessageSink MessageSource) AbstractPanel) HostingPanel) load_state save_state)Scoperecurring_checksafe_cancel_tasksplit_for_chunk)MalwareHitStatus) MalwareHiti,)daysT)slotscneZdZUdZeeZeeee fe d<dZ e e d<dZ e e d<dS) ProcessedHitsz"Result of processing malware hits.)default_factoryfilesrinfected_count cleaned_countN)__name__ __module__ __qualname____doc__rlistr!dictstrr__annotations__r"intr#^/opt/imunify360/venv/lib/python3.11/site-packages/imav/plugins/send_malware_infection_state.pyrr<sb,,"'%"="="=E4S#X ===NCM3r.rc eZdZdZejZdS)MalwareInfectionStateMALWARE_STATE_SNAPSHOTSN)r$r%r&DEFAULT_METHODr APITARGETr-r.r/r1r1Es.N  FFFr.r1c^eZdZejZdZdZdZde fdZ de fdZ dZ e dedefd Zd(d eezd zfd Zdefd ZdZdZe dedefdZdedeeeffdZdeedefdZ d)dedededeeeefdedededeed zdefdZ d)deedededededeed zde!efd Z"e d!ed"e#edefd#Z$de!efd$Z%deedededede!ef d%Z&deedededed&e'de!ef d'Z(d S)*SendMalwareInfectionStateic"d|_d|_dS)Nr)_task_last_send_timestampselfs r/__init__z"SendMalwareInfectionState.__init__Os $%!!!r.loopc KdSNr-)r<r>s r/ create_sinkz%SendMalwareInfectionState.create_sinkSs  r.cK||_||_|t t |j|_dSr@)_sink_load_last_send_timestampr: create_taskrRECURRING_CHECK_INTERVAL_check_and_sendr9)r<r>sinks r/ create_sourcez'SendMalwareInfectionState.create_sourceVs^ $($B$B$D$D!%% K 5O4 5 5d6J K K M M   r.cdK|j&d|jc|_}t|d{VdSdSr@)r9r)r<ts r/shutdownz"SendMalwareInfectionState.shutdown]sK : ! $*MDJ"1%% % % % % % % % % % " !r. timestampreturncFt|ttfo|dkS)z.Check if timestamp is a valid positive number.r) isinstancer,float)rMs r/_is_valid_timestampz-SendMalwareInfectionState._is_valid_timestampbs!)c5\22EyA~Er.Ntsc||jn|}||std|dSt |jd|idS)z1Save the last send timestamp to persistent state.Nz'Invalid timestamp to save: %s, skippinglast_send_timestamp)r:rRloggerwarningr STATE_KEY)r<rSrMs r/_save_last_send_timestampz3SendMalwareInfectionState._save_last_send_timestampgsi13D-- '' 22  NN99    F4>$99#EFFFFFr.ct|jd}||stddSt t|S)z3Load the last send timestamp from persistent state.rUz>>GAt  18<<<!%!=!=c8S""       g " "&!@!@c8S"""       g ""7  s*$B%C#' C#0)CC#4EE(c\K|||||dg23d{V}|WV 6dS)z+Generate messages aggregated at user level.rsr|rrrrrN)r)r<r|rrrrfs r/rz1SendMalwareInfectionState._generate_user_messagessu"<<!# =         'MMMMM   s+rc NK||d{V}tt}|D]'}||j|j(tt} |D][} | dd} || |} | | | \| D]B\} }| ||||| || g23d{V}|WV 6CdS)z4Generate messages aggregated at document root level.Nrrrsr) get_user_domains_detailsrr(rr~domainr[rkeysitemsr)r<r|rrrrdomain_detailsdocroot_to_domains domain_datadocroot_to_hitsrprrr docroot_hitsrfs r/rz4SendMalwareInfectionState._generate_docroot_messages,s "::8DDDDDDDD;Fd:K:K) O OK {2 3 : :;;M N N N NCN C C  9 9C++I"99-2244O O , 3 3C 8 8 8 8&5%:%:%<%<   !G\!%!@!@!!%,/33GR@@ "A""       g ""  sD#r@)rsN))r$r%r&rAV_IM360SCOPErrXr=rrArIrL staticmethodrboolrRr,rQrYrDrGr`r*roMalwareHitDictr)r{r(rrr1rrrr rrdrrrr-r.r/r7r7Js NEJ+I&&& &7     (9    &&& FsFtFFF\FGGC%K$,>GGGG&5&&&& - - -666 C C   \   ^  S#X     $~"6=2%')-   $sCx.)   "3i$& :%')->"    " 3i$& , -4 # # 3   \ (-8M*N((((T ( /4 @C JM  , -    &>"&& &  &  & , -&&&&&&r.r7)8r'datetimeloggingrr^asyncior collectionsr dataclassesrrtypingrrr r "defence360agent.contracts.messagesr r r &defence360agent.contracts.myimunify_idr!defence360agent.contracts.pluginsrr"defence360agent.subsys.panels.baser+defence360agent.subsys.panels.hosting_panelr'defence360agent.subsys.persistent_staterrdefence360agent.utilsrrrrimav.malwarelib.configrimav.malwarelib.modelr getLoggerr$rVrFr, timedelta total_secondsr_r)r*rrr1r7r-r.r/rs* %%%%%%######((((((((555555555555 GFFFFFHHHHHHHH<<<<<<DDDDDDJJJJJJJJ 433333,,,,,,  8 $ $"&H&A...<<>>?? c3h GZ HHHHH ]HHHHHr.