MCPcopy
hub / github.com/fortra/impacket / __process_answer_structure

Method __process_answer_structure

impacket/dns.py:372–452  ·  view source on GitHub ↗
(self, offset, num)

Source from the content-addressed store, hash-verified

370 return self.__process_answer_structure(offset, arcount)
371
372 def __process_answer_structure(self, offset, num):
373 aux = []
374 data = self.get_body_as_string()
375 for _ in range(num):
376 offset, qname = self.parseCompressedMessage(data, offset)
377 qtype = data[offset:offset+self.__TYPE_LEN]
378 qtype = struct.unpack("!H", qtype)[0]
379 offset += self.__TYPE_LEN
380
381 qclass = data[offset:offset+self.__CLASS_LEN]
382 qclass = struct.unpack("!H", qclass)[0]
383 offset += self.__CLASS_LEN
384
385 qttl_raw = data[offset:offset+self.__TTL_LEN]
386 qttl = struct.unpack("!L", qttl_raw)[0]
387 offset += self.__TTL_LEN
388
389 qrdlength = data[offset:offset+self.__RDLENGTH_LEN]
390 qrdlength = struct.unpack("!H", qrdlength)[0]
391 offset += self.__RDLENGTH_LEN
392
393 qrdata = {}
394 if qtype == DNSType.A:
395 # IP Address Unsigned 32-bit value representing the IP address
396 qrdata["IPAddress"] = socket.inet_ntoa(data[offset:offset+qrdlength])
397 offset += self.__TYPE_A_LEN
398 elif qtype == DNSType.SOA:
399 # Primary NS Variable length. The name of the Primary Master for the domain. May be a label, pointer or any combination.
400 offset, primaryNs = self.parseCompressedMessage(data, offset)
401 qrdata["PrimaryNS"] = primaryNs
402 # Admin MB Variable length. The administrator's mailbox. May be a label, pointer or any combination.
403 offset, adminMb = self.parseCompressedMessage(data, offset)
404 qrdata["AdminMB"] = adminMb
405 # Serial Number Unsigned 32-bit integer.
406 qrdata["SerialNumber"] = struct.unpack("!L", data[offset:offset+self.__SERIAL_LEN])[0]
407 offset += self.__SERIAL_LEN
408 # Refresh interval Unsigned 32-bit integer.
409 qrdata["RefreshInterval"] = struct.unpack("!L", data[offset:offset+self.__REFRESH_LEN])[0]
410 offset += self.__REFRESH_LEN
411 # Retry Interval Unsigned 32-bit integer.
412 qrdata["RetryInterval"] = struct.unpack("!L", data[offset:offset+self.__RETRY_LEN])[0]
413 offset += self.__RETRY_LEN
414 # Expiration Limit Unsigned 32-bit integer.
415 qrdata["ExpirationLimit"] = struct.unpack("!L", data[offset:offset+self.__EXPIRATION_LEN])[0]
416 offset += self.__EXPIRATION_LEN
417 # Minimum TTL Unsigned 32-bit integer.
418 qrdata["MinimumTTL"] = struct.unpack("!L", data[offset:offset+self.__MINTTL_LEN])[0]
419 offset += self.__MINTTL_LEN
420 elif qtype == DNSType.MX:
421 # Preference Unsigned 16-bit integer.
422 qrdata["Preference"] = struct.unpack("!H", data[offset:offset+self.__PREF_LEN])[0]
423 # Mail Exchanger The name host name that provides the service. May be a label, pointer or any combination.
424 offset, mailExch = self.parseCompressedMessage(data, offset)
425 qrdata["MailExchanger"] = mailExch
426 elif qtype == DNSType.PTR or qtype == DNSType.NS or qtype == DNSType.CNAME:
427 # Name The host name that represents the supplied IP address (in the case of a PTR) or the NS name for the supplied domain (in the case of NS). May be a label, pointer or any combination.
428 offset, name = self.parseCompressedMessage(data, offset)
429 qrdata["Name"] = str(name.decode('ascii'))

Callers 3

__get_answersMethod · 0.95
__get_authoritativeMethod · 0.95
__get_additionalsMethod · 0.95

Calls 5

get_body_as_stringMethod · 0.80
appendMethod · 0.80
unpackMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected