@@ -303,18 +303,40 @@ def get_instance_name_from_tags(instance):
303303
304304 @staticmethod
305305 def _get_vulnerable_ports (protocol_display : str , raw_rule : dict , vulnerable_ports : str ):
306- try :
307- ports = [int (port .strip ()) for port in vulnerable_ports .split (',' )]
306+ # try:
307+ # ports = [int(port.strip()) for port in vulnerable_ports.split(',')]
308+ #
309+ # if protocol_display == "ALL":
310+ # return ports
311+ #
312+ # to_port = raw_rule.get("ToPort")
313+ # from_port = raw_rule.get("FromPort")
314+ #
315+ # if to_port is None or from_port is None:
316+ # return None
317+ #
318+ # filtered_ports = [str(port) for port in ports if from_port <= port <= to_port]
319+ #
320+ # return filtered_ports if filtered_ports else None
321+ # except ValueError:
322+ # raise ERROR_VULNERABLE_PORTS(vulnerable_ports)
308323
309- if protocol_display == "ALL" :
310- return ports
324+ try :
325+ ports = []
311326
312327 to_port = raw_rule .get ("ToPort" )
313328 from_port = raw_rule .get ("FromPort" )
314329
315- if to_port is None or from_port is None :
316- return []
330+ if protocol_display != "ALL" and (to_port is None or from_port is None ):
331+ return None
332+
333+ for port in vulnerable_ports .split ("," ):
334+ target_port = int (port )
317335
318- return [port for port in ports if from_port <= port <= to_port ]
336+ if protocol_display == "ALL" :
337+ ports .append (port )
338+ elif from_port <= target_port <= to_port :
339+ ports .append (port )
340+ return ports if ports else None
319341 except ValueError :
320342 raise ERROR_VULNERABLE_PORTS (vulnerable_ports )
0 commit comments