m4rvxpn/portex
GitHub: m4rvxpn/portex
PORTEX 是一款 AI 增强的端口扫描器,通过自适应探测与流量伪装提升隐蔽性与效率,解决传统扫描易被检测的问题。
Stars: 0 | Forks: 0
## 什么是 Portex?
Portex 是一款用 Go 编写的高性能 AI 增强端口扫描器。它完整复刻 nmap 的扫描架构 —— 包括全部 13 种扫描类型、服务识别、操作系统指纹识别,以及与 NSE 等效的 Lua 脚本 —— 同时新增五层 AI,使每一次扫描都具备自适应、规避和增强能力。
**为何不直接使用 nmap?**
| 功能 | nmap | Portex |
|---|---|---|
| 并发探测 | ~500(线程) | 5000(goroutine) |
| 报文构造 | libdnet/C | gopacket(零拷贝,sync.Pool) |
| 自适应探测逻辑 | 静态 | RL 代理(ONNX/启发式) |
| 防火墙规避 | 手动标志 | 自动载荷变异 + 模仿 |
| 输出 | XML / 可 grep 格式 | JSON、BBOT NDJSON、nuclei YAML、CSV、XML |
| 扫描后增强 | 脚本 | LLM(Claude / Ollama) |
| 流水线集成 | 无 | bbot / phantom-easm 原生支持 |
## 五层 AI 能力
```
Probe dispatch
│
├─ Layer 1: RL Probe Optimizer → selects flags, TTL, source port per target state
├─ Layer 2: Payload Mutator → fragments, pads, shifts urgent pointer, source-routes
├─ Layer 3: Protocol Obfuscation → QUIC, DNS-tunnel, IPv6 ext-hdr, ICMP covert
├─ Layer 4: Traffic Mimicry → per-OS window sizes, TTL spoofing, decoy flood
│
└─ Raw socket → target
│
└─ Layer 5: LLM Enrichment → CVE lookup, nuclei template gen, vuln summary
```
## 快速开始
### 前置条件
```
# Debian/Ubuntu/Kali
sudo apt-get install -y libpcap-dev
# Arch
sudo pacman -S libpcap
# Go 1.22+
go version
```
### 构建
```
git clone https://github.com/m4rvxpn/portex
cd portex
make build # → bin/portex
```
### 首次扫描
```
# 基本主机 SYN 扫描(需要 root 权限以使用原始套接字)
sudo ./bin/portex scan -t 192.168.1.1 -p 1-1024 --mode syn
# 前 1000 个端口及服务检测
sudo ./bin/portex scan -t 192.168.1.0/24 -p top1000 --mode syn --service-detect
# 全隐身模式(包含所有 AI 层)
sudo ./bin/portex scan -t 192.168.1.1 -p top1000 --mode stealth \
--rl --mutate --mimic --llm --output bbot,json,nuclei-yaml
```
## 扫描模式
| 标志 | 模式 | 描述 |
|---|---|---|
| `--mode syn` | SYN 隐蔽 | 半开 TCP,最快、记录最少 |
| `--mode connect` | TCP 连接 | 完整握手,无需原始套接字 |
| `--mode ack` | ACK 探测 | 防火墙规则映射 |
| `--mode fin` | FIN 探测 | 规避简单无状态过滤 |
| `--mode xmas` | XMAS | FIN+PSH+URG,RFC 793 行为 |
| `--mode null` | NULL | 无 TCP 标志 |
| `--mode window` | 窗口 | RST 窗口大小解释 |
| `--mode maimon` | Maimon | FIN+ACK,BSD 特定 |
| `--mode udp` | UDP | 通过 ICMP 不可达实现服务识别 |
| `--mode sctp` | SCTP INIT | SCTP 栈指纹识别 |
| `--mode ipproto` | IP 协议 | 支持的 IP 协议 |
| `--mode idle` | 空闲/僵尸 | 通过僵尸主机实现真正盲扫 |
| `--mode stealth` | 隐身 | 每端口/RTT 由 RL 选择的模式 |
## 使用参考
### CLI 标志
```
portex scan [flags]
Targeting:
-t, --targets string IPs, CIDRs, hostnames (comma-sep or @file)
-p, --ports string port spec: 80,443 | 1-1024 | top100 | top1000 | all
Scan control:
--mode string scan mode (see table above, default: syn)
--timing int T0-T5 paranoid→insane (default: 3)
--goroutines int concurrent probes (default: 5000)
--max-retries int per-port retry limit (default: 6)
--zombie string host:port for idle scan (--mode idle)
Detection:
--service-detect banner grab + nmap-service-probes matching
--os-detect OS fingerprinting via TTL/window heuristics
--script-scan run bundled Lua scripts
--scripts string comma-sep script names (default: all)
AI layers:
--rl RL probe optimizer (Layer 1)
--mutate payload mutation (Layer 2)
--mimic traffic mimicry (Layer 4)
--llm LLM enrichment (Layer 5)
--llm-provider string claude | ollama (default: claude)
Output:
--output string formats: json,bbot,xml,csv,nuclei-yaml (comma-sep)
--output-file string base path for output files
--session-id string phantom pipeline session correlation ID
Network:
--proxy string socks5://host:port or http://host:port
-v, --verbose verbose logging
```
### 示例
```
# 使用僵尸主机进行空闲扫描(真正盲扫)
sudo ./bin/portex scan -t 10.0.0.5 -p 80,443,8080 --mode idle --zombie 10.0.0.3:80
# 操作系统检测 + 特定端口脚本
sudo ./bin/portex scan -t 10.0.0.1 -p 22,80,443 \
--service-detect --os-detect --script-scan --scripts http-title,ssl-cert
# 全 AI 驱动隐身侦察 → bbot + nuclei 模板
sudo ./bin/portex scan -t 10.0.0.0/24 -p top1000 --mode stealth \
--rl --mutate --mimic --llm \
--output bbot,json,nuclei-yaml --output-file ./results/target
# 代理感知(通过 phantom-easm 的 SOCKS5)
SOCKS5_PROXY=socks5://127.0.0.1:1080 \
sudo -E ./bin/portex scan -t 10.0.0.1 -p 443 --mode connect
# REST API 服务器
sudo ./bin/portex serve --bind 0.0.0.0:8080 --api-key $(openssl rand -hex 32)
```
## REST API
```
POST /v1/scan start async scan → returns scan_id
GET /v1/scan/:id get scan status
GET /v1/scan/:id/results stream results (SSE or JSON array)
DELETE /v1/scan/:id cancel scan
POST /v1/scan/sync synchronous scan (60s timeout)
GET /v1/health liveness probe
GET /metrics Prometheus metrics
```
请求体:
```
{
"targets": ["10.0.0.1/24"],
"ports": "top1000",
"mode": "syn",
"enable_rl": true,
"enable_llm": false,
"output_formats": ["bbot", "json"],
"session_id": "phantom-abc123"
}
```
## bbot 集成
Portex 输出 BBOT 原生 NDJSON 事件 —— 可直接接入任意 bbot 流水线:
```
// Open port discovered
{"type":"OPEN_TCP_PORT","data":{"host":"10.0.0.1","port":443,"proto":"tcp","status":"open","service":"https","version":"nginx/1.25.0"},"module":"portex","scan_id":"..."}
// Technology identified
{"type":"TECHNOLOGY","data":{"host":"10.0.0.1","port":443,"tech":"nginx","version":"1.25.0","cpe":"cpe:/a:nginx:nginx:1.25.0"},"module":"portex"}
// Vulnerability (LLM-enriched)
{"type":"VULNERABILITY","data":{"host":"10.0.0.1","port":443,"severity":"high","cves":["CVE-2023-44487"],"summary":"HTTP/2 Rapid Reset DoS"},"module":"portex"}
```
事件携带基于 `(类型, 主机, 端口)` 的确定性 UUID v5,用于在 phantom 数据路由器中实现去重。
## LLM 增强
设置 `ANTHROPIC_API_KEY` 以使用 Claude,或指向本地 Ollama 实例:
```
# Claude(默认)
export ANTHROPIC_API_KEY=sk-ant-...
sudo -E ./bin/portex scan -t 10.0.0.1 -p top100 --llm
# Ollama(本地,无需 API 密钥)
sudo ./bin/portex scan -t 10.0.0.1 -p top100 --llm --llm-provider ollama
```
对于每个开放端口,LLM 将返回:
- 影响该服务/版本的 CVE
- 攻击面摘要
- 上下文相关的利用指导
- 即用的 nuclei YAML 模板
## 容器化
```
# 构建
docker build -t portex:latest .
# 运行(需要 NET_RAW + NET_ADMIN 权限以使用原始套接字)
docker run --rm --cap-add NET_RAW --cap-add NET_ADMIN --network host \
-e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
portex:latest scan -t 10.0.0.1 -p top1000 --mode syn
```
## 构建与测试
```
make build # compile → bin/portex
make build-static # CGO_ENABLED=0 static binary (no libpcap)
make test # unit tests (-short, no root)
make lint # golangci-lint
make vet # go vet
make docker # docker build
# 集成测试(需要 root 权限)
sudo make test-integration
```
## 文档
完整维基位于 [`docs/`](docs/):
| 文档 | 内容 |
|---|---|
| [架构](docs/architecture.md) | 内部原理、并发模型、AI 流水线 |
| [安装](docs/installation.md) | 依赖、构建选项、Docker |
| [扫描模式](docs/scan-modes.md) | 每种模式的包级详解 |
| [AI 能力](docs/ai-layers.md) | RL 代理、变异器、模仿、LLM 增强 |
| [输出格式](docs/output-formats.md) | JSON、BBOT、XML、CSV、nuclei YAML |
| [REST API](docs/rest-api.md) | 端点参考、认证、SSE 流 |
| [bbot 集成](docs/bbot-integration.md) | phantom-easm 流水线接入 |
| [配置](docs/configuration.md) | 所有标志、环境变量、配置文件格式 |
| [用例](docs/use-cases.md) | 红队、漏洞赏金、资产清单、EASM |
## 法律声明
Portex 仅限授权安全测试使用。请仅对您拥有或已获得明确书面许可的系统进行测试。作者不对滥用行为承担任何责任。
标签:AI安全, BBOT, Chat Copilot, Claude, CNCF毕业项目, CSV, CVE检测, EVTX分析, goroutine, Go语言, gRPC, JSON, LLM增强, LLM评估, Nmap替代, Nuclei格式, Ollama, ONNX, OS指纹识别, sync.Pool, T1046, T1055, T1057, T1059, T1078, URL短链接分析, XML输出, YAML, 协议模糊, 安全库, 并发扫描, 强化学习, 插件系统, 数据统计, 日志审计, 服务探测, 漏洞赏金平台, 程序破解, 端口扫描, 网络安全, 自适应扫描, 请求拦截, 负载变异, 防火墙绕过, 隐私保护, 零拷贝, 高性能扫描