misp-warninglists/tools/generate-amazon-aws.py

39 lines
1.2 KiB
Python
Raw Normal View History

2018-02-21 22:50:13 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
2021-06-12 12:13:23 +02:00
from generator import download_to_file, get_version, write_to_file, get_abspath_source_file, consolidate_networks
def process(file, dst):
with open(get_abspath_source_file(file), 'r') as json_file:
amazon_aws_ip_list = json.load(json_file)
l = []
for prefix in amazon_aws_ip_list['prefixes']:
l.append(prefix['ip_prefix'])
for prefix in amazon_aws_ip_list['ipv6_prefixes']:
l.append(prefix['ipv6_prefix'])
warninglist = {
'name': 'List of known Amazon AWS IP address ranges',
'version': get_version(),
'description': 'Amazon AWS IP address ranges (https://ip-ranges.amazonaws.com/ip-ranges.json)',
'type': 'cidr',
2021-06-12 12:13:23 +02:00
'list': consolidate_networks(l),
'matching_attributes': ["ip-src", "ip-dst", "domain|ip", "ip-src|port", "ip-dst|port"]
}
write_to_file(warninglist, dst)
2018-02-21 22:50:13 +01:00
if __name__ == '__main__':
amazon_url = "https://ip-ranges.amazonaws.com/ip-ranges.json"
amazon_file = "amazon_ip-ranges.json"
amazon_dst = "amazon-aws"
2018-02-21 22:50:13 +01:00
download_to_file(amazon_url, amazon_file)
process(amazon_file, amazon_dst)