
新鈦雲服已累計為您分享813篇技術乾貨

-
自建DNS服務:在不登入window dns伺服器的情況下,透過日誌系統進行查詢解析記錄。 -
HTTPS安全通訊:為所有域名服務列印域名證書的時間資訊。 -
告警系統:監控域名證書狀態,並在出現問題時及時告警。
-
域名解析測試
-
在內部網路的客戶端上測試域名解析,確保所有服務都能正確解析。 -
驗證HTTPS證書連線,確保瀏覽器或客戶端能夠安全訪問服務。 -
證書和域名監控
-
監控證書的有效期,設定告警閾值(如到期前60天)。 -
監控HTTPS服務的可用性,確保服務在DNS解析和證書有效的情況下正常執行。 -
告警機制
-
如果證書即將到期或已過期,發出告警,確保運維人員能夠及時更新證書。 -
實現自動化指令碼,當證書即將到期時,生產新的證書進替換
-
openssl軟體下載地址 https://slproweb.com/download/Win64OpenSSL-3_3_2.msi -
軟體下載後直接點選下一步進行安裝,直到安裝完成. -
openssl環境變數配置


Get-DnsServerResourceRecord -ZoneName "text" | Where-Object { $_.RecordType -eq"CNAME" -or $_.RecordType -eq"A"} | Format-Table -AutoSize
$domain = "text"
cmd /c "echo | openssl s_client -servername `"$($domain)`" -connect `"$($domain):443`"2>&1| openssl x509 -noout -dates | findstr /C:notAfter"

