Home | History | Annotate | Line # | Download | only in ans3
      1  1.1  christos """
      2  1.1  christos Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      3  1.1  christos 
      4  1.1  christos SPDX-License-Identifier: MPL-2.0
      5  1.1  christos 
      6  1.1  christos This Source Code Form is subject to the terms of the Mozilla Public
      7  1.1  christos License, v. 2.0.  If a copy of the MPL was not distributed with this
      8  1.1  christos file, you can obtain one at https://mozilla.org/MPL/2.0/.
      9  1.1  christos 
     10  1.1  christos See the COPYRIGHT file distributed with this work for additional
     11  1.1  christos information regarding copyright ownership.
     12  1.1  christos """
     13  1.1  christos 
     14  1.1  christos from collections.abc import AsyncGenerator
     15  1.1  christos 
     16  1.1  christos import dns.rcode
     17  1.1  christos import dns.rdatatype
     18  1.1  christos import dns.rrset
     19  1.1  christos 
     20  1.1  christos from isctest.asyncserver import (
     21  1.1  christos     AsyncDnsServer,
     22  1.1  christos     DnsResponseSend,
     23  1.1  christos     QueryContext,
     24  1.1  christos     ResponseAction,
     25  1.1  christos     ResponseHandler,
     26  1.1  christos )
     27  1.1  christos 
     28  1.1  christos 
     29  1.1  christos class AttackerAuthority(ResponseHandler):
     30  1.1  christos     async def get_responses(
     31  1.1  christos         self, qctx: QueryContext
     32  1.1  christos     ) -> AsyncGenerator[ResponseAction, None]:
     33  1.1  christos         if qctx.qtype == dns.rdatatype.A:
     34  1.1  christos             qctx.response.answer.append(
     35  1.1  christos                 dns.rrset.from_text(
     36  1.1  christos                     qctx.qname, 300, qctx.qclass, dns.rdatatype.A, "6.6.6.6"
     37  1.1  christos                 )
     38  1.1  christos             )
     39  1.1  christos 
     40  1.1  christos         yield DnsResponseSend(qctx.response)
     41  1.1  christos 
     42  1.1  christos 
     43  1.1  christos def main() -> None:
     44  1.1  christos     server = AsyncDnsServer(default_aa=True, default_rcode=dns.rcode.NOERROR)
     45  1.1  christos     server.install_response_handler(AttackerAuthority())
     46  1.1  christos     server.run()
     47  1.1  christos 
     48  1.1  christos 
     49  1.1  christos if __name__ == "__main__":
     50  1.1  christos     main()
     51