Dxsk/dotenv-sec
GitHub: Dxsk/dotenv-sec
渗透测试环境一键启动器,通过单一 CLI 统一管理 tmux 会话、MITM 代理、隔离浏览器、Exegol 集成及 OOB 监听器,为每个测试任务提供完整、隔离的攻击性安全工作区。
Stars: 1 | Forks: 0
# dotenv-sec
[](https://github.com/Dxsk/dotenv-sec/actions/workflows/ci.yml)
[](LICENSE)
[](https://www.gnu.org/software/bash/)
[](https://www.docker.com/)
[](https://exegol.com/)
[](https://trivy.dev/)
**渗透测试环境启动器**:一个 CLI 即可启动您的整个攻击性安全工作区:
- tmux 会话
- MITM proxy
- 隔离的 Chromium
- Exegol 集成
- 一条侦察 → 扫描 → 审计的完整流水线
## 架构
```
dotsec new acme-corp example.com
│
├─► /workspace/acme-corp/ ← full engagement tree
│ └─ .env ← per-engagement vars
│
├─► tmux session "acme-corp" ← 6 windows (recon→monitor)
│
├─► mitmproxy container ← proxy:9999 + webUI:9998
│ └─► chromium container ← routed through proxy
│
└─► homer dashboard ← all services at a glance (port 9997)
```
## 快速开始
```
# 安装
make install
# 新测试任务:workspace + proxy + Exegol + tmux + proxied browser
dotsec new acme-corp example.com
# 将测试任务 env source 到当前 shell
dotsec load acme-corp
# 可选:dashboard,然后附加 tmux session
dotsec board up
dotsec tmux attach acme-corp
```
## 命令
| 命令 | 描述 |
|---------|-------------|
| `dotsec new [-w ] [domain]` | 初始化工作区 + proxy + Exegol + tmux |
| `dotsec load ` | 加载测试项目的环境变量 |
| `dotsec unload` | 取消设置所有测试项目的变量 |
| `dotsec list` | 列出 `/workspace/` 下的所有项目 |
| `dotsec spawn [session]` | 在 Exegol 中生成 6 窗口的渗透测试 tmux 并连接 |
| `dotsec proxy up\|down\|status\|logs` | 管理 mitmproxy Docker 容器 |
| `dotsec browser [target]` | 启动通过代理路由的 Chromium |
| `dotsec listener up\|down\|logs\|status` | OOB HTTP 回调服务器 + ssh 隧道 |
| `dotsec board up\|down\|reload\|status` | 位于 http://127.0.0.1:9997 的 Homer 仪表板 |
| `dotsec secrets [target]` | 显示测试项目的掩码密钥状态 |
| `dotsec rotate [target] [type]` | 重新生成密钥 (all\|token\|mitmweb\|ssh\|ca) |
| `dotsec tmux attach\|create\|kill\|ls` | Exegol 内部的 tmux 会话 |
| `dotsec log ` | 运行命令并记录到 `commands.log` |
| `dotsec archive [target]` | 将工作区归档为 tar.gz |
| `dotsec rm [--archive]` | 移除测试项目 (容器 + 工作区) |
| `dotsec stop ` | 停止该项目的 proxy + tmux |
| `dotsec restart ` | 重启 proxy + Exegol + tmux |
| `dotsec exegol exec\|shell\|setup` | 在 Exegol 内部运行命令 / 配置工具 |
| `dotsec status [target]` | 概览:测试项目、proxy/tmux、统计数据 |
| `dotsec info` | 显示当前测试项目 + 全局配置状态 |
## 配置
### 全局默认设置:`~/.config/dotenvsec/config`
```
export EXEGOL_CONTAINER="exegol" # default Exegol container
export UA="H1-yourhandle" # default User-Agent
export PROXY_PORT="9999"
export WEB_PORT="9998"
export HOMER_PORT="9997"
export PLATFORM="h1" # h1 | ywh | inti | custom
```
### 单个测试项目:`/workspace/$TARGET/.env`
```
export TARGET="acme-corp"
export DOMAIN="acme-corp.com"
export UA="H1-myhandle"
export HTTP_PROXY="http://127.0.0.1:9999"
export EXEGOL_CONTAINER="exegol"
```
## 密钥
每次运行 `dotsec new` 都会为该项目生成专属密钥(幂等操作,绝不提交)到工作区:
- `.env.secrets` (chmod 600): `DOTSEC_SESSION_SECRET`, `DOTSEC_API_TOKEN`, `MITMWEB_PASS`
- `keys/id_ed25519`: 临时的 Ed25519 SSH 密钥 (600),`keys/id_ed25519.pub` (644)
- CA 证书:在首次执行 `proxy up` 时生成至 `proxy/certs/`
```
dotsec secrets acme-corp # show masked status (never prints values)
dotsec rotate acme-corp # regenerate all secrets (prompts for ssh/ca/all)
dotsec rotate acme-corp token # rotate tokens only (no prompt)
dotsec rotate acme-corp mitmweb # rotate proxy password only (no prompt)
```
## MITM Proxy
```
dotsec proxy up # start mitmproxy container
# → Proxy : http://127.0.0.1:9999
# → Web UI : http://127.0.0.1:9998
# → CA PEM : /workspace/$TARGET/proxy/certs/mitmproxy-ca-cert.pem
dotsec proxy status # check container
dotsec proxy logs # tail container logs
dotsec proxy down # stop container
```
### 浏览器集成
在您的浏览器中安装一次 CA 证书,然后:
```
dotsec browser # Chromium auto-routed through proxy
```
或者将任何浏览器配置为使用 `http://127.0.0.1:9999` 作为 HTTP/HTTPS proxy。
## Exegol 集成
```
dotsec exegol shell # open shell in Exegol
dotsec exegol exec nmap -sV target # run command inside Exegol
dotsec exegol exec "sqlmap -u ..." # quoted multi-word commands
dotsec exegol setup # install uv + pnpm inside Exegol
```
### Exegol 工具配置
该项目附带了一个 `my-resources` 包,通过 `make exegol-setup`(也会由 `make install` 运行)部署(合并)到 `~/.exegol/my-resources/`。
该包包含:
- **recon** 脚本:`recon-subs`, `recon-alive`, `recon-fingerprint`, `recon-portscan`, `recon-screenshot`, `recon-crawl`, `recon-urls`, `recon-loot`, `recon-extract`, `recon-sourcemaps`, `recon-full`, `dl`
- **scan** 脚本:`scan-nuclei` (漏洞扫描),`scan-takeover` (悬空 CNAME;subzy → nuclei 后备)
- **audit** 脚本:`audit-code` (密钥/SAST/SCA),`audit-sinks` (危险函数),`audit-endpoints` (路由 + JS 攻击面),`audit-hotspots` (排名候选者),`audit-full`
- Shell 别名和预加载的历史记录
- `load_user_setup.sh`:脚本所需的、但基础镜像中缺失的工具的幂等安装程序 (xnLinkFinder, waymore, sourcemapper, osv-scanner, …)
```
make exegol-setup # deploy/merge bundle to ~/.exegol/my-resources/
```
脚本在 Exegol 容器**内部**运行,由项目的环境变量(`$DOMAIN`, `$WORKSPACE`)驱动。
在加载了项目的窗口中的典型流程:
```
recon-full # discovery → portscan → screenshots → crawl → loot → JS extract
scan-nuclei # vulnerability scan of the alive hosts (routed through the proxy)
scan-takeover # subdomain takeover check
audit-code # white-box audit of recovered source / sourcemaps
audit-full # full white-box pass: secrets + SCA + sinks + endpoints + ranked hotspots
```
首次启动容器时,Exegol 会自动运行 `/opt/my-resources/setup/load_user_setup.sh`。
要手动触发它(也会安装缺失的工具):
```
dotsec exegol setup
```
## OOB 监听器
带外 (Out-of-band) HTTP 回调服务器(用于 SSRF/XXE/SSTI 盲注)位于容器中,通过无身份验证的 `ssh -R` 隧道 (localhost.run) 进行公开暴露。仅支持 HTTP。
```
dotsec listener up # container + public URL (in workspace/oob/url.txt)
dotsec listener up --no-tunnel # local only (127.0.0.1:9996), expose it yourself
dotsec listener logs # tail captured hits (workspace/oob/hits.log)
dotsec listener status # container + public URL
dotsec listener down # stop container + kill tunnel
```
每次命中都会记录时间戳、源 IP、方法、路径、标头和正文。
## Docker 安全
- 基础镜像通过 `@sha256` 摘要进行固定
- 目前容器以 root 身份运行(非 root 权限强化被单独跟踪);所有服务端口均 >1024(兼容无 root 权限的 Docker)
- CI 流水线在每次推送时运行 Trivy 漏洞扫描
- 每周一进行定时扫描 + 自动创建 CVE issue
## Makefile
| 目标 | 描述 |
|--------|-------------|
| `make install` | 完整设置:symlinks + config + shell 集成 + 构建镜像 |
| `make build` | 构建所有 Docker 镜像 |
| `make scan` | 在所有镜像上运行 Trivy 漏洞扫描器 |
| `make test` | 运行 bats 测试 |
| `make lint` | 在所有 bash 上运行 shellcheck |
| `make smoke` | Docker 集成冒烟测试(需要 `make build`) |
| `make update` | Git pull + 重新构建镜像 |
| `make clean` | 停止并移除所有 mitmproxy 容器 |
| `make uninstall` | 移除 symlinks 和 config |
## 安装
要求:`zsh`, `docker`, `tmux`,可选 `trivy`。
```
git clone git@github.com:Dxsk/dotenv-sec.git
cd dotenv-sec
make install
source ~/.zshrc
```
## 开发
```
pre-commit install # runs shellcheck + bats on every commit
make test # bats test suite
make lint # shellcheck all bash
make smoke # Docker integration smoke (requires make build)
```
## 许可证
MIT:参见 [LICENSE](LICENSE)。
标签:Docker, 安全防御评估, 应用安全, 自动化环境, 请求拦截