From d1b528b0d656454db2d42070eac2123dd397510f Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 30 Apr 2022 12:00:45 +0530 Subject: [PATCH] DropRequests: updated app to support blocking entire zone of the configured qname. --- Apps/DropRequestsApp/App.cs | 23 ++++++++++++++++++++--- Apps/DropRequestsApp/dnsApp.config | 3 ++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Apps/DropRequestsApp/App.cs b/Apps/DropRequestsApp/App.cs index e1b3ee6b..724bbbf6 100644 --- a/Apps/DropRequestsApp/App.cs +++ b/Apps/DropRequestsApp/App.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2021 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -170,6 +170,7 @@ namespace DropRequests #region variables readonly string _name; + readonly bool _blockZone; readonly DnsResourceRecordType _type; #endregion @@ -179,6 +180,11 @@ namespace DropRequests public BlockedQuestion(dynamic jsonQuestion) { _name = jsonQuestion.name?.Value; + if (_name is not null) + _name = _name.TrimEnd('.'); + + if (jsonQuestion.blockZone is not null) + _blockZone = jsonQuestion.blockZone.Value; string strType = jsonQuestion.type?.Value; if (!string.IsNullOrEmpty(strType) && Enum.TryParse(strType, true, out DnsResourceRecordType type)) @@ -193,8 +199,19 @@ namespace DropRequests public bool Matches(DnsQuestionRecord question) { - if ((_name is not null) && !_name.Equals(question.Name, StringComparison.OrdinalIgnoreCase)) - return false; + if (_name is not null) + { + if (_blockZone) + { + if ((_name.Length > 0) && !_name.Equals(question.Name, StringComparison.OrdinalIgnoreCase) && !question.Name.EndsWith("." + _name, StringComparison.OrdinalIgnoreCase)) + return false; + } + else + { + if (!_name.Equals(question.Name, StringComparison.OrdinalIgnoreCase)) + return false; + } + } if ((_type != DnsResourceRecordType.Unknown) && (_type != question.Type)) return false; diff --git a/Apps/DropRequestsApp/dnsApp.config b/Apps/DropRequestsApp/dnsApp.config index 9d22df06..70445361 100644 --- a/Apps/DropRequestsApp/dnsApp.config +++ b/Apps/DropRequestsApp/dnsApp.config @@ -12,7 +12,8 @@ ], "blockedQuestions": [ { - "name": "example.com" + "name": "example.com", + "blockZone": true }, { "type": "ANY"