BBOT 高级用法完全指南:Python 库集成与命令行深度解析
【免费下载链接】bbotThe recursive internet scanner for hackers. 🧡项目地址: https://gitcode.com/GitHub_Trending/bb/bbot
本文以 docs/scanning/advanced.md 为骨架,系统讲解 BBOT(The recursive internet scanner for hackers)的两大进阶能力:一是将 BBOT 作为 Python 库嵌入自己的代码(同步/异步两种模式),二是对完整命令行接口(CLI)进行逐组拆解。读完本文,你将能够用几行 Python 代码驱动一次完整扫描、按需消费事件流,并精确控制目标、模块、输出与依赖安装等全部命令行参数。
一、把 BBOT 当作 Python 库使用
BBOT 的核心入口是Scanner类(源码位于 bbot/scanner/scanner.py),它代表一次独立的扫描。通过 Python 库方式使用 BBOT,你可以把子域名枚举、端口扫描、指纹识别等能力嵌入自己的脚本、CI/CD 流水线或安全自动化平台。
Scanner的构造函数接受与命令行等价的参数:目标(可变数量)、presets、modules、output_modules、config、scan_name等。源码注释中的示例给出了基本用法:
# 多目标 + 多模块 my_scan = Scanner("evilcorp.com", "1.2.3.0/24", modules=["portscan", "sslcert", "httpx"]) # 自定义配置 config = {"http_proxy": "http://127.0.0.1:8080", "modules": {"portscan": {"top_ports": 2000}}} my_scan = Scanner("www.evilcorp.com", modules=["portscan", "httpx"], config=config)1.1 同步模式:start()
最简单的集成方式是使用Scanner.start(),它返回一个同步生成器,逐条产出扫描过程中发现的事件:
from bbot.scanner import Scanner if __name__ == "__main__": scan = Scanner("evilcorp.com", presets=["subdomain-enum"]) for event in scan.start(): print(event)1.2 异步模式:async_start()
在 asyncio 环境中,推荐使用async_start()异步生成器。每个事件对象可以通过.json()序列化为结构化数据,便于后续落库或转发:
from bbot.scanner import Scanner async def main(): scan = Scanner("evilcorp.com", presets=["subdomain-enum"]) async for event in scan.async_start(): print(event.json()) if __name__ == "__main__": import asyncio asyncio.run(main())1.3 不消费事件:start_without_generator()
如果你的目的是"跑完一次扫描"而不是逐条处理事件(例如事件由输出模块负责写文件、推送到 SIEM),可以使用无生成器变体。源码 scanner.py 显示这些方法是相互转化的:
def start(self): for event in async_to_sync_gen(self.async_start()): yield event def start_without_generator(self): for event in async_to_sync_gen(self.async_start()): pass async def async_start_without_generator(self): async for event in self.async_start(): pass即同步版start()本质上是async_start()经async_to_sync_gen适配后的包装;start_without_generator()与async_start_without_generator()则是"只管启动、丢弃事件流"的快捷方式。测试 bbot/test/test_step_1/test_python_api.py 验证了这些用法,例如用output_modules=["json"]扫描127.0.0.1后,会在扫描目录下生成output.json、scan.log、debug.log,且每次扫描的日志写入各自独立的目录。
1.4 与命令行参数一一对应
库 API 与 CLI 参数是同一套抽象(CLI 最终也走Scanner(preset=preset)这条路径,见 bbot/cli.py)。常用的构造函数参数包括:
| 库参数 | 对应 CLI | 说明 |
|---|---|---|
*targets | -t | 扫描目标,支持 DNS 名称、IP、IP 段、端口、URL、邮箱、ORG/USER 桩等 |
presets | -p | 启用预设(如["subdomain-enum"]) |
modules | -m | 显式启用扫描模块 |
output_modules | -om | 指定输出模块(默认csv、json、python、txt) |
exclude_modules | -em | 排除指定模块 |
flags/require_flags/exclude_flags | -f/-rf/-ef | 按标志批量启用/约束模块 |
config | -c | 自定义配置字典(等效于key=value) |
scan_name | -n | 扫描名称,决定~/.bbot/scans/<名称>下的输出目录 |
strict_scope | --strict-scope | 严格作用域 |
参数校验逻辑也值得注意:无效的目标、模块名、输出模块名、标志都会抛出ValidationError,并给出"Did you mean"纠错提示。例如Scanner("asdf:::asdf")会报Unable to autodetect data type from "asdf:::asdf",Scanner(modules=["json"])会报Could not find scan module "json"——这些行为都有对应测试用例(见 test_python_api.py),说明 Python 库与 CLI 共享同一套严格校验,集成时可以放心依赖异常语义。
二、命令行接口(CLI)完整参考
bbot命令的帮助信息由 bbot/cli.py 中的参数解析器生成。以下是完整的 usage 与全部参数组:
usage: bbot [-h] [-t TARGET [TARGET ...]] [-w WHITELIST [WHITELIST ...]] [-b BLACKLIST [BLACKLIST ...]] [--strict-scope] [-p [PRESET ...]] [-c [CONFIG ...]] [-lp] [-m MODULE [MODULE ...]] [-l] [-lmo] [-em MODULE [MODULE ...]] [-f FLAG [FLAG ...]] [-lf] [-rf FLAG [FLAG ...]] [-ef FLAG [FLAG ...]] [--allow-deadly] [-n SCAN_NAME] [-v] [-d] [-s] [--force] [-y] [--fast-mode] [--dry-run] [--current-preset] [--current-preset-full] [-mh MODULE] [-o DIR] [-om MODULE [MODULE ...]] [-lo] [--json] [--brief] [--event-types EVENT_TYPES [EVENT_TYPES ...]] [--exclude-cdn] [--no-deps | --force-deps | --retry-deps | --ignore-failed-deps | --install-all-deps] [--version] [--proxy HTTP_PROXY] [-H CUSTOM_HEADERS [CUSTOM_HEADERS ...]] [-C CUSTOM_COOKIES [CUSTOM_COOKIES ...]] [--custom-yara-rules CUSTOM_YARA_RULES] [--user-agent USER_AGENT]命令行参数可分为六个组,下面逐一说明。
2.1 Target(目标与作用域)
| 参数 | 说明 |
|---|---|
-t, --targets | 用于种子化扫描的目标,可指定任意多个(支持文件路径,可混合 CLI 与文件) |
-w, --whitelist | 定义何为"在作用域内"(默认与--targets相同) |
-b, --blacklist | 完全排除这些资源(优先级最高,甚至高于白名单) |
--strict-scope | 不把目标/白名单的子域名视为在作用域内 |
关于目标类型与作用域(Scope Distance、通配符检测等)的完整说明,参见 docs/scanning/index.md。注意--strict-scope只作用于目标与白名单、不作用于黑名单——即使开启严格作用域,放入黑名单的internal.evilcorp.com的所有子域名也都会被排除。
2.2 Presets(预设与配置)
| 参数 | 说明 |
|---|---|
-p, --preset | 启用 BBOT 预设(如subdomain-enum、kitchen-sink) |
-c, --config | 以key=value形式指定自定义配置,如modules.shodan.api_key=1234;也可传入 YAML 文件 |
-lp, --list-presets | 列出可用预设 |
预设是 BBOT 组织常用扫描组合的方式。关于预设文件格式(modules、blacklist、config等字段)可参考 docs/scanning/presets.md,仓库中的实际预设样例位于 bbot/presets(例如subdomain-enum.yml、kitchen-sink.yml)。配置加载顺序为:全局配置~/.config/bbot/bbot.yml→ 预设 → 命令行-c覆盖(优先级最高),详见 docs/scanning/configuration.md。
2.3 Modules(模块管理)
| 参数 | 说明 |
|---|---|
-m, --modules | 启用指定模块,可选模块全集见下 |
-l, --list-modules | 列出所有可用模块 |
-lmo, --list-module-options | 显示所有模块的配置选项 |
-em, --exclude-modules | 排除指定模块 |
-f, --flags | 按标志启用模块(如-f subdomain-enum) |
-lf, --list-flags | 列出所有可用标志 |
-rf, --require-flags | 仅启用带有这些标志的模块(如-rf passive) |
-ef, --exclude-flags | 禁用带有这些标志的模块(如-ef aggressive) |
--allow-deadly | 允许使用高度激进(deadly)的模块 |
可选的扫描模块(-m的 choices)包括:affiliates, ajaxpro, anubisdb, apkpure, asn, aspnet_bin_exposure, azure_tenant, baddns, baddns_direct, baddns_zone, badsecrets, bevigil, bucket_amazon, bucket_digitalocean, bucket_file_enum, bucket_firebase, bucket_google, bucket_microsoft, bufferoverrun, builtwith, bypass403, c99, censys_dns, censys_ip, certspotter, chaos, code_repository, credshed, crt, crt_db, dehashed, dnsbimi, dnsbrute, dnsbrute_mutations, dnscaa, dnscommonsrv, dnsdumpster, dnstlsrpt, docker_pull, dockerhub, dotnetnuke, emailformat, extractous, ffuf, ffuf_shortnames, filedownload, fingerprintx, fullhunt, generic_ssrf, git, git_clone, gitdumper, github_codesearch, github_org, github_usersearch, github_workflows, gitlab_com, gitlab_onprem, google_playstore, gowitness, graphql_introspection, hackertarget, host_header, httpx, hunt, hunterio, iis_shortnames, ip2location, ipneighbor, ipstack, jadx, leakix, legba, lightfuzz, medusa, myssl, newsletters, ntlm, nuclei, oauth, otx, paramminer_cookies, paramminer_getparams, paramminer_headers, pgp, portfilter, portscan, postman, postman_download, rapiddns, reflected_parameters, retirejs, robots, securitytrails, securitytxt, shodan_dns, shodan_idb, skymem, smuggler, social, sslcert, subdomaincenter, subdomainradar, telerik, trickest, trufflehog, url_manipulation, urlscan, vhost, viewdns, virustotal, wafw00f, wayback, wpscan。
可用标志(-f的 choices)包括:active, affiliates, aggressive, baddns, cloud-enum, code-enum, deadly, download, email-enum, iis-shortnames, passive, portscan, safe, service-enum, slow, social-enum, subdomain-enum, subdomain-hijack, web-basic, web-paramminer, web-screenshots, web-thorough。
每个模块都带有若干标志(如securitytrails是passive、safe、subdomain-enum),标志组合是精细控制扫描面最有效的手段。完整标志与模块对应关系见 docs/scanning/index.md 的"List of Flags"表格。从 bbot/cli.py 的源码可见,启用 deadly 模块(ffuf、legba、lightfuzz、medusa、nuclei、vhost)时会强制要求--allow-deadly,这是防止误用高度侵入性模块的硬性保护。
2.4 Scan(扫描行为)
| 参数 | 说明 |
|---|---|
-n, --name | 扫描名称(默认随机生成) |
-v, --verbose | 更详细的输出 |
-d, --debug | 启用调试输出 |
-s, --silent | 静默模式 |
--force | 即使存在条件违规或模块设置失败也继续扫描 |
-y, --yes | 跳过扫描确认提示 |
--fast-mode | 只扫描给定目标、不做额外发现,尽可能快 |
--dry-run | 在执行扫描前中止 |
--current-preset | 以 YAML 格式显示当前预设 |
--current-preset-full | 以完整形式(含默认值)显示当前预设 |
-mh, --module-help | 显示指定模块的帮助 |
关于扫描名称:每次扫描默认获得一个随机的趣味名称(如demonic_jimmy),输出与截图保存在~/.bbot/scans/<名称>,最近 20 次扫描会被保留。-n指定名称后,输出会落到当前目录下同名文件夹(配合-o)。交互式终端中,扫描开始前会要求回车确认,运行期间输入kill <module>可热停某个模块、直接回车可切换日志级别并查看模块状态——这些逻辑都在 bbot/cli.py 中实现。
2.5 Output(输出控制)
| 参数 | 说明 |
|---|---|
-o, --output-dir | 扫描结果输出目录 |
-om, --output-modules | 指定输出模块,可选:asset_inventory, csv, discord, emails, http, json, mysql, neo4j, nmap_xml, postgres, python, slack, splunk, sqlite, stdout, subdomains, teams, txt, web_parameters, web_report, websocket |
-lo, --list-output-modules | 列出所有可用输出模块 |
--json, -j | 以 JSON 格式输出扫描数据 |
--brief, -br | 只输出数据本身 |
--event-types | 选择显示哪些事件类型 |
--exclude-cdn, -ec | 过滤掉 CDN/WAF 上不想要的开放端口(仅保留 80、443) |
输出模块负责把事件投递到不同目的地(文件、数据库、Webhook、SIEM 等),默认启用human、json、csv三种。各输出模块的配置项(如modules.json.siem_friendly、modules.mysql.host、modules.discord.webhook_url)可通过-c或配置文件设置,完整清单见 docs/scanning/configuration.md 与 docs/scanning/output.md。
2.6 Module dependencies(模块依赖管理)
模块可能依赖 OS 包(如openssl)、外部二进制(如nuclei)或 Python 库(如wappalyzer)。启用模块时,其依赖会在运行时通过 Ansible 自动安装(详见 docs/scanning/index.md 的 Dependencies 一节,以及模块编写指南 docs/dev/module_howto.md)。命令行提供五个互斥参数:
| 参数 | 说明 |
|---|---|
--no-deps | 不安装模块依赖 |
--force-deps | 强制安装所有模块依赖 |
--retry-deps | 重试安装失败的依赖 |
--ignore-failed-deps | 即使依赖失败也运行模块 |
--install-all-deps | 为所有模块安装依赖(适合在渗透测试工作机上提前预置) |
依赖失败时的默认行为是"中止扫描",可通过deps.behavior配置改为retry_failed、ignore_failed或disable(见 bbot/defaults.yml)。--install-all-deps在 bbot/cli.py 中的实现是:创建一个包含全部模块的"虚拟扫描",仅执行依赖安装与模块 setup(deps_only=True),完成后清理临时目录,非常适合批量预装环境。
2.7 Misc(杂项)
| 参数 | 说明 |
|---|---|
--version | 显示 BBOT 版本并退出 |
--proxy HTTP_PROXY | 所有 HTTP 请求走该代理 |
-H, --custom-headers | 自定义请求头,格式header=value,可多个 |
-C, --custom-cookies | 自定义 Cookie,格式cookie=value,可多个 |
--custom-yara-rules, -cy | 为 excavate 添加自定义 YARA 规则 |
--user-agent, -ua | 设置所有 HTTP 请求的 User-Agent |
三、开箱即用的实战示例
原文档在 CLI 帮助末尾给出了经过验证的常用命令组合,这里完整保留并逐条注释:
# 子域名枚举 bbot -t evilcorp.com -p subdomain-enum # 仅被动子域名枚举(不主动连接目标系统) bbot -t evilcorp.com -p subdomain-enum -rf passive # 子域名 + 端口扫描 + Web 截图(指定扫描名与输出目录) bbot -t evilcorp.com -p subdomain-enum -m portscan gowitness -n my_scan -o . # 子域名 + 基础 Web 扫描 bbot -t evilcorp.com -p subdomain-enum web-basic # Web 爬虫:限制连续跟进链接数(spider_distance=2)与目录深度(spider_depth=2) bbot -t www.evilcorp.com -p spider -c web.spider_distance=2 web.spider_depth=2 # 全功能扫描(kitchen-sink 预设) bbot -t evilcorp.com -p kitchen-sink # 列出模块 / 输出模块 / 预设 / 标志 bbot -l bbot -lo bbot -lp bbot -lf # 查看指定模块的帮助 bbot -mh <module_name>注意spider_distance与spider_depth是全局web配置项(默认分别为0和1),-c直接以点分路径覆盖;相关配置还有web.spider_links_per_page(默认 25)。完整的web、dns、scope、engine等全局配置项与默认值见 bbot/defaults.yml 及 docs/scanning/configuration.md。
四、进一步阅读
- 扫描基础概念(目标类型、模块分类、标志、依赖、作用域与 Scope Distance、DNS 通配符检测):docs/scanning/index.md
- 配置体系(配置文件优先级、全局/模块级配置项全表):docs/scanning/configuration.md
- 事件模型与输出:<docs/scanning/events.md> 与 docs/scanning/output.md
- 预设文件格式与内置预设列表:docs/scanning/presets.md 与 docs/scanning/presets_list.md
- 全部模块清单及说明:docs/modules/list_of_modules.md
- 编写自定义模块(含依赖声明方式):docs/dev/module_howto.md
- Python API 实测用例:bbot/test/test_step_1/test_python_api.py
至此,你既可以在 Python 脚本中以同步/异步方式驱动 BBOT 并消费事件流,也能熟练运用命令行六大参数组精确控制每一次递归扫描。两条路径共享同一套Scanner/Preset抽象,从原型验证平滑迁移到自动化平台时无需重写逻辑。
【免费下载链接】bbotThe recursive internet scanner for hackers. 🧡项目地址: https://gitcode.com/GitHub_Trending/bb/bbot
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考