Collect all the All DNS records for the provided zone and add them to NetworkX graph
(graph, zone, groups, dns_manager, ip_manager)
| 75 | |
| 76 | |
| 77 | def find_all_dns_by_zone(graph, zone, groups, dns_manager, ip_manager): |
| 78 | """ |
| 79 | Collect all the All DNS records for the provided zone and add them to NetworkX graph |
| 80 | """ |
| 81 | dns_results = dns_manager.find_multiple({"zone": zone}, None) |
| 82 | |
| 83 | for result in dns_results: |
| 84 | zone_g_index = add_to_list(zone, groups) |
| 85 | if result["type"] == "a": |
| 86 | temp = result["value"].split(".") |
| 87 | ip_group = ".".join(temp[:-1]) |
| 88 | if ip_manager.is_aws_ip(result["value"]): |
| 89 | ip_group = "aws" |
| 90 | elif ip_manager.is_akamai_ip(result["value"]): |
| 91 | ip_group = "akamai" |
| 92 | elif ip_manager.is_azure_ip(result["value"]): |
| 93 | ip_group = "azure" |
| 94 | elif ip_manager.is_gcp_ip(result["value"]): |
| 95 | ip_group = "gcp" |
| 96 | |
| 97 | ip_g_index = add_to_list(ip_group, groups) |
| 98 | if str(result["fqdn"]) != zone: |
| 99 | graph.add_node( |
| 100 | result["fqdn"].replace("." + zone, ""), |
| 101 | data_type="domain", |
| 102 | type=zone_g_index, |
| 103 | depends=[zone], |
| 104 | dependedOnBy=[result["value"]], |
| 105 | docs="", |
| 106 | ) |
| 107 | else: |
| 108 | graph.add_node( |
| 109 | result["fqdn"], |
| 110 | data_type="tld", |
| 111 | type=zone_g_index, |
| 112 | depends=[], |
| 113 | dependedOnBy=[result["value"]], |
| 114 | docs="", |
| 115 | ) |
| 116 | graph.add_node( |
| 117 | result["value"], |
| 118 | data_type="ip", |
| 119 | type=ip_g_index, |
| 120 | depends=[result["fqdn"].replace("." + zone, "")], |
| 121 | dependedOnBy=[], |
| 122 | docs="", |
| 123 | ) |
| 124 | graph.add_edge(zone, result["fqdn"].replace("." + zone, ""), value=2) |
| 125 | graph.add_edge( |
| 126 | result["fqdn"].replace("." + zone, ""), result["value"], value=1 |
| 127 | ) |
| 128 | elif result["type"] == "cname": |
| 129 | dns_group = zone |
| 130 | if is_akamai_domain(result["value"]): |
| 131 | dns_group = "akamai.net" |
| 132 | elif result["value"].endswith(zone) is False: |
| 133 | dns_group = get_fld_from_value(result["value"], zone) |
| 134 |
no test coverage detected