feat(http): add bounded proxy pool failover to HTTP test tool

This commit is contained in:
Sycun committed 2026-10-31 23:29:48 +08:00
1 parent 697e875fa4
commit 5d7cb1ff5d
11 files changed
+987 -5

No files matched your search

+2
View File
@@ -32,6 +32,7 @@ CyberStrikeAI documentation is organized by user journey. Start with deployment,
- [资产管理](zh-CN/asset-management.md)
- [项目任务续接](zh-CN/project-resume.md)
- [Token 用量分析](zh-CN/token-usage-monitoring.md)
- [HTTP 测试工具代理池](zh-CN/http-proxy-pool.md)
- [知识库](zh-CN/knowledge-base.md)
- [RBAC 权限管理](zh-CN/rbac.md)
- [机器人接入](zh-CN/robot.md)
@@ -76,6 +77,7 @@ CyberStrikeAI documentation is organized by user journey. Start with deployment,
- [Asset Management](en-US/asset-management.md)
- [Resuming Project Tasks](en-US/project-resume.md)
- [Token Usage Analysis](en-US/token-usage-monitoring.md)
- [HTTP Test Tool Proxy Pool](en-US/http-proxy-pool.md)
- [Knowledge Base](en-US/knowledge-base.md)
- [RBAC Administration](en-US/rbac.md)
- [Robot / Chatbot](en-US/robot.md)
+1
View File
@@ -20,6 +20,7 @@
## Feature guides
- [Resuming Project Tasks](project-resume.md) · [Token Usage Analysis](token-usage-monitoring.md)
- [HTTP Test Tool Proxy Pool](http-proxy-pool.md)
- [Asset Management](asset-management.md) · [Knowledge Base](knowledge-base.md) · [Robot / Chatbot](robot.md) · [Vision](VISION.md)
- [WebShell](webshell.md) · [C2](c2.md) · [MCP Federation](mcp-federation.md)
+88
View File
@@ -0,0 +1,88 @@
# HTTP test tool proxy pool
[中文](../zh-CN/http-proxy-pool.md) | [Documentation home](README.md)
`http-framework-test` accepts a user-supplied proxy list and/or provider endpoint. It switches proxies within a bounded attempt budget on transport failures or configured HTTP status codes, and reuses a successful proxy. The feature is opt-in; the existing single `proxy` option and calls without a pool remain available.
## Usage
After updating the tool file, apply configuration in settings or restart the service to reload its parameters. Pool options are per-call arguments; no `config.yaml` change is required.
Example MCP tool arguments:
```json
{
"url": "https://your-authorized-target.example/health",
"method": "GET",
"proxy_pool": "[\"http://127.0.0.1:8081\",\"http://127.0.0.1:8082\"]",
"proxy_max_attempts": 3,
"proxy_cooldown": "60",
"proxy_fail_status": "403,429",
"response_max_bytes": 8192
}
```
`proxy_pool` also accepts newline-separated endpoints. Supported forms are `http://host:port`, `https://host:port`, `socks5://host:port`, and bare `host:port` (HTTP). An explicit port is required. IPv6 brackets and URL-encoded `user:password@host:port` credentials are supported. SOCKS support is included in the `httpx[http2,socks]` requirement.
To fetch proxies automatically, add or use `proxy_source` alone:
```json
{
"url": "https://your-authorized-target.example/health",
"proxy_source": "https://your-proxy-provider.example/api/proxies"
}
```
The endpoint must return UTF-8 newline-separated endpoints, a JSON array of endpoint strings, or an object containing a `proxies` or `data` array:
```json
{"proxies": ["http://127.0.0.1:8081", "127.0.0.1:8082"]}
```
Other provider formats require an adapter. No public free-proxy sources are built in. The source is fetched at startup and at most once more per request/redirect hop when available candidates run out. New endpoints are deduplicated and merged without clearing cooldowns. Fetches have a 10-second timeout, do not follow redirects, accept at most 1 MiB, and the pool holds at most 256 endpoints. An initial fetch failure stops the call. A refresh failure preserves the last HTTP failure response, or reports an error if no response exists.
## Behavior
| Parameter | Default | Meaning |
| --- | --- | --- |
| `proxy_pool` | Empty | JSON string array or newline-separated list |
| `proxy_source` | Empty | User-configured HTTP(S) provider endpoint, optionally combined with a list |
| `proxy_max_attempts` | `3` | 1–10 distinct proxy attempts per request/redirect hop |
| `proxy_cooldown` | `"60"` | 0–86400 seconds before a failed proxy is eligible again |
| `proxy_fail_status` | `"403,429"` | Comma-separated status codes from 400–599; `"none"` disables status-based switching |
- Successful proxies stay selected. Failed proxies enter cooldown. Each proxy is tried at most once per request/redirect hop.
- Only GET, HEAD and OPTIONS are replayed automatically. POST, PUT, DELETE and other methods retain the first result. An explicit `repeat` still requests additional executions.
- Transport failures before response headers can trigger switching. Failures while reading a response body are reported without replaying a partial response.
- A 429 with a valid future `Retry-After` stops automatic replay and reports that the caller should retry later. Further requests to that origin within the same tool invocation are blocked until the wait expires; waits are recorded for at most 24 hours.
- If the final attempt returns an HTTP failure response, it is preserved with a nonzero exit code. A network failure or a pool with all endpoints cooling down reports an error. There is no direct fallback or extra direct DNS/TCP/TLS target probe.
- Pool diagnostics show attempt numbers, proxy numbers and failure types. They omit proxy credentials and provider URLs. The platform's existing argument traces, audit records and logs still apply; treat arguments containing credentials as sensitive configuration.
## Scope and design
[#357](https://github.com/AIPentest/CyberStrikeAI/issues/357) requests automatic proxy acquisition and switching after a ban, without specifying providers, detection or tool scope. This implementation starts with `http-framework-test`, where both HTTP and decrypted HTTPS responses can be inspected. A standalone forwarding proxy cannot read HTTPS responses inside a CONNECT tunnel. See the [HTTPX proxy](https://www.python-httpx.org/advanced/proxies/) and [transport](https://www.python-httpx.org/advanced/transports/) documentation.
A 403 can be an application authorization failure; a 429 can apply to an account or other scope. Status matching is a configurable policy, not proof of an IP ban. CAPTCHA or HTTP 200 block pages remain unchanged. Replay and waiting rules are informed by [RFC 9110 §9.2.2](https://www.rfc-editor.org/rfc/rfc9110.html#section-9.2.2) and [RFC 6585 §4](https://www.rfc-editor.org/rfc/rfc6585.html#section-4).
Pool state lasts for one tool invocation. Other scanners, `exec`, Eino `execute`, external MCP servers and LLM API connections are outside this pool; no global settings page is added. Provider fetching uses a separate client with TLS verification and no target cookies, target Authorization, environment proxies or inherited `allow_insecure`. Use HTTPS for production provider endpoints.
## Troubleshooting and source
| Message | Action |
| --- | --- |
| `Proxy pool exhausted` | Check endpoint connectivity, wait for cooldown, or replace the list/provider results |
| `failure policy still matched` | Inspect the preserved response and distinguish IP restrictions from normal authorization/rate limits; adjust `proxy_fail_status` if needed |
| `Retry-After is still active` | Wait for the target's requested delay before another call |
| `Could not fetch proxy source` | Check provider connectivity, authentication and TLS; target `allow_insecure` does not affect provider connections |
| `SOCKS support requires ...` | Install `httpx[socks]` in the tool's Python environment or update its requirements |
The implementation and MCP parameter definitions are in [tools/http-framework-test.yaml](../../tools/http-framework-test.yaml); regression scenarios are in [scripts/test_http_proxy_pool.py](../../scripts/test_http_proxy_pool.py).
## Local verification
```sh
python3 -m pip install 'httpx[http2,socks]>=0.27.0' PyYAML
python3 -m unittest discover -s scripts -p 'test_http_proxy_pool.py' -v
```
Tests execute the code read from the tool YAML against local HTTP proxies, CONNECT tunnels and TLS servers. No external targets or real providers are contacted. The HTTPS fixture requires `openssl`.
+1
View File
@@ -20,6 +20,7 @@
## 功能指南
- [项目任务续接](project-resume.md) · [Token 用量分析](token-usage-monitoring.md)
- [HTTP 测试工具代理池](http-proxy-pool.md)
- [资产管理](asset-management.md) · [知识库](knowledge-base.md) · [机器人接入](robot.md) · [视觉分析](VISION.md)
- [WebShell](webshell.md) · [C2](c2.md) · [MCP 联邦](mcp-federation.md)
+98
View File
@@ -0,0 +1,98 @@
# HTTP 测试工具代理池
[English](../en-US/http-proxy-pool.md) | [文档首页](README.md)
`http-framework-test` 支持用户提供的代理列表及代理供应商接口。连接失败或响应命中指定状态码时,在次数上限内切换代理;成功代理继续复用连接。默认关闭,原有 `proxy` 参数及无代理调用方式继续可用。
## 使用
更新工具文件后,在系统设置中应用配置或重启服务以重新加载工具参数。代理池通过每次工具调用的参数启用,不需要修改 `config.yaml`。
调用 `http-framework-test` 时传入以下参数(MCP 工具参数示例):
```json
{
"url": "https://your-authorized-target.example/health",
"method": "GET",
"proxy_pool": "[\"http://127.0.0.1:8081\",\"http://127.0.0.1:8082\"]",
"proxy_max_attempts": 3,
"proxy_cooldown": "60",
"proxy_fail_status": "403,429",
"response_max_bytes": 8192
}
```
`proxy_pool` 也接受每行一个代理的字符串。支持 `http://host:port`、`https://host:port`、`socks5://host:port` 和省略协议的 `host:port`(按 HTTP 解析);端口必须显式指定。支持 IPv6 方括号及 `user:password@host:port` 认证,凭证中的特殊字符须做 URL 编码。SOCKS 依赖包含在 `requirements.txt` 的 `httpx[http2,socks]` 中。
使用供应商接口自动获取代理时,增加或单独使用:
```json
{
"url": "https://your-authorized-target.example/health",
"proxy_source": "https://your-proxy-provider.example/api/proxies"
}
```
接口返回 UTF-8 文本,每行一个代理,或以下 JSON 格式之一:
```json
["http://127.0.0.1:8081", "127.0.0.1:8082"]
```
```json
{"proxies": ["http://127.0.0.1:8081"]}
```
也支持 `{"data": ["http://127.0.0.1:8081"]}`。需要其他供应商字段格式时,应由供应商或自建适配接口转换为上述格式。项目不内置公共免费代理来源。
供应商接口在调用开始时拉取一次;每个请求或重定向跳的可用代理耗尽时,最多再拉取一次。新地址与现有地址去重合并,已有冷却记录保留。接口超时固定 10 秒,不跟随重定向,响应上限 1 MiB,代理总数上限 256。首次拉取失败直接结束调用;切换过程中拉取失败则保留最后的 HTTP 失败响应,若还未收到响应则报错。
## 切换与结果
| 参数 | 默认值 | 行为 |
| --- | --- | --- |
| `proxy_pool` | 空 | JSON 字符串数组或换行列表 |
| `proxy_source` | 空 | 用户配置的 HTTP(S) 供应商接口,可与列表合用 |
| `proxy_max_attempts` | `3` | 每个请求/重定向跳最多尝试 1–10 个不同代理 |
| `proxy_cooldown` | `"60"` | 失败代理冷却 0–86400 秒 |
| `proxy_fail_status` | `"403,429"` | 逗号分隔的 400–599 状态码,传 `"none"` 禁用状态码切换 |
具体规则:
- 池内成功代理保持粘性复用;失败后冷却,在剩余可用代理中切换。每个请求或重定向跳内,同一代理最多尝试一次。
- 仅 GET、HEAD、OPTIONS 自动重放。POST、PUT、DELETE 等方法发生错误或命中状态码时保留首次结果;用户显式设置的 `repeat` 仍表示额外执行次数。
- 连接、代理、超时等传输错误可触发上述切换;响应体开始读取后的中断直接报错,不重放部分响应。
- 429 若包含有效且尚未到期的 `Retry-After`,停止自动重放并提示稍后重试。同一工具调用中,对该目标源的后续请求也会被阻止至等待期结束,等待值最多记为 24 小时。
- 最后一次尝试若收到 HTTP 失败响应,保留该响应并返回非零退出码;网络故障或所有代理处于冷却时报告错误。不会回退到直连,也不会运行额外的目标 DNS/TCP/TLS 直连探针。
- stderr 记录尝试编号、代理编号及失败类型;stdout 保留最终响应及最终代理编号。代理池自身诊断不输出代理凭证或供应商 URL。工具调用参数仍沿用平台既有的轨迹、审计与日志规则,带凭证的参数应按敏感配置管理。
## 调研结论与覆盖范围
[#357](https://github.com/AIPentest/CyberStrikeAI/issues/357) 仅提出自动获取代理与被封后切换,未定义供应商、识别方式或工具范围。当前实现从能读取 HTTP 响应的 `http-framework-test` 接入,使 HTTP 和 HTTPS 的切换行为都可验证。
HTTP CONNECT 隧道中的 HTTPS 响应需要由发起请求的客户端解密才能读取,因此单独增加全局转发代理不足以识别全部工具的 HTTPS 封禁响应。HTTPX 的代理与自定义传输接口适合在本工具内完成切换,见 [HTTPX 代理文档](https://www.python-httpx.org/advanced/proxies/)与[传输文档](https://www.python-httpx.org/advanced/transports/)。
403 也可能是业务权限错误,429 也可能按账号或其他维度限流;默认状态码只是可配置的失败策略,不宣称已确认 IP 被封。不匹配状态码的验证码页、HTTP 200 拦截页目前保持原样。重放和等待规则参考 [RFC 9110 §9.2.2](https://www.rfc-editor.org/rfc/rfc9110.html#section-9.2.2) 和 [RFC 6585 §4](https://www.rfc-editor.org/rfc/rfc6585.html#section-4)。
池状态只在单次工具调用内保留,不跨会话共享。其他扫描工具、`exec`、Eino `execute`、外部 MCP、LLM API 连接暂不接入本池;未新增全局代理设置页。供应商拉取使用独立客户端,开启 TLS 校验,不继承目标请求的 Cookie、Authorization、环境代理或 `allow_insecure`;生产供应商接口建议使用 HTTPS。
## 排错与源码
| 提示 | 处理 |
| --- | --- |
| `Proxy pool exhausted` | 检查代理可达性,等待冷却或更换列表/供应商返回值 |
| `failure policy still matched` | 查看保留的响应;确认是 IP 限制还是正常的权限/限流结果,按需调整 `proxy_fail_status` |
| `Retry-After is still active` | 等待目标指定的时间后再发起调用 |
| `Could not fetch proxy source` | 检查供应商接口网络、认证和 TLS;目标的 `allow_insecure` 不影响供应商连接 |
| `SOCKS support requires ...` | 在工具使用的 Python 环境安装 `httpx[socks]` 或更新 `requirements.txt` 依赖 |
执行代码与 MCP 参数定义位于 [tools/http-framework-test.yaml](../../tools/http-framework-test.yaml),回归场景位于 [scripts/test_http_proxy_pool.py](../../scripts/test_http_proxy_pool.py)。
## 本地验证
```sh
python3 -m pip install 'httpx[http2,socks]>=0.27.0' PyYAML
python3 -m unittest discover -s scripts -p 'test_http_proxy_pool.py' -v
```
测试从 YAML 读取实际执行代码,使用本地 HTTP 代理、CONNECT 隧道及 TLS 服务验证切换、路径保真、重放限制、等待期、供应商刷新与凭证隔离;不访问外部目标或真实供应商。HTTPS 测试需要 `openssl`。