Skip to content

feat(dns_query): add expected IP validation and metrics for domain hijacking detection#1475

Merged
kongfei605 merged 2 commits into
flashcatcloud:mainfrom
kongfei605:dns_up
Jul 9, 2026
Merged

feat(dns_query): add expected IP validation and metrics for domain hijacking detection#1475
kongfei605 merged 2 commits into
flashcatcloud:mainfrom
kongfei605:dns_up

Conversation

@kongfei605

@kongfei605 kongfei605 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator
  • Add ExpectQueryIps configuration to specify expected IPs for target domains.
  • Enhance DNS response parsing to extract IPs from A and AAAA records.
  • Compare actual parsed IPs with expected IPs and expose status_change and status_change_detail metrics upon mismatch.
  • Append a new ips tag containing all returned IPs to the base dns_query metrics.
  • Add configuration examples and explanations to dns_query.toml.
  • Update English and Chinese README documentation with the new configuration and metrics details.

Copilot AI review requested due to automatic review settings July 9, 2026 08:03
@kongfei605 kongfei605 changed the title feat(dns_query): add expected IP validation and metrics for domain hi… feat(dns_query): add expected IP validation and metrics for domain hijacking detection Jul 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the dns_query input to support “expected IP” validation for DNS answers (aimed at detecting domain hijacking / unexpected resolution changes) and updates the accompanying docs/config/dashboard artifacts.

Changes:

  • Add expect_query_ips configuration and emit dns_query_status_change / dns_query_status_change_detail metrics.
  • Add an ips tag (comma-separated resolved IPs) to the main dns_query metrics.
  • Update README/README_CN, example TOML config, and dashboard to surface the new behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
inputs/dns_query/dns_query.go Implements expected-IP comparison, new metrics, and adds ips tag to samples.
inputs/dns_query/README.md Documents the new config knob and metrics.
inputs/dns_query/README_CN.md Chinese documentation for the new config knob and metrics.
conf/input.dns_query/dns_query.toml Adds commented example and explanation for expect_query_ips.
inputs/dns_query/dashboard.json Updates dashboard to visualize new metrics (and restructures dashboard format).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +183 to +203
if v, ok := ins.ExpectQueryIps[domain]; ok && v != nil {
sort.Slice(ips, func(i, j int) bool {
ip1 := net.ParseIP(ips[i])
ip2 := net.ParseIP(ips[j])
return bytes.Compare(ip1, ip2) < 0
})
minus, _ := diff(v, ips)
status := 0
if len(minus) > 0 {
status = 1

diffTags := make(map[string]string)
for k, v := range tags {
diffTags[k] = v
}
diffTags["diff"] = strings.Join(minus, ",")
diffTags["ips"] = strings.Join(ips, ",")
slist.PushSample(inputName, "status_change_detail", status, diffTags)
}
slist.PushSample(inputName, "status_change", status, tags)
}
Comment on lines +214 to +216
if len(ips) > 0 {
tags["ips"] = strings.Join(ips, ",")
}
Comment on lines +45 to +46
- `dns_query_status_change`: When `expect_query_ips` is configured, this value is 1 if any expected IP is missing from the result, otherwise 0.
- `dns_query_status_change_detail`: Reported only when there is a diff (value is 1). Includes a `diff` tag for missing IPs, and an `ips` tag for all returned IPs.
Comment on lines +45 to +46
- `dns_query_status_change`: 当配置了预期 IP 校验时,如果实际查询到的 IP 中缺失了预期 IP,则该值为 1,否则为 0。
- `dns_query_status_change_detail`: 当开启 IP 校验且存在差异时才会上报此指标(值为 1)。带有 `diff` 标签记录缺失的 IP 列表,`ips` 标签记录所有实际返回的 IP 列表。
# timeout = 2

## 监控域名劫持
## record_type必须为A/AAA, expect_query_ips中必须包含对应的域名和IP列表(ip列表越全越好)
Comment on lines 1 to +12
{
"title": "DNS Query Quality",
"uid": "82f9567e",
"tags": [
"dns query quality"
"version": "3.0.0",
"var": [
{
"name": "datasource",
"type": "datasource",
"definition": "prometheus",
"defaultValue": 1,
"label": "Datasource",
"hide": false
},
{
Copilot AI review requested due to automatic review settings July 9, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Comment on lines +164 to +184
if v, ok := ins.ExpectQueryIps[domain]; ok && v != nil {
sort.Slice(ips, func(i, j int) bool {
ip1 := net.ParseIP(ips[i])
ip2 := net.ParseIP(ips[j])
return bytes.Compare(ip1, ip2) < 0
})
minus, _ := diff(v, ips)
status := 0
if len(minus) > 0 {
status = 1

diffTags := make(map[string]string)
for k, v := range tags {
diffTags[k] = v
}
diffTags["diff"] = strings.Join(minus, ",")
diffTags["ips"] = strings.Join(ips, ",")
slist.PushSample(inputName, "status_change_detail", status, diffTags)
}
slist.PushSample(inputName, "status_change", status, tags)
}
Comment on lines +195 to +197
if len(ips) > 0 {
tags["ips"] = strings.Join(ips, ",")
}
# timeout = 2

## 监控域名劫持
## record_type必须为A/AAA, expect_query_ips中必须包含对应的域名和IP列表(ip列表越全越好)
## record_type必须为A/AAA, expect_query_ips中必须包含对应的域名和IP列表(ip列表越全越好)
## 对比响应中的IP与如下配置的IP,会生成两个新的指标 dns_query_status_change 与 dns_query_status_change_detail
## 当diff 不为空的时候 dns_query_status_change 为1 , diff 为空的时候 dns_query_status_change=0
## dns_query_status_change_detail{ips="响应的IP列表", diff="响应IP列表-期望IP列表"}
Comment on lines 1 to +12
{
"title": "DNS Query Quality",
"uid": "82f9567e",
"tags": [
"dns query quality"
"version": "3.0.0",
"var": [
{
"name": "datasource",
"type": "datasource",
"definition": "prometheus",
"defaultValue": 1,
"label": "Datasource",
"hide": false
},
{
@kongfei605 kongfei605 merged commit 1c9df74 into flashcatcloud:main Jul 9, 2026
3 checks passed
@kongfei605 kongfei605 deleted the dns_up branch July 9, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants