diff --git a/app/Classes/Protocol/DNS.php b/app/Classes/Protocol/DNS.php index a7747d6..aa836ab 100644 --- a/app/Classes/Protocol/DNS.php +++ b/app/Classes/Protocol/DNS.php @@ -59,8 +59,8 @@ final class DNS extends BaseProtocol public const DNS_TYPE_SOA = 6; // SOA Records public const DNS_TYPE_MX = 15; // MX Records public const DNS_TYPE_TXT = 16; // TXT Records - public const DNS_TYPE_AAAA = 28; // AAAA Records + public const DNS_TYPE_SRV = 33; // SRV Records public const DNS_TYPE_OPT = 41; // OPT Records public const DNS_TYPE_DS = 43; // DS Records (Delegation signer RFC 4034) diff --git a/app/Classes/Protocol/DNS/Query.php b/app/Classes/Protocol/DNS/Query.php index ac9d18b..9a77ae8 100644 --- a/app/Classes/Protocol/DNS/Query.php +++ b/app/Classes/Protocol/DNS/Query.php @@ -50,7 +50,7 @@ final class Query $this->labels = collect(); while (($len=ord(substr($this->buf,$rx_ptr++,1))) !== 0x00) { - $this->labels->push(substr($this->buf,$rx_ptr,$len)); + $this->labels->push(strtolower(substr($this->buf,$rx_ptr,$len))); $rx_ptr += $len; } @@ -74,8 +74,8 @@ final class Query if ($this->arcount) { // Additional records, EDNS: https://datatracker.ietf.org/doc/html/rfc6891 if (($haystack = strstr(substr($this->buf,$rx_ptr+1+10),"\x00",true)) !== FALSE) { - Log::error(sprintf('%s:! DNS additional record format error?',self::LOGKEY)); - // @todo catch this + Log::error(sprintf('%s:! DNS additional record format error?',self::LOGKEY),['buf'=>hex_dump($this->buf)]); + return; } $this->additional = new RR(substr($this->buf,$rx_ptr,(strlen($haystack) === 0) ? NULL : strlen($haystack))); diff --git a/app/Classes/Protocol/DNS/RR.php b/app/Classes/Protocol/DNS/RR.php index 4081a66..d1d313e 100644 --- a/app/Classes/Protocol/DNS/RR.php +++ b/app/Classes/Protocol/DNS/RR.php @@ -4,6 +4,7 @@ namespace App\Classes\Protocol\DNS; use Illuminate\Support\Arr; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use App\Classes\Protocol\DNS; @@ -26,8 +27,15 @@ final class RR $domain = strstr($buf,"\x00",TRUE); $i += strlen($domain)+1; - $this->type = Arr::get(unpack('n',substr($buf,$i,2)),1); - $this->class = Arr::get(unpack('n',substr($buf,$i+2,2)),1); + try { + $this->type = Arr::get(unpack('n',substr($buf,$i,2)),1); + $this->class = Arr::get(unpack('n',substr($buf,$i+2,2)),1); + + } catch (\ErrorException $e) { + Log::error(sprintf('%s:! Error unpacking buffer [%s]',self::LOGKEY,$buf),['buf'=>hex_dump($buf)]); + return; + } + $i += 4; switch ($this->type) {