BBOT 高级用法完全指南:Python 库集成与命令行深度解析
2026/9/15 18:45:12 网站建设 项目流程

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的构造函数接受与命令行等价的参数:目标(可变数量)、presetsmodulesoutput_modulesconfigscan_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.jsonscan.logdebug.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指定输出模块(默认csvjsonpythontxt
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-enumkitchen-sink
-c, --configkey=value形式指定自定义配置,如modules.shodan.api_key=1234;也可传入 YAML 文件
-lp, --list-presets列出可用预设

预设是 BBOT 组织常用扫描组合的方式。关于预设文件格式(modulesblacklistconfig等字段)可参考 docs/scanning/presets.md,仓库中的实际预设样例位于 bbot/presets(例如subdomain-enum.ymlkitchen-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

每个模块都带有若干标志(如securitytrailspassivesafesubdomain-enum),标志组合是精细控制扫描面最有效的手段。完整标志与模块对应关系见 docs/scanning/index.md 的"List of Flags"表格。从 bbot/cli.py 的源码可见,启用 deadly 模块(ffuflegbalightfuzzmedusanucleivhost)时会强制要求--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 等),默认启用humanjsoncsv三种。各输出模块的配置项(如modules.json.siem_friendlymodules.mysql.hostmodules.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_failedignore_faileddisable(见 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_distancespider_depth是全局web配置项(默认分别为01),-c直接以点分路径覆盖;相关配置还有web.spider_links_per_page(默认 25)。完整的webdnsscopeengine等全局配置项与默认值见 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),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询