Beispiel #1
0
    def _send_queries(
            self,
            send_socket,  # type: socket
            source_mac_address,  # type: str
            source_ipv4_address,  # type: str
            source_ipv6_address,  # type: str
            domain,  # type: str
            ns_servers,  # type: List[Dict[str, str]]
            destination_port=53,  # type: int
            max_threats_count=9,  # type: int
            subdomains=['www'],  # type: List[str]
            queries_type=[1, 28],  # type: List[int]
            queries_class=[1]  # type: List[int]
    ):
        # type: (...) -> None
        """
        Send DNS queries to IPv4/IPv6 DNS servers
        :param send_socket: Raw socket for sending DNS queries
        :param source_mac_address: Source MAC address for DNS query (most likely this is MAC address on your network interface)
        :param source_ipv4_address: Source IPv4 address for DNS query (most likely this is IPv4 address on your network interface)
        :param source_ipv6_address: Source IPv6 address for DNS query (most likely this is IPv6 address on your network interface)
        :param domain: Target domain (example: 'test.com')
        :param ns_servers: List of DNS servers (example: [{'ipv4 address': '8.8.8.8', 'mac address': '01:23:45:67:89:0a'}])
        :param destination_port: UDP destination port (default: 53)
        :param max_threats_count: Maximum threats count (default: 9)
        :param subdomains: List of subdomains (default: ['www'])
        :param queries_type: List of queries type (default: [1, 28]; type 1: A, type 28: AAAA)
        :param queries_class: List of queries class (default: [1]; class 1: IN)
        :return: None
        """

        # DNS query type: 1 (A)
        # DNS query type: 28 (AAAA)
        # DNS query class: 1 (IN)

        # region Init threat manager
        send_threats = ThreadManager(max_threats_count)
        # endregion

        # region Make DNS queries list
        queries = list()
        for subdomain in subdomains:
            for query_type in queries_type:
                for query_class in queries_class:
                    queries.append({
                        'type': query_type,
                        'class': query_class,
                        'name': subdomain + '.' + domain
                    })
        # endregion

        # region Calculate number of DNS queries for one threat
        queries_len = len(queries)
        ipv4_ns_servers_len = 0
        ipv6_ns_servers_len = 0

        for ns_server in ns_servers:
            if 'ipv4 address' in ns_server.keys():
                ipv4_ns_servers_len += 1
            if 'ipv6 address' in ns_server.keys():
                ipv6_ns_servers_len += 1

        if source_ipv6_address is not None:
            queries_len_for_threat = int(
                (queries_len * (ipv4_ns_servers_len + ipv6_ns_servers_len)) /
                max_threats_count) + 1
        else:
            queries_len_for_threat = int(
                (queries_len * ipv4_ns_servers_len) / max_threats_count) + 1
        # endregion

        # region Send DNS queries

        # region Send DNS queries to IPv4 NS servers
        for ns_server in ns_servers:
            if 'ipv4 address' in ns_server.keys():
                for query_index in range(0, queries_len,
                                         queries_len_for_threat):
                    send_threats.add_task(
                        self._send_ipv4_queries, source_mac_address,
                        source_ipv4_address, ns_server['mac address'],
                        ns_server['ipv4 address'], destination_port,
                        queries[query_index:query_index +
                                queries_len_for_threat], send_socket)
        # endregion

        # region Send DNS queries to IPv6 NS servers
        if source_ipv6_address is not None:
            for ns_server in ns_servers:
                if 'ipv6 address' in ns_server.keys():
                    for query_index in range(0, queries_len,
                                             queries_len_for_threat):
                        send_threats.add_task(
                            self._send_ipv6_queries, source_mac_address,
                            source_ipv6_address, ns_server['mac address'],
                            ns_server['ipv6 address'], destination_port,
                            queries[query_index:query_index +
                                    queries_len_for_threat], send_socket)
        # endregion

        # endregion

        # region Wait all threats
        send_threats.wait_for_completion()
Beispiel #2
0
                exit(1)
            else:
                apple_device = [target_ip, target_mac]
        # endregion

        # region Print target IP and MAC address
        Base.print_info("Target: ",
                        apple_device[0] + " (" + apple_device[1] + ")")
        # endregion

        # region Start sniffer
        tm = ThreadManager(2)
        tm.add_task(sniffer)
        # endregion

        # region Send first Multicast ARP request
        sleep(3)
        Base.print_warning("Send initial Multicast ARP requests")
        send_arp_request()
        # endregion

        # region Wait for completion
        tm.wait_for_completion()
        # endregion

    except KeyboardInterrupt:
        Base.print_info("Exit")
        exit(0)

# endregion