From patchwork Tue Nov 5 09:31:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2573 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 476kvt2B6Mz420M for ; Tue, 5 Nov 2019 09:32:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 476kvs08CGz4XM; Tue, 5 Nov 2019 09:32:09 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 476kvr4Mtyz2yjx; Tue, 5 Nov 2019 09:32:08 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 476kvq3Vnyz2yWt for ; Tue, 5 Nov 2019 09:32:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 476kvp41x4z2dx; Tue, 5 Nov 2019 09:32:06 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1572946327; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5Az5hmIoVJcl/WpRpfDhovRX8uskBhw96cFkG61IhG8=; b=xK+UE7z3bcyEgu+oB7k7kfzbl8f90VAIFWpneqwkPPJZVXt41tGTm/wznlv3aGe5qRvqL5 f7FlJFJi8tJ/ALDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1572946327; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5Az5hmIoVJcl/WpRpfDhovRX8uskBhw96cFkG61IhG8=; b=Xe/ruCVErR7IkrB2eJpt76RVpMhUc51SZL9yzh1t6of0BZNTm05dplzSPdavHOHld8xajh IPevtzknoXo/EFeJY9QrCrCxqh6nRuCnOgyK9IZoI7ktzVdJcn3+g2numqYCMII1a75+8Z H2IV7//WjDhCYCS+ZsdBAO8NZyEugkZ566xBxmaJZpDgBMVATNimJUlZUf/A0nGRCIPh0q qDamPA+3bXdWz3er06b8XcsNrEBU6+GmHaazEozr3EO1rV+RpeU+h7uuo8LXij4S9zi/zg nzcIKvwkIGf7G+ae1IBlzrAJdlLHo6bt2SErwfnoF2gOPu6GKyRzzVDmootXXQ== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 1/5] ids-functions.pl: Introduce generate_dns_servers_file() Date: Tue, 5 Nov 2019 10:31:58 +0100 Message-Id: <20191105093202.4488-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.auth=stevee smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This function is used to generate a yaml file which take care of the current used DNS configuration and should be included in the main suricata config file. Signed-off-by: Stefan Schantl --- config/cfgroot/ids-functions.pl | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index 94de1373c..54d86f70f 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -34,6 +34,9 @@ our $used_rulefiles_file = "$settingsdir/suricata-used-rulefiles.yaml"; # File where the addresses of the homenet are stored. our $homenet_file = "$settingsdir/suricata-homenet.yaml"; +# File where the addresses of the used DNS servers are stored. +our $dns_servers_file = "$settingsdir/suricata-dns-servers.yaml"; + # File which contains the enabled sids. our $enabled_sids_file = "$settingsdir/oinkmaster-enabled-sids.conf"; @@ -695,6 +698,65 @@ sub generate_home_net_file() { close(FILE); } +# +# Function to generate and write the file which contains the configured and used DNS servers. +# +sub generate_dns_servers_file() { + # Open file which contains the current used DNS configuration. + open (FILE, "${General::swroot}/red/dns") or die "Could not read DNS configuration from ${General::swroot}/red/dns. $!\n"; + + # Read-in whole file content and store it in a temporary array. + my @file_content = ; + + # Close file handle. + close(FILE); + + # Format dns servers declaration. + my $line = "\"\["; + + # Loop through the array which contains the file content. + foreach my $server (@file_content) { + # Remove newlines. + chomp($server); + + # Check if the current DNS configuration is using the local recursor mode. + if ($server eq "local recursor") { + # The responsible DNS servers on red are directly used, and because we are not able + # to specify each single DNS server address here, we currently have to thread each + # address which is not part of the HOME_NET as possible DNS server. + $line = "$line" . "!\$HOME_NET"; + } else { + # Add the DNS server to the line. + $line = "$line" . "$server"; + } + + # Check if the current DNS server was the last in the array. + if ($server eq $file_content[-1]) { + # Close the line. + $line = "$line" . "\]\""; + } else { + # Add "," for the next DNS server. + $line = "$line" . "\,"; + } + } + + # Open file to store the used DNS server addresses. + open(FILE, ">$dns_servers_file") or die "Could not open $dns_servers_file. $!\n"; + + # Print yaml header. + print FILE "%YAML 1.1\n"; + print FILE "---\n\n"; + + # Print notice about autogenerated file. + print FILE "#Autogenerated file. Any custom changes will be overwritten!\n"; + + # Print the generated DNS declaration to the file. + print FILE "DNS_SERVERS:\t$line\n"; + + # Close file handle. + close(FILE); +} + # ## Function to generate and write the file for used rulefiles. #