Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScannerInterface.py
More file actions
Latest commit
60 lines (51 loc) · 2.53 KB
/
Copy pathScannerInterface.py
File metadata and controls
60 lines (51 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
fromabcimportABC, abstractmethod
fromtypingimportList, Dict, Tuple, TypedDict, TYPE_CHECKING
ifTYPE_CHECKING:
fromProcessManagerimportProcessManager
# Alias de type pour le retour des méthodes scan
# ScanResult = Tuple[str, bool, Optional[str], Dict, Dict[str, str]]
ScanResult=Tuple[str, bool, strorNone, dict, TypedDict]
classScannerInterface(ABC):
def__init__(self, strategy: str, yaml_file: str, process_manager: 'ProcessManager'):
self.strategy=strategy
self.yaml_file=yaml_file
self.process_manager=process_manager
self.strategies=self.load_strategies()
self.ports=None
ifstrategynotinself.strategies:
raiseValueError(f"Stratégie inconnue : {strategy}. Options valides : {list(self.strategies.keys())}")
@abstractmethod
defload_strategies(self) ->Dict[str, any]:
"""Charge les stratégies depuis le fichier YAML. Retourne un dictionnaire."""
pass
@abstractmethod
defscan(self, ip: str, thread_id: str, event_queue, stop_flag) ->ScanResult:
"""
Effectue un scan sur une IP donnée et retourne un tuple avec un format standardisé :
- ip (str): L'adresse IP scannée.
- success (bool): True si le scan a réussi, False sinon.
- error (Optional[str]): Message d'erreur si le scan échoue, None sinon.
- details (Dict): Détails du scan, incluant au moins {"ports": [int]} (liste des ports ouverts).
- extra (Optional[str]): Informations supplémentaires (non utilisé ici, mais pour compatibilité future).
"""
pass
# noinspection PyMethodMayBeStatic
defparse_ports(self, port_string: str) ->List[int]:
"""Parse une chaîne de ports au format Nmap (ex. '80,443' ou '1-1000')."""
ports= []
items=port_string.split(',')
foriteminitems:
item=item.strip()
if'-'initem:
start, end=map(int, item.split('-'))
ifnot (1<=start<=65535and1<=end<=65535):
raiseValueError(f"Ports hors limites (1-65535) dans la plage {item}")
ifstart>end:
raiseValueError(f"Plage invalide dans {item}: début > fin")
ports.extend(range(start, end+1))
else:
port=int(item)
ifnot (1<=port<=65535):
raiseValueError(f"Port hors limites (1-65535): {port}")
ports.append(port)
returnsorted(list(set(ports)))