h:bdZddlmZddlZddlmZddlmZddlm Z m Z m Z m Z ddl mZddlmZdd lmZed d Gd d Zed d GddZed d GddZd dZd dZd!dZd!dZd dZd"dZdS)#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) dataclass)Path) CollectionIterableSetTuple) hosting_panel) to_thread) CloudwaysUserT)eqfrozenc$eZdZUded<ded<dS)MalwareDatabaseHitErrorintcodestrmessageN__name__ __module__ __qualname____annotations__T/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/scan/mds/report.pyrr"s" IIILLLLLrrceZdZUded<ded<ded<ded<ded<ded<ded <d ed <ded <ded <dZded<dZded<dZded<dZded<dZe ddZ e ddZ e d dZ e d!dZ dS)"MalwareDatabaseHitInforscan_idpath signatureapp_namedb_hostdb_namerdb_portz#Tuple[MalwareDatabaseHitError, ...]errorsowneruserN table_name table_field table_row_infsnippetcB|j|j|j|j|jfSN)r r"r#r%r$)selfs r _get_db_infoz#MalwareDatabaseHitInfo._get_db_info9s% I M L L L   rhits Iterable[MalwareDatabaseHitInfo]returnset[MalwareDatabaseHitInfo]ci}|D]}|}||vr|||< t|Sr.)r0setvalues)clsr1db_hitshitdb_infos rget_hits_per_dbz&MalwareDatabaseHitInfo.get_hits_per_dbBsW ' 'C&&((Gg%%#& 7>>##$$$rc d}d}|dp|d}|r%|d}|d}|d}|d} |d} tjt| | ||} ||| ||d |d |d t d |d D|d| | | S)NzBAD URLdetailed_reportsdetailed_urls_reportsrsigidsnptr app_owner_uidapp database_host database_namec3NK|] }t|d|dV!dSrrNr.0errs r z5MalwareDatabaseHitInfo.from_report..hsH(F S^DDr error_list database_port) rr r!r"r#r$r&r%r'r(r,)getr override_uid_by_pathrtuple) r8reportusers_from_panelpw_allrr!r,r>detailed_reportr r'r(s r from_reportz"MalwareDatabaseHitInfo.from_reportMs !::&899 VZZ #> >   2.q1O'0I%))&11G6NO,!6 JJ/  sE]?+?+!,/?+    rdatadictc +$K|dgD]v}|dgD]]}|dgD]D}|d |d|d|dt||dd|VE^wdS) Ntablesfieldsrow_idsr@tablefieldrA)r!r)r*r+r,r)rOr)r8rWkwargsr]r^row_ids r_get_hits_from_reportz,MalwareDatabaseHitInfo._get_hits_from_reportrsXXh++  E8R00  #ii 266F#"&w-#(>$)'N&)&kk $ 0 0  !    rc #K|d}|d}tjt||||}|||d|d|dtd|dD|d||d }|d x} r| D]} |j| fi|Ed{VdS|d gD]} |j| fi|Ed{VdS) Nr rBrCrDrEc3NK|] }t|d|dV!dSrGrHrIs rrLz?MalwareDatabaseHitInfo.iter_from_scan_report..sH(F S^DDrrMrN) rr r"r#r$r&r%r'r(r>r?)r rPrrQrOra) r8rRrSrTrr r'r(r_r>rUs riter_from_scan_reportz,MalwareDatabaseHitInfo.iter_from_scan_reportso 6NO,!6 JJ/   u o.o.!,/o.    &zz*<== =  P#3 P P434_OOOOOOOOOOOO P P$*::.Er#J#J P P434_OOOOOOOOOOOO P Pr)r1r2r3r4)r3r)rWrXr3r2)r3r2)rrrrr)r*r+r,r0 classmethodr<rVrardrrrrr(sMLLL IIINNNMMMLLLLLLLLL////JJJ IIIJKMG   %%%[%" " " [" H   [ PPP[PPPrrcBeZdZUded<ded<ded<ded<ded<dS) MalwareDatabaseScanReportzSet[MalwareDatabaseHitInfo]r1rstarted completedtotal_resourcestotal_maliciousNrrrrrgrgsH%%%%LLLNNNrrgreportsIterable[dict]r3rcRttd|DdS)Nc38K|]}|d|dzVdS) start_time running_timeNrrJrRs rrLz'_last_completed_time..sE  |$vn'==      rrdefault)rmaxrls r_last_completed_timerwsG    %         rcRttd|DdS)Nc3&K|] }|dV dS)rpNrrrs rrLz&_first_started_time..s'??VF<(??????rrrs)rminrvs r_first_started_timer{s, s??w???KKK L LLrc>ttd|S)Nc|dduS)NrCrrs rz_found..s5!5riterfilterrvs r_foundrs 55w?? @ @@rc>ttd|S)Nc|ddkS)N#count_of_detected_malicious_entriesrrr~s rrz_malicious..sa=>Brrrvs r _maliciousrs*  B B     rc4td|DS)Nc3BK|]}|ddVdS) rows_countrN)rOrrs rrLz&_total_scanned_rows..s0AAvvzz,**AAAAAAr)sumrvs r_total_scanned_rowsrs AAAAA A AArhit_report_listCollection[dict]rrc Kttjd{V}t t jd{V}t}tt|D]/}|tt ||||z}0t|}t|}t|}t|} t||||| Sr.)r6r HostingPanel get_usersr pwdgetpwallrrrrdr{rwrlenrg) rrrSrTr1rRrhrirjrks r scan_reportrs !;!=!=!G!G!I!IIIIIIIJJS\** * * * * * *F 55DVO4455    " 8 8(&'      "/22G$_55I)/::O$iiO $ gy/?  r)rlrmr3r)rlrmr3rm)rrrrr3rg)__doc__ __future__rr dataclassesrpathlibrtypingrrrr defence360agent.subsys.panelsr defence360agent.utils.threadsr imav.malwarelib.utils.cloudwaysr rrrgrwr{rrrrrrrrs*#""""" !!!!!!333333333333777777333333999999 d4   !   d4   xPxPxPxPxPxPxP! xPv d4   !     MMMMAAAABBBBr