HackTheBox MCP 服务器是一个基于模型上下文协议(MCP)的服务器,它为 AI 助手提供了对 HackTheBox 平台功能的编程访问能力,极大地提升了用户与平台交互的便捷性和效率。
HTB MCP 服务器提供了 12 种全面的工具,用于与 HackTheBox 平台进行交互:
list_challenges
- 获取带有过滤功能的分页挑战列表。start_challenge
- 初始化挑战环境。submit_challenge_flag
- 提交挑战标志以进行验证。list_machines
- 获取带有状态信息的活跃/退役机器列表。start_machine
- 启动机器并获取连接详情。get_machine_ip
- 获取活跃机器的 IP 地址。submit_user_flag
- 提交机器的用户标志。submit_root_flag
- 提交机器的根标志。get_user_profile
- 获取用户资料和统计信息。get_user_progress
- 获取完成状态和成就信息。search_content
- 对挑战、机器和用户进行高级搜索。get_server_status
- 进行健康检查并获取服务器信息。git clone https://github.com/NoASLR/htb-mcp-server.git
cd htb-mcp-server
go build -o htb-mcp-server main.go
xxx.yyy.zzz
)。服务器通过环境变量进行配置:
HTB_TOKEN
- 你的 HackTheBox API 令牌(JWT 格式)。SERVER_PORT
- 服务器端口(默认:3000)。LOG_LEVEL
- 日志级别:DEBUG、INFO、WARN、ERROR(默认:INFO)。RATE_LIMIT_PER_MINUTE
- API 速率限制(默认:100)。CACHE_TTL_SECONDS
- 响应缓存的生存时间(默认:300)。REQUEST_TIMEOUT_SECONDS
- HTTP 请求超时时间(默认:30)。export HTB_TOKEN="your.jwt.token.here"
./htb-mcp-server
docker build -t htb-mcp-server .
docker run -e HTB_TOKEN="your.jwt.token.here" htb-mcp-server
将以下内容添加到你的 MCP 客户端配置(例如,Claude Desktop)中:
{
"mcpServers": {
"htb": {
"command": "/path/to/htb-mcp-server",
"env": {
"HTB_TOKEN": "your.jwt.token.here"
}
}
}
}
连接成功后,你可以通过 AI 助手使用这些工具:
# 列出活跃挑战
"Can you show me the available Web challenges on HackTheBox?"
# 启动一台机器
"Please start machine ID 123 and get its IP address"
# 提交标志
"Submit the user flag 'HTB{example_flag}' for machine 123"
# 搜索内容
"Search for machines related to 'Active Directory'"
# 检查服务器状态
"What's the current status of the HTB MCP server?"
服务器通过标准输入输出传输实现了 MCP 协议。所有通信都遵循 JSON-RPC 2.0 规范。
initialize
- 初始化 MCP 会话。tools/list
- 列出可用工具。tools/call
- 执行特定工具。服务器与 HackTheBox API v4 集成:
https://labs.hackthebox.com/api/v4
。htb-mcp-server/
├── main.go # 入口点
├── pkg/
│ ├── config/ # 配置管理
│ ├── htb/ # HTB API 客户端
│ └── mcp/ # MCP 协议实现
├── internal/
│ ├── server/ # MCP 服务器核心
│ └── tools/ # 工具实现
├── tests/ # 测试文件
└── docs/ # 文档
Tool
接口:type MyTool struct {
client *htb.Client
}
func (t *MyTool) Name() string { return "my_tool" }
func (t *MyTool) Description() string { return "Description" }
func (t *MyTool) Schema() mcp.ToolSchema { /* schema */ }
func (t *MyTool) Execute(ctx context.Context, args map[string]interface{}) (*mcp.CallToolResponse, error) {
// 实现代码
}
registry.go
中注册工具:r.RegisterTool(NewMyTool(r.htbClient))
# 运行单元测试
go test ./...
# 运行带覆盖率的测试
go test -cover ./...
# 运行集成测试(需要 HTB_TOKEN)
HTB_TOKEN="your.token" go test -tags=integration ./...
RATE_LIMIT_PER_MINUTE
。启用调试日志:
export LOG_LEVEL=DEBUG
./htb-mcp-server
测试服务器连接:
curl -X POST http://localhost:3000/health
本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。
为网络安全社区精心打造 ❤️