# New API Gateway Pentest

> Use when target runs New API / One API LLM gateway.

- Skill: `yufeifeio/new-api-gateway-pentest` (Agent Skill)
- Install (CLI): `npx get-skill add yufeifeio/new-api-gateway-pentest`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yufeifeio/new-api-gateway-pentest/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: Yufeifeio (https://skillmd.com/u/yufeifeio)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/yufeifeio/new-api-gateway-pentest

---


# New API / One API LLM 网关渗透

中国 AI 订阅代充生态常把 New API（Calcium-Ion/new-api，One API 分支）作为上游 LLM 网关：React SPA + Gin 后端，管理上游 OpenAI/Claude/Gemini 渠道密钥与用户额度。识别后先 `git clone` 源码再打；所有结论以源码为准，不靠猜。

## 识别
- 响应头 `x-new-api-version: v1.0.0-rc.xx-relayNN`、`x-oneapi-request-id`。
- 首页 `<title>New API</title>`，`/static/js/index.*.js` 的 React SPA。
- `GET /api/status` 公开，返回 `version / setup / register_enabled / email_verification / turnstile_check / oauth* / system_name`——**第一个请求就查 setup**。
- `/api/*` 未命中返回 `{"error":{"message":"Invalid URL ..."}}`。

## 1. setup 闸门（最高优先级）
- `GET /api/setup` → `{success, data:{status, root_init, database_type}}`。
- `POST /api/setup` 仅在 `constant.Setup == false` 时可用；未初始化时提交 `{username,password,confirm_password,self_use_mode_enabled,demo_site_enabled}` 会创建 `RoleRootUser`、quota 100000000 的管理员。**setup:false 就直接拿 root，别打别的。**
- `setup:true` 时 PostSetup 直接拒绝（“The system is already initialized”）——转注册/登录面，不要在 setup 绕过上耗时间。

## 2. 注册面（拿普通用户）
- 发码：`GET /api/verification?email=<mail.tm地址>`（EmailVerificationRateLimit + 可选 Turnstile；无 Turnstile 时直接发）。
- 注册：`POST /api/user/register` `{username,password,email,verification_code}`。**role 被强制为普通用户（cleanUser 显式设置），mass assignment 无效。**
- 若目标开了 `GenerateDefaultToken`，注册会生成一个 `UnlimitedQuota:true` 的默认 token（`GET /api/token/` 可见）——免费额度，但不是管理员。
- 邮箱验证码走运营方 SMTP：用 mail.tm 收码即可；**顺手拉原始 EML（`GET /messages/{id}/download`）看第一跳 `Received: from`——自建/本机 SMTP 会直接暴露网关服务器 IP（实测 `Received: from localhost ([43.160.210.72])`）；Resend/SES 则只露服务商，停手。**

## 3. 登录/限流
- `POST /api/user/login` `{username,password}`；`CriticalRateLimit` 按 IP 限流，超限返回空 body 的 429，**没有账号锁定串**。Tor 电路隔离（`waf-evasion-and-credential-attack` §3b）可换桶，但 root 口令是安装时随机生成，字典通常无解。
- 默认用户 `root`（setup 时填的）；别人做的 setup 用户名未知，登录错误统一为 “Username or password is incorrect, or user has been banned”，无枚举。
- `GET /api/user/login/encryption-key` 公开；前端可能做密码加密，先抓一次真实登录请求确认字段格式。
- **429 是 IP 级、可能连 `/api/status` 一起封**：爆破/探测把出口打封后，换 Tor 电路再验活，别把 429 当业务结论。

## 4. 用户面自检（确认没有 mass assignment）
- `PUT /api/user/self`：只更新 username/display_name；`role/quota/status` 不生效（cleanUser 白名单）。
- `/api/token/`、`/api/user/aff`、`/api/user/topup`（兑换码管理员生成）——普通用户拿不到管理面。
- 充值回调 `/api/user/epay/notify` 校验 epay 签名；未配置 epay 时直接 fail。

## 5. 管理面（拿到 admin 之后）
- 管理路由 `/api/channel/*`、`/api/option/*`、`/api/log/*`、`/api/user/*`、`/api/redemption/*`、`/api/plugin/*`。
- 渠道里是上游 OpenAI/Claude 密钥（`/api/channel/:id/key` 看 secret）——拿 admin 后的第一目标。
- 插件系统 `pkg/jsplugin` 是 **JS 沙箱（自带 fetch）**，不是 Node 子进程：可 SSRF 内网/元数据，但不要假设直接 RCE。

## 6. 源码审计要点（先 clone 再谈洞）
- `controller/setup.go`：setup 状态与 RootUserExists 兜底；`controller/user.go` 的 Register/UpdateSelf 用 cleanUser 白名单，mass assignment 已修——审计时先看 handler 是否显式设 Role。
- `router/api-router.go` 列出全部公开/鉴权路由：`/api/models` 要 UserAuth，`/api/pricing`/`/api/rankings` 走 HeaderNavModuleAuth；`/api/setup`、`/api/status`、`/api/verification`、`/api/reset_password`、webhook 是公开面。
- `constant.Setup` 是内存变量，重启后由 DB 状态决定；`GetSetup` 在 setup 前返回 `root_init/database_type`，可判断实例新旧。

## 关联
- 源站定位：邮件原始头（自建 SMTP）或 `cdn-origin-tracing`
- 限流绕过：`waf-evasion-and-credential-attack` §3b（Tor 电路隔离）
- 同生态发卡主站：`dujiao-next-platform-pentest`

