whoamiamleo/crt.sh.enum

GitHub: whoamiamleo/crt.sh.enum

通过直连 crt.sh 的 PostgreSQL 数据库,从证书透明度日志中快速、全面地枚举目标域名的子域名。

Stars: 1 | Forks: 0

# crt.sh.enum ![Python](https://img.shields.io/badge/Python-3.8%2B-blue?style=flat-square&logo=python&logoColor=white) ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-psycopg2-336791?style=flat-square&logo=postgresql&logoColor=white) ![License](https://img.shields.io/badge/License-MIT-green?style=flat-square) ![Platform](https://img.shields.io/badge/Platform-Linux%20%7C%20macOS%20%7C%20Windows-lightgrey?style=flat-square) ![Authorized Pentesting Only](https://img.shields.io/badge/⚠%EF%B8%8F%20Authorized%20Pentesting%20Only-critical?style=flat-square) 通过 [crt.sh](https://crt.sh) 证书透明度日志进行子域名枚举,使用直接的 PostgreSQL 连接以实现快速、无中断的查询。 ## 目录 - [功能](#features) - [工作原理](#how-it-works) - [安装说明](#installation) - [用法](#usage) - [示例](#examples) - [支持](#support) - [格式](#formatting) - [输入](#input) - [输出](#output) - [贡献](#contributing) - [归属](#attribution) - [法律与道德](#legal--ethics) - [许可证](#license) ## 功能 - **直接访问 PostgreSQL**:直接连接到 crt.sh 的公共只读副本数据库,绕过受速率限制的 HTTP API,以实现更快、更完整的查询。 - **每个证书的五个名称来源**:提取 Common Name、dNSName SANs、email SANs、URI SANs 和 CRL/AIA 主机名,以实现最大程度的覆盖。 - **批处理**:以 500 个为一批查询证书,以保持在服务器超时限制内,并渐进式流式传输结果。 - **自动重试**:当由于 PgBouncer 恢复冲突导致数据库连接失败时,自动重新连接并重试最多 5 次。 - **多域名**:在单次运行中枚举多个域名,并进行全局去重。 - **清晰的输出**:结果输出到 stdout,进度信息输出到 stderr——可以直接通过管道传递给其他工具而不会产生干扰。 ## 工作原理 大多数 crt.sh 工具访问的是 JSON HTTP 端点,该端点对于大型域名来说具有速率限制、需要分页且速度较慢。此工具直接连接到 crt.sh 的公共 PostgreSQL 只读副本(`crt.sh:5432`,用户 `guest`,数据库 `certwatch`),这也是为该网站提供支持的同一个数据库。 **名称来源** — 对于每个与您的目标域名匹配的证书,将提取五个来源: | # | 来源 | 字段 | |---|---|---| | 1 | Common Name + dNSName SANs | `2.5.4.3`、`san:dNSName` | | 2 | Email SANs | `san:rfc822Name`(提取 `@` 之后的域名) | | 3 | URI SANs | `san:uniformResourceIdentifier`(取自 URI 的主机名) | | 4 | CRL Distribution Point URLs | 通过正则表达式提取的主机名 | | 5 | Authority Information Access URLs | 通过正则表达式提取的主机名 | **查询策略** — 阶段 1 使用 `identities(certificate)` 上的 GIN 索引配合 `to_tsquery`,在单次查询中获取所有匹配的证书 ID。阶段 2 为每批 500 个证书 ID 提取全部 5 种名称来源。新的唯一名称会在每批次处理完后立即写入输出,从而实现结果的渐进式流式传输。 **可靠性** — crt.sh 在 PostgreSQL 热备节点上运行 [PgBouncer](https://www.pgbouncer.org/),采用语句池化模式。恢复冲突可能会导致 TCP 连接在查询过程中断开。该工具会自动重新连接并重试最多 5 次(每次延迟 10 秒),然后才会放弃。 ## 安装说明 **需要 Python 3.8+** ``` git clone https://github.com/whoamiamleo/crt.sh.enum.git cd crt.sh.enum pip install -r requirements.txt ``` 或者直接安装该单一依赖项: ``` pip install psycopg2-binary ``` ## 用法 ``` usage: crt.sh.enum.py [-h] [-d FILE] [-v] [-o FILE] [domains ...] positional arguments: domains Domain(s) to enumerate options: -d FILE, --domains FILE File containing newline-separated domains -v, --verbose Print connection and query progress messages -o FILE, --output FILE Write results to FILE instead of stdout ``` ### 示例 ``` # 单个 domain python crt.sh.enum.py example.com # 多个 domain python crt.sh.enum.py example.com another.com # 来自文件的 domain python crt.sh.enum.py -d domains.txt # 详细输出,保存至文件 python crt.sh.enum.py example.com -d domains.txt -v -o results.txt # 通过管道传入 sort 以获取整洁的输出 python crt.sh.enum.py example.com | sort -u | tee subdomains.txt ``` 如果未找到结果,退出代码为 `1`,否则为 `0`。 ## 支持 | 需求 | 详情 | |---|---| | Python | 3.8+ | | 外部服务 | crt.sh 公共 PostgreSQL 副本 (`crt.sh:5432`) | | macOS | ✅ | | Linux | ✅ | | Windows | ✅ | 结果会在单次运行中跨所有域名进行全局去重。通配符前缀 (`*.`) 会在输入和输出中自动去除。该工具不执行 DNS 解析或存活检查——它只枚举存在于证书透明度日志中的名称。 ## 格式 ### 输入 域名可作为位置参数提供,或通过纯文本文件(`-d`)提供。每行一个域名。以 `#` 开头的行和空行将被忽略。 ``` # targets example.com another.com ``` ### 输出 结果将写入 **stdout**(或使用 `-o` 写入文件),每行一个子域名。进度和状态信息会输出到 **stderr**,保持 stdout 干净以便通过管道传递。 ``` dev.example.com mail.example.com www.example.com ``` ## 归属 如果您在项目或研究中使用了 crt.sh.enum,希望能提及或链接回本仓库。 - 作者:Leopold von Niebelschuetz-Godlewski - 仓库:[https://github.com/whoamiamleo/crt.sh.enum](https://github.com/whoamiamleo/crt.sh.enum) - 许可证:MIT ## 法律与道德 crt.sh.enum 仅用于授权的安全测试和研究活动。严禁任何未经授权的使用。作者对因不当或非法使用而导致的滥用或损害不承担任何责任。 ## 许可证 MIT License Copyright (c) 2026 Leopold von Niebelschuetz-Godlewski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
标签:ESC4, OSINT, PostgreSQL, psycopg2, Python, 域名探测, 多平台, 威胁建模, 子域名枚举, 批量处理, 无后门, 正则匹配, 测试用例, 白帽黑客, 系统安全, 网络安全, 证书透明度, 逆向工具, 隐私保护