<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>使用示例 on PowerShell 模块 DNSServer.DebugLogParser</title><link>https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/</link><description>Recent content in 使用示例 on PowerShell 模块 DNSServer.DebugLogParser</description><generator>Hugo</generator><language>cn</language><atom:link href="https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/index.xml" rel="self" type="application/rss+xml"/><item><title>域环境中的实际应用（基于 GPO 的收集与转换）</title><link>https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/gpo-driven-collection/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/gpo-driven-collection/</guid><description>&lt;p&gt;本文档概述了在 Active Directory 域环境中运行 DNSServer.DebugLogParser 的一个实际端到端示例，重点是转换域控制器上的 Windows DNS 服务器调试日志。&lt;/p&gt;
&lt;p&gt;本示例附带一个 &lt;a href="../gpo/T0-C-Analytics-DNSDebugLogging.zip"&gt;ZIP 压缩包&lt;/a&gt;，其中包含用于实现本文描述工作流的策略工件。&lt;br&gt;
最相关的工件包括 &lt;a href="../gpo/backup/manifest.xml" target="_blank" rel="noopener noreferrer"&gt;备份清单&lt;/a&gt;、&lt;a href="../gpo/backup/{2B6F16BC-0E7C-4787-83D7-2854FED882EE}/gpreport.xml" target="_blank" rel="noopener noreferrer"&gt;GPO 报告&lt;/a&gt;、&lt;a href="../gpo/backup/{2B6F16BC-0E7C-4787-83D7-2854FED882EE}/DomainSysvol/GPO/Machine/Preferences/Files/Files.xml" target="_blank" rel="noopener noreferrer"&gt;Files.xml&lt;/a&gt;、&lt;a href="../gpo/backup/{2B6F16BC-0E7C-4787-83D7-2854FED882EE}/DomainSysvol/GPO/Machine/Preferences/Files/Set-DNSServerDebugLogging.ps1" target="_blank" rel="noopener noreferrer"&gt;Set-DNSServerDebugLogging.ps1&lt;/a&gt; 以及 &lt;a href="../gpo/backup/{2B6F16BC-0E7C-4787-83D7-2854FED882EE}/DomainSysvol/GPO/Machine/Preferences/ScheduledTasks/ScheduledTasks.xml" target="_blank" rel="noopener noreferrer"&gt;ScheduledTasks.xml&lt;/a&gt;。&lt;/p&gt;
&lt;h2 id="场景"&gt;场景&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;多个域控制器（DC）承载 DNS 服务器角色。&lt;/li&gt;
&lt;li&gt;通过计划任务在每个 DC 上启用并统一配置 DNS 调试日志（日志文件写入路径为 &lt;code&gt;C:\Administration\Logs\DNSServer&lt;/code&gt;）。&lt;/li&gt;
&lt;li&gt;集中管理的进程将日志转换为 CSV，用于：
&lt;ul&gt;
&lt;li&gt;安全分析&lt;/li&gt;
&lt;li&gt;运营报告&lt;/li&gt;
&lt;li&gt;故障排查&lt;/li&gt;
&lt;li&gt;合规/保留&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="目标结果"&gt;目标结果&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;所有 DC 上的转换设置保持一致&lt;/li&gt;
&lt;li&gt;输出位置和命名可预测&lt;/li&gt;
&lt;li&gt;可选压缩以减少存储占用&lt;/li&gt;
&lt;li&gt;可选统计输出以实现快速的每日汇总&lt;/li&gt;
&lt;li&gt;主机端风险最小，明确重跑和清理策略&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="建议架构"&gt;建议架构&lt;/h2&gt;
&lt;h3 id="收集模型本地转换--中央拉取"&gt;收集模型：本地转换 + 中央拉取&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;每个 DC 将 DNS 调试日志写入磁盘，并启用日志轮转。&lt;/li&gt;
&lt;li&gt;每个 DC 将轮转的 &lt;code&gt;*.log&lt;/code&gt; 文件转换成数据 CSV 和统计 CSV，然后通过计划任务压缩输出为 &lt;code&gt;*.zip&lt;/code&gt;。&lt;/li&gt;
&lt;li&gt;输出文件与日志文件写在同一目录，简化管道流程。&lt;/li&gt;
&lt;li&gt;中央服务器收集 &lt;code&gt;*.zip&lt;/code&gt; 输出，例如通过文件共享导入、定时复制、SIEM 转发器或基于代理的收集器。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;该模型最大限度减少了对大型原始日志文件的网络读取，将解析工作保持在数据近旁。&lt;/p&gt;
&lt;h2 id="gpo-工作流"&gt;GPO 工作流&lt;/h2&gt;
&lt;p&gt;该工作流通过组策略（计算机配置）实现，确保所有域控制器的设置一致。&lt;/p&gt;</description></item><item><title>使用 SQL Server 的安全分析工作流</title><link>https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/security-analysis-sql/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/security-analysis-sql/</guid><description>&lt;p&gt;此示例展示了一个实用的安全分析工作流：使用 &lt;code&gt;Convert-DNSDebugLogFile&lt;/code&gt; 解析 DNS 调试日志，将生成的 CSV 导入 SQL Server，并运行查询以突出显示异常大量的 TXT 记录查询。&lt;/p&gt;
&lt;p&gt;为了最佳的互操作性，此示例通过使用 &lt;code&gt;-OutputCulture 'sv-SE'&lt;/code&gt; 以类似 ISO 的格式写入时间戳。&lt;/p&gt;
&lt;h2 id="所需模块"&gt;所需模块&lt;/h2&gt;
&lt;p&gt;此示例使用以下 PowerShell 模块：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;DNSServer.DebugLogParser&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SqlServer&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;如有需要，请安装它们：&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-powershell"&gt;Install-Module -Name DNSServer.DebugLogParser -Scope CurrentUser
Install-Module -Name SqlServer -Scope CurrentUser
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="场景"&gt;场景&lt;/h2&gt;
&lt;p&gt;当你想将解析后的 DNS 调试日志数据移入 SQL Server，以便你可以：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;高效搜索大数据集&lt;/li&gt;
&lt;li&gt;构建可重复使用的检测查询&lt;/li&gt;
&lt;li&gt;关联多个 DNS 服务器的活动&lt;/li&gt;
&lt;li&gt;保留规范化数据以供后续调查&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;时，请使用此工作流。&lt;/p&gt;
&lt;h2 id="转换步骤的输出"&gt;转换步骤的输出&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Convert-DNSDebugLogFile&lt;/code&gt; 不直接写入 SQL Server。它首先创建一个 CSV 文件。该 CSV 文件即为导入数据库的数据集。&lt;/p&gt;
&lt;p&gt;在此示例中：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;输入日志：&lt;code&gt;C:\Administration\Logs\DNS\dns.log&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;生成的 CSV：&lt;code&gt;C:\Administration\Logs\DNS\dns.csv&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;目标表：&lt;code&gt;dbo.DNSQueries&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="创建目标表"&gt;创建目标表&lt;/h2&gt;
&lt;p&gt;在 SQL Server 中运行以下语句一次，创建目标表。&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-sql"&gt;IF OBJECT_ID('dbo.DNSQueries', 'U') IS NULL
BEGIN
 CREATE TABLE dbo.DNSQueries (
 DateTime datetime2(0) NOT NULL,
 ThreadId int NULL,
 Context nvarchar(20) NULL,
 PacketId int NULL,
 Protocol nvarchar(10) NULL,
 Direction nvarchar(10) NULL,
 ClientIP nvarchar(64) NULL,
 Xid nvarchar(16) NULL,
 Type nvarchar(16) NULL,
 Opcode nvarchar(16) NULL,
 FlagsHex nvarchar(16) NULL,
 FlagsChar nvarchar(16) NULL,
 ResponseCode nvarchar(32) NULL,
 QuestionType nvarchar(32) NULL,
 QuestionName nvarchar(512) NULL,
 Information nvarchar(max) NULL,
 Details nvarchar(max) NULL,
 ComputerName nvarchar(256) NULL
 );
END;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="转换日志并导入-csv"&gt;转换日志并导入 CSV&lt;/h2&gt;
&lt;p&gt;以下 PowerShell 示例执行完整工作流：&lt;/p&gt;</description></item><item><title>计划任务示例</title><link>https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/scheduletask/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://DNSServerDebugLogParser.andibellstedt.com/v1.2.0.0/cn/docs/examples/scheduletask/</guid><description>&lt;p&gt;此脚本创建了一个每天凌晨 2:00 运行的 Windows 计划任务。它导入模块并处理脚本执行所在文件夹中的所有日志文件（本例中为 &amp;ldquo;C:\Administration\Logs\DNS&amp;rdquo;）。该过程会将输出压缩成 ZIP 文件，并删除原始文件以保持整洁。&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-powershell"&gt;$actionParams = @{
 Execute = &amp;quot;powershell.exe&amp;quot;
 Argument = '-ExecutionPolicy RemoteSigned -Command &amp;quot;Import-Module DNSServer.DebugLogParser; Get-ChildItem .\*.log | Sort-Object lastwritetime, Name -Descending | Convert-DNSDebugLogFile -ComputerName $env:COMPUTERNAME -Delimiter \&amp;quot;;\&amp;quot; -OutputType Both -ContextFilter Packet -OutputCulture sv-SE -CompressOutput&amp;quot;'
 WorkingDirectory = &amp;quot;C:\Administration\Logs\DNS&amp;quot;
}
$Action = New-ScheduledTaskAction @actionParams

$Trigger = New-ScheduledTaskTrigger -Daily -At &amp;quot;2:00AM&amp;quot;

Register-ScheduledTask -TaskName &amp;quot;Process DNS Logs&amp;quot; -Action $Action -Trigger $Trigger -Description &amp;quot;Convert DNS debug logs to CSV daily&amp;quot;
&lt;/code&gt;&lt;/pre&gt;</description></item></channel></rss>