From 2291c52323b4cd2d0626e37111be7057256e3811 Mon Sep 17 00:00:00 2001 From: SkelSec Date: Thu, 29 Aug 2024 08:20:41 +0200 Subject: [PATCH] dns parsing fixes --- msldap/_version.py | 2 +- msldap/client.py | 1 + msldap/wintypes/dnsp/strcutures.py | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/msldap/_version.py b/msldap/_version.py index c32c3e6..3b4e743 100644 --- a/msldap/_version.py +++ b/msldap/_version.py @@ -1,5 +1,5 @@ -__version__ = "0.5.11" +__version__ = "0.5.12" __banner__ = \ """ # msldap %s diff --git a/msldap/client.py b/msldap/client.py index 5e2324e..afa4407 100644 --- a/msldap/client.py +++ b/msldap/client.py @@ -1680,6 +1680,7 @@ async def dnattrs(self, dn, attrs:List[str]): if err is not None: raise err return entry['attributes'], None + return None, None #no results except Exception as e: return None, e diff --git a/msldap/wintypes/dnsp/strcutures.py b/msldap/wintypes/dnsp/strcutures.py index 37cf737..8a76f1f 100644 --- a/msldap/wintypes/dnsp/strcutures.py +++ b/msldap/wintypes/dnsp/strcutures.py @@ -2,7 +2,6 @@ # parts of the dns implementation was taken from https://github.com/dirkjanm/adidnsdump import enum import io -import socket import datetime from typing import List @@ -136,7 +135,14 @@ def from_bytes(data): @staticmethod def from_buffer(buff:io.BytesIO): res = DNS_RPC_RECORD_A() - res.IpAddress = socket.inet_ntoa(buff.read(4)) + #webassembly... + #res.IpAddress = socket.inet_ntoa(buff.read(4)) + ipv4_bytes = buff.read(4) + + # Convert each byte to an integer and join them with dots to form the IPv4 address + ipv4_str = '.'.join(str(byte) for byte in ipv4_bytes) + res.IpAddress = ipv4_str + return res def to_line(self, separator = '\t'): @@ -156,7 +162,14 @@ def from_bytes(data): @staticmethod def from_buffer(buff:io.BytesIO): res = DNS_RPC_RECORD_AAAA() - res.IpAddress = socket.inet_ntop(socket.AF_INET6, buff.read(16)) + # webassembly pyodide has problems with socket implementation + #res.IpAddress = socket.inet_ntop(socket.AF_INET6, buff.read(16)) + ipv6_bytes = buff.read(16) + ipv6_hex = ''.join(f'{byte:02x}' for byte in ipv6_bytes) + + # Convert the hex string into the standard IPv6 format + ipv6_str = ":".join(ipv6_hex[i:i + 4] for i in range(0, 32, 4)) + res.IpAddress = ipv6_str return res def to_line(self, separator = '\t'):