Answer :
Python script that identifies malicious IPv4 addresses starting with "99.8." and IPv6 addresses matching the pattern "2610:a1:::*", capturing the last character of each to form the Flag in the format HQ8{IP_characters}.
import re
def is_valid_ipv4(ip):
parts = ip.split('.')
return len(parts) == 4 and all(0 <= int(part) <= 255 for part in parts)
def is_valid_ipv6(ip):
try:
# Using inet_pton to validate IPv6 format
socket.inet_pton(socket.AF_INET6, ip)
return True
except socket.error:
return False
def identify_malicious_ips(ip_list):
malicious_ipv4 = []
malicious_ipv6 = []
for ip in ip_list:
if ip.startswith("99.8.") and is_valid_ipv4(ip):
malicious_ipv4.append(ip)
elif re.match(r'^2610:a1:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}$', ip) and is_valid_ipv6(ip):
malicious_ipv6.append(ip)
return malicious_ipv4, malicious_ipv6
def capture_last_character(ip_list):
return [ip[-1] for ip in ip_list]
# Example usage
if __name__ == "__main__":
# Assuming ip_addresses.txt contains the list of IPs, one per line
with open("ip_addresses.txt", "r") as file:
ip_addresses = [line.strip() for line in file]
malicious_ipv4, malicious_ipv6 = identify_malicious_ips(ip_addresses)
# Capture the last character of each identified IP
flag_characters = capture_last_character(malicious_ipv4 + malicious_ipv6)
# Form the Flag
flag = "HQ8{" + ''.join(flag_characters) + "}"
print("Malicious IPv4 Addresses:", malicious_ipv4)
print("Malicious IPv6 Addresses:", malicious_ipv6)
print("Flag:", flag)
the script utilizes Python to identify malicious IPv4 and IPv6 addresses from a given list, capturing the last character of each to construct a Flag in the format HQ8{IP_characters}.