Skip to main content

Add your description here

Project description

Tencent Cloud Intelligent Pentest Competition Mock API Server

本项目为腾讯云智能化渗透测试大赛 API 模拟器,旨在本地复现赛题下发、提示获取及答题流程,辅助自动化攻防策略的开发与调试。

功能特性

  • 靶场编排:基于官方 XBow benchmark 动态复制赛题环境,自动映射端口并通过 Docker Compose 启动容器。
  • 协议仿真:完全复刻线上平台 API 结构,覆盖题目获取、提示查询、答案提交等核心接口。
  • 多端支持:提供 CLI、Python SDK 及 MCP (FastMCP) 协议支持,便于脚本调用及 AI Agent 集成。
  • 资源管理:全链路结构化日志记录;进程退出时自动清理靶场容器,防止资源泄露。

环境要求

  1. Python 环境:建议使用 uv 管理依赖。
  2. Container Runtime:安装 Docker 及 Docker Compose。
  3. Redis:本地需启动 Redis 服务以模拟官方 API 的速率限制 (1 QPS)。
  4. Benchmark 数据:需下载修正版题目环境。

部署与启动

1. 准备赛题数据

git clone https://github.com/Neuro-Sploit/xbow-validation-benchmarks --branch main --depth 1 ~/xbow-validation-benchmarks

2. 启动模拟服务器

screenshot

# 克隆仓库
git clone https://github.com/WangYihang/tencent-cloud-hackathon-intelligent-pentest-competition-api-server.git
cd tencent-cloud-hackathon-intelligent-pentest-competition-api-server

# 安装依赖
uv sync

# 启动服务
# --host: API 监听地址
# --port: API 监听端口
# --public-accessible-host: 赛题对外暴露的 IP (通常为本机局域网 IP,如:192.168.1.2)
# -i: 指定启动的题目 ID (如 XBEN-001-24),该选项可以通过重复指定来同时启动多个题目环境
python -m tencent_cloud_hackathon_intelligent_pentest_competition_api_server.server \
 --xbow-benchmark-folder ~/xbow-validation-benchmarks/benchmarks \
 --host 0.0.0.0 \
 --port 8000 \
 --public-accessible-host 192.168.1.2 \
 -i 1 -i 2 -i 3 -i 4

服务启动后相关资源地址:

fastapi

API 接口

接口协议遵循官方文档

方法 路径 描述
GET /api/v1/challenges 获取当前阶段题目实例信息(目标 IP、端口、积分等)。
GET /api/v1/hint/{challenge_code} 获取题目提示(首次查看将触发罚分机制)。
POST /api/v1/answer 提交 Flag,校验通过后返回积分并标记完成。

客户端

客户端工具默认读取以下环境变量:

export COMPETITION_BASE_URL=http://127.0.0.1:8000
export COMPETITION_API_TOKEN=00000000-0000-0000-0000-000000000000

命令行工具 (CLI)

cli

# 获取题目列表
python -m tencent_cloud_hackathon_intelligent_pentest_competition_api_server.client_cli get-challenges

# 获取提示
python -m tencent_cloud_hackathon_intelligent_pentest_competition_api_server.client_cli get-challenge-hint <challenge_code>

# 提交答案
python -m tencent_cloud_hackathon_intelligent_pentest_competition_api_server.client_cli submit-answer <challenge_code> <flag>

Python SDK

  • Python SDK: client_sdk.APIClient 内置指数退避重试策略与速率限制处理。
pip install tencent-cloud-hackathon-intelligent-pentest-competition-api-server
from tencent_cloud_hackathon_intelligent_pentest_competition_api_server.client_sdk import APIClient

client = APIClient(
    base_url='http://127.0.0.1:8000',
    api_token='00000000-0000-0000-0000-000000000000',
)

challenges = client.get_challenges()
print(challenges)
first_challenge_code = challenges.challenges[0].challenge_code
print(client.get_challenge_hint(first_challenge_code))
print(client.submit_answer(first_challenge_code, 'flag{...}'))

MCP Server

  • MCP Protocol: 通过 client_mcp 模块暴露接口,支持 AI Agent 直接调用。
> python -m tencent_cloud_hackathon_intelligent_pentest_competition_api_server.client_mcp
{"timestamp": "2025-11-27T15:57:31.881942", "level": "INFO", "message": "Initializing API client", "action": "init", "base_url": "http://localhost:8000/", "api_token": "00000000-0000-0000-0000-000000000000"}


                                         ╭──────────────────────────────────────────────────────────────────────────────╮
                                                                                                                                                                                         ▄▀▀ ▄▀█ █▀▀ ▀█▀ █▀▄▀█ █▀▀ █▀█                                                                                          █▀  █▀█ ▄▄█       █▄▄ █▀▀                                                                                                                                                                                                                        FastMCP 2.13.1                                                                                                                                                                                                                                                                                                                                      🖥  Server name: Capture The Flag Competition API                                                                                                                                                                                              📦 Transport:   STDIO                                                                                                                                                                                                                         📚 Docs:        https://gofastmcp.com                                                                                  🚀 Hosting:     https://fastmcp.cloud                                                                                                                                                                                          ╰──────────────────────────────────────────────────────────────────────────────╯


[11/27/25 15:57:31] INFO     Starting MCP server 'Capture The Flag Competition API' with transport 'stdio'

运维说明

  • 生命周期管理:ChallengeManager 在启动时分配随机端口,进程终止 (SIGINT/SIGTERM) 时自动执行 docker compose down 并清理临时文件。
  • 日志分析:服务与客户端行为均记录于 logs/ 目录下的 JSONL 文件。
  • 故障排查
    • 端口冲突:若自动分配端口失败,请删除 challenges/ 目录下的临时文件夹后重启。
    • Flag 读取异常:确保 Benchmark 环境 .env 文件中 FLAG 变量已正确设置。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file tencent_cloud_hackathon_intelligent_pentest_competition_api_server-0.1.19.tar.gz.

File metadata

  • Download URL: tencent_cloud_hackathon_intelligent_pentest_competition_api_server-0.1.19.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tencent_cloud_hackathon_intelligent_pentest_competition_api_server-0.1.19.tar.gz
Algorithm Hash digest
SHA256 80313a6bb751e8785512a386011bf92cda6efe9f4ee3ad2583c8db456177afb3
MD5 988c557ee0fc7dde7d001b8591af515a
BLAKE2b-256 874376f30cab2595cf030b9b555adeee2fc9090c0e9f9f622533dd44f9b6d2f8

See more details on using hashes here.

File details

Details for the file tencent_cloud_hackathon_intelligent_pentest_competition_api_server-0.1.19-py3-none-any.whl.

File metadata

  • Download URL: tencent_cloud_hackathon_intelligent_pentest_competition_api_server-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tencent_cloud_hackathon_intelligent_pentest_competition_api_server-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 a515a3b4e076e39dd9c9548fca9ebceda6f2562410e6b44a8838c5fa53530917
MD5 cb6b78db1c3e9ecdd46e4082d655610e
BLAKE2b-256 d89fc96187a17faad6f737c4bb4380d545cdce3629a8d0192f48bd784a73a31e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page