Beispiel #1
0
 def find_any_record_on_ns(response: Response, domain):
     req = Request(Header("aaaa", Flags(BitArray(b"\x01\x00")), 1, 0, 0, 0),
                   [Question(domain, RecordTypes.ANY)],
                   str_to_hex("aa 1a 01 00 00 01 00 00 00 00 00 00"))
     req_bytes = req.to_bytes()
     with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
         s.sendto(req_bytes, (response.answers[0].data, 53))
         data, sender = s.recvfrom(512)
         response = parse_answers(data)
     return response
Beispiel #2
0
 def parse_int_to_bytes(ints):
     normal_data = ""
     for j in ints.split(" "):
         if j == "\n":
             continue
         hex_char = hex(int(j))[2:]
         if len(hex_char) == 1:
             hex_char = "0" + hex_char
         normal_data += hex_char + " "
     return str_to_hex(normal_data)
Beispiel #3
0
 def __init__(self, q_name, q_type):
     if q_type not in RecordTypes.ValidRequestType:
         raise ValueError("Invalid type value")
     self.data = str_to_hex(insert_info_into_request(q_name, q_type))
     self.address = "127.0.0.1"
     self.port = 53
     with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
         s.sendto(self.data, (self.address, self.port))
         data, sender = s.recvfrom(256)
         answer = parse_answers(data)
         print(answer)
Beispiel #4
0
 def find_ip_for_ns(self, response: Response):
     domain = response.get_all_info()[0].data
     request = Request(
         Header("aaaa", Flags(BitArray(b"\x01\x00")), 1, 0, 0, 0),
         [Question(domain, RecordTypes.A)],
         str_to_hex("aa aa 01 00 00 01 00 00 00 00 00 00"))
     req_bytes = request.to_bytes()
     self.socket_resolver.sendto(
         req_bytes, (self.address_resolver, self.port_resolver))
     data, sender = self.socket_resolver.recvfrom(512)
     data = parse_answers(data)
     return data
Beispiel #5
0
 def get_error_response(request: Request):
     return str_to_hex(f"{request.header.id} 80 01 00 00 00 00 00 00 00 00")