@@ -729,12 +729,19 @@ class ExploitScanner:
729729 def __init__ (self , signatures : Sequence [Signature ] | None = None ) -> None :
730730 self .signatures : list [Signature ] = list (signatures ) if signatures is not None else load_signatures ()
731731 self ._flows : dict [tuple [str , int | None , str , int | None , str ], _FlowState ] = {}
732+ logger .debug (
733+ "ExploitScanner: {} signature(s) ({}), dont {} a detecteur structurel" ,
734+ len (self .signatures ),
735+ "fournies" if signatures is not None else "base par defaut" ,
736+ sum (1 for sig in self .signatures if sig .detector is not None ),
737+ )
732738
733739 def _state (self , pkt : PacketLike ) -> _FlowState :
734740 key = (pkt .src , pkt .sport , pkt .dst , pkt .dport , pkt .proto )
735741 state = self ._flows .get (key )
736742 if state is None :
737743 if len (self ._flows ) >= MAX_TRACKED_FLOWS :
744+ logger .trace ("ExploitScanner._state: {} flux suivis, eviction du plus ancien" , len (self ._flows ))
738745 del self ._flows [next (iter (self ._flows ))] # evince le flux le plus ancien
739746 state = self ._flows [key ] = _FlowState ()
740747 return state
@@ -781,6 +788,16 @@ def scan_packet(self, pkt: PacketLike, point: str = "") -> list[Detection]:
781788 else :
782789 hit = self ._match_pattern (sig , view )
783790 if hit is not None :
791+ logger .trace (
792+ "scan_packet: signature {} sur la trame {} ({}:{} -> {}:{}), cible {}" ,
793+ sig .id ,
794+ pkt .frame_number ,
795+ pkt .src ,
796+ pkt .sport ,
797+ pkt .dst ,
798+ pkt .dport ,
799+ hit [0 ],
800+ )
784801 detections .append (
785802 Detection (
786803 signature_id = sig .id ,
@@ -807,8 +824,18 @@ def scan_packet(self, pkt: PacketLike, point: str = "") -> list[Detection]:
807824 def scan_packets (self , packets : Iterable [PacketLike ], point : str = "" ) -> list [Detection ]:
808825 """Detections pour des paquets fournis dans l'ordre de capture."""
809826 detections : list [Detection ] = []
827+ scanned = 0
810828 for pkt in packets :
829+ scanned += 1
811830 detections .extend (self .scan_packet (pkt , point ))
831+ logger .debug (
832+ "scan_packets: point {!r}, {} paquet(s), {} detection(s) sur {} signature(s) distincte(s), {} flux suivis" ,
833+ point ,
834+ scanned ,
835+ len (detections ),
836+ len ({d .signature_id for d in detections }),
837+ len (self ._flows ),
838+ )
812839 return detections
813840
814841
@@ -825,7 +852,9 @@ def detect_exploits(
825852
826853def detections_to_dicts (detections : Iterable [Detection ]) -> list [dict [str , Any ]]:
827854 """Serialisation JSON stable (sans charge utile)."""
828- return [asdict (d ) | {"cves" : list (d .cves )} for d in detections ]
855+ out = [asdict (d ) | {"cves" : list (d .cves )} for d in detections ]
856+ logger .debug ("detections_to_dicts: {} detection(s)" , len (out ))
857+ return out
829858
830859
831860__all__ = [
0 commit comments