anthonyg-1/connectivity-test-zone

GitHub: anthonyg-1/connectivity-test-zone

该脚本整合 subfinder 和 nmap,实现对目标域名的子域名枚举、DNS 解析和 TCP 端口连通性检测,并输出结构化 JSON 结果。

Stars: 0 | Forks: 0

# connectivity-test-zone `connectivity-test-zone` 用于枚举一个或多个目标域名的 DNS 子域名, 解析每个主机名,测试选定的 TCP 端口,并输出 JSON 格式的连通性 结果。 ## 功能说明 - 针对提供的域名或文本文件中的每个域名运行 `subfinder`。 - 在扫描之前解析每个主机名。 - 对于无法解析的名称跳过 `nmap`。 - 使用 `nmap` 测试选定的 TCP 端口。 - 在打印进度信息的同时,抑制 `subfinder` 和 `nmap` 产生的冗余输出。 - 通过 `jq -C` 向控制台输出带有颜色的 JSON。 - 可选择保存不含 ANSI 颜色代码的纯净有效 JSON。 - 在顶层 JSON 对象中包含本地的出口源 IP 地址以及运行的日期/时间。 ## JSON schema ``` { "domain": "example.com", "source_ip": "192.0.2.10", "run_datetime": "6/26/2026 2:41 PM EDT", "results": [ { "target": "api.example.com", "ipaddress": "192.0.2.20", "resolved": true, "connected": true, "ports": [80, 443] } ] } ``` ## 依赖项 - `subfinder` - `nmap` - `python3` - `jq` - `sed` - `grep` - `sort` - `wc` - `tr` - `date` - `mktemp` - `mkdir` - `cp` - `cat` - `rm` ## macOS 安装说明 使用 Homebrew 安装常用依赖项: ``` brew install jq nmap shellcheck shfmt ``` 使用 Go 安装 `subfinder`: ``` go install github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest ``` 确保你的 Go 二进制文件路径位于 `PATH` 中。常见的设置如下: ``` export PATH="$PATH:$HOME/go/bin" ``` ## Linux 安装说明 在 Debian/Ubuntu 上,使用以下命令安装常用软件包: ``` sudo apt update sudo apt install -y jq nmap python3 sed grep coreutils findutils ``` 使用 Go 安装 `subfinder`: ``` go install github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest ``` 确保你的 Go 二进制文件路径位于 `PATH` 中。常见的设置如下: ``` export PATH="$PATH:$HOME/go/bin" ``` ## 用法 ``` ./connectivity-test-zone.sh --domain example.com ./connectivity-test-zone.sh -d example.com ./connectivity-test-zone.sh --domains-file domains.txt ./connectivity-test-zone.sh -df domains.txt ./connectivity-test-zone.sh --domain example.com --ports 22,80,443 ./connectivity-test-zone.sh -d example.com -p 22,80,443 ./connectivity-test-zone.sh --domain example.com --outjson ./connectivity-test-zone.sh -d example.com -oj ./connectivity-test-zone.sh --domain example.com --outjson --outdir ./results ./connectivity-test-zone.sh -d example.com -oj -od ./results ``` 默认端口: ``` 20,21,22,23,25,53,80,88,111,135,139,389,443,445,464,593,636,1433,1521,2049,2379,2380,3268,3269,3306,3389,5432,5672,5900,5985,5986,6379,6443,8000,8080,8081,8433,8443,9000,9200,9389,10250,27017 ``` 使用 `--ports` 或 `-p` 可覆盖默认列表。 使用 `--domains-file` 或 `-df` 可从文本文件中读取根域名,每行一个域名。 空行将被忽略。如果文件不存在,脚本将在扫描前退出并报错。 ## 权限 脚本在以 root 身份运行时使用 `nmap -sS`,否则使用 `nmap -sT`。 ## 输出 控制台输出的 JSON 会通过 `jq -C` 进行着色。保存的 JSON 为纯净的有效 JSON。 单域名运行结果包含一个顶层的 `domain` 字符串。基于文件且包含多个域名的运行结果包含一个顶层的 `domains` 数组。 如果存在 `--outjson`,脚本将保存 `connectivity-results.json`。 如果同时提供了 `--outdir`,JSON 文件将保存在该目录中。 如果存在 `--outjson` 但没有 `--outdir`,JSON 文件将保存在 当前目录中。 如果不存在 `--outjson`,脚本将不会创建任何持久化的输出 文件或目录。 ## 临时文件 临时文件会在一个由 `mktemp -d` 创建的工作目录中生成,并在退出时自动 删除。只有在使用 `--outjson` 时才会写入持久化的 JSON。 脚本不会留下持久化的 `.nmap`、`.gnmap` 或 `.xml` 文件。 ## 开发检查 ``` bash -n connectivity-test-zone.sh shellcheck connectivity-test-zone.sh shfmt -d connectivity-test-zone.sh ``` 该脚本还包含一个内嵌的 Python heredoc。在运行 Python linting 和语法 检查之前,请先将其提取出来: ``` awk \ '/<<'\''PY'\''/{flag=1; next} /^PY$/{flag=0} flag {print}' \ connectivity-test-zone.sh > /tmp/connectivity-test-zone-embedded.py ruff check /tmp/connectivity-test-zone-embedded.py ruff format --check /tmp/connectivity-test-zone-embedded.py python3 -m py_compile /tmp/connectivity-test-zone-embedded.py ```
标签:Cutter, 主机安全, 云存储安全, 子域名枚举, 系统安全, 网络安全, 网络扫描, 逆向工具, 隐私保护