$zoneName = "text"
# domaininput.txt需要排除的域名列表資訊
$inputFilePath = "D:\domain\domaininput.txt"
# domainoutput.txt需要輸出日誌記錄的域名列表資訊
$outputFilePath = "D:\domain\domainoutput.txt"
# 飛書webhook
$feishuWebhookUrl = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxxxxxxxxx"# 替換為你的飛書 Webhook URL
function Send-FeishuNotification {
param (
[string]$message,
[string]$color
)
if ($color-eq"blue") {
$formattedMessage = "*Success:* $message"
} elseif ($color-eq"black") {
$formattedMessage = "*Error:* $message"
} else {
$formattedMessage = $message
}
$payload = @{
msg_type = "text"
content = @{
text = $formattedMessage
}
}
$jsonPayload = $payload | ConvertTo-Json -Depth 1
Invoke-RestMethod -Uri $feishuWebhookUrl -Method Post -Body $jsonPayload -ContentType 'application/json'
}
function Get-CertificateEndDate {
param (
[string]$domain
)
Write-Host"正在處理域名: $domain"
try {
# 獲取證書到期資訊
$certInfo = cmd /c "echo | openssl s_client -servername `"$($domain)`" -connect `"$($domain):443`" 2>&1 | openssl x509 -noout -dates | findstr /C:notAfter"
Write-Host"獲取的證書資訊: $certInfo"
if ($certInfo-match"notAfter=(.*)") {
$formattedDate = $matches[1].Trim() # 獲取到期時間並去掉空格
Write-Host"證書到期時間: $formattedDate"
# 修剪多餘空格
$formattedDate = $formattedDate-replace'\s+', ' '
# 解析日期時,指定格式並轉換為 yyyy-MM-dd
$parsedDate = [datetime]::ParseExact($formattedDate, "MMM d HH:mm:ss yyyy 'GMT'", [System.Globalization.CultureInfo]::InvariantCulture)
$endDate = $parsedDate.ToString("yyyy-MM-dd")
Write-Host"格式化後的日期: $endDate"
return$endDate
} else {
Write-Host"未找到證書資訊: $certInfo"
return"2008-08-08"# 預設日期
}
} catch {
Write-Host"發生錯誤: $_"
return"2008-08-08"# 預設日期
}
}
try {
if (-Not (Test-Path$inputFilePath)) {
$errorMessage = "輸入檔案不存在:$inputFilePath"
$failureMessage = "failed $zoneName$errorMessage"
Send-FeishuNotification -message $failureMessage -color "black"
exit
}
$excludedDomains = Get-Content -Path $inputFilePath | Where-Object { $_.Trim() -ne"" }
$dnsRecords = Get-DnsServerResourceRecord -ZoneName $zoneName |
Where-Object { $_.RecordType -eq"CNAME" -or $_.RecordType -eq"A" }
$output = @{}
$ignoredDomains = @()
foreach ($recordin$dnsRecords) {
$hostName = $record.HostName
if ($hostName.EndsWith($zoneName, [System.StringComparison]::OrdinalIgnoreCase)) {
$fullDomain = $hostName
} else {
$fullDomain = "$hostName.$zoneName"
}
# 修正重複的域名問題
$fullDomain = $fullDomain-replace'\.text\.text\.cn$', '.text.cn'
if ($excludedDomains-notcontains$fullDomain) {
$endDate = Get-CertificateEndDate -domain $fullDomain
$key = "$fullDomain|$($record.RecordType)"
if (-not$output.ContainsKey($key)) {
$output[$key] = @{
RecordType = $record.RecordType
domain = $fullDomain
EndDate = $endDate
CimInstanceProperties = $record.RecordData
}
}
} else {
$ignoredDomains += $fullDomain
}
}
$outputArray = $output.Values
$outputLines = $outputArray | ForEach-Object {
$_ | ConvertTo-Json -Depth 1 -Compress
}
$outputLines | Set-Content -Path $outputFilePath -Encoding utf8
$lineCount = $outputLines.Count
$uniqueIgnoredDomains = $ignoredDomains | Select-Object -Unique
$ignoredJson = @{}
foreach ($domainin$uniqueIgnoredDomains) {
$ignoredJson["domain_$($ignoredJson.Count + 1)"] = $domain
}
$ignoredJsonString = $ignoredJson | ConvertTo-Json -Depth 10
$successMessage = "domain:$zoneName path:$outputFilePath row:$lineCount ignore: `n$ignoredJsonString"
Send-FeishuNotification -message $successMessage -color "blue"
} catch {
$errorMessage = $_.Exception.Message
$failureMessage = "failed $zoneName$errorMessage"
Send-FeishuNotification -message $failureMessage -color "black"
throw
}
#domainoutput.txt檔案內容輸出JSON LOG資訊
{"CimInstanceProperties":{"CimClass":"root/Microsoft/Windows/DNS:DnsServerResourceRecordA","CimInstanceProperties":"IPv4Address = \"20.20.20.20\"","CimSystemProperties":"Microsoft.Management.Infrastructure.CimSystemProperties"},"RecordType":"A","domain":"view.lu.cn","EndDate":"2008-08-08"}
{"CimInstanceProperties":{"CimClass":"root/Microsoft/Windows/DNS:DnsServerResourceRecordCName","CimInstanceProperties\"":"HostNameAlias = \"alb-cs.cn","CimSystemProperties":"Microsoft.Management.Infrastructure.CimSystemProperties"},"RecordType":"CNAME","domain":"pa.lu.cn","EndDate":"2025-05-31"}



* | SELECT "content.domain", "content.RecordType", "content.CimInstanceProperties.CimInstanceProperties" , "content.EndDate"from log LIMIT 1000


在本文中,我們詳細探討了如何透過自建DNS實現域名解析與證書告警的管理。透過建立Purview門戶、配置金鑰保管庫、實施流量回放和監控,我們不僅提高了資產的可見性,還確保了資料的安全性和合規性。隨著企業數字化轉型的不斷深入,資產梳理和安全運營將變得愈發重要。我們鼓勵大家定期進行資產審查和監控,以應對不斷變化的安全威脅和業務需求。感謝您對安全運營工作的關注與支援,讓我們共同努力,提升企業的安全防護水平,確保業務的持續穩定執行。
如有相關問題,請在文章後面給小編留言,小編安排作者第一時間和您聯絡,為您答疑解惑。