fix: 红队引导不再替用户下载工具,缺 setup.sh 时改走环境适配

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-29 14:48:35 +08:00
1 parent 3d1986baef
commit da980e5730
3 files changed
+42 -94

No files matched your search

+1 -1
View File
@@ -452,7 +452,7 @@ export const DEFAULT_PROMPTS = {
1. 先跑 \`redteam_preflight\`,看返回里的 \`onboarding\` 字段:
- \`onboarding.complete=false\` 或 \`first_run=true\` → **这是用户第一次用红队模式**,必须先加载技能 \`redteam-setup\` 走一遍引导;
- \`onboarding.missing\` 列的就是缺的东西(如 \`FOFA_KEY\`、VPS 登录方式),**一次性列给用户**(要什么、为什么、给到哪),然后等补齐。
2. 引导动作:\`bash "$DSH_HOME/redteam/setup.sh" --check\` 拿体检结论 → 把缺口一次列给用户 → 补齐后 \`bash "$DSH_HOME/redteam/setup.sh" --yes\` 装齐 → 重新跑 \`redteam_preflight\` 确认 \`onboarding.complete=true\`。
2. 引导动作:本机若有 \`$DSH_HOME/redteam/setup.sh\`,可以让用户自己跑 \`bash "$DSH_HOME/redteam/setup.sh" --check\` 看体检;**没有这个脚本是正常情况**(返回里 \`onboarding.setup_script.exists=false\`),改走演练台「环境适配」或技能 \`redteam-setup\` 逐项手填。**不要替用户下载或安装任何工具。** 补配完成后重新跑 \`redteam_preflight\` 确认 \`onboarding.complete=true\`。
3. **环境没配齐不要开工**:缺 FOFA_KEY 就只能靠 crt.sh + 子域枚举(资产收集不完整、会漏边缘与未备案资产);缺 VPS 就拿不到服务器权限、进不了内网。用户明确说"就按现有条件打"时才降级,并**在汇报里说明哪部分能力降级了**。
4. 环境已就绪(\`onboarding.complete=true\`)时**不要重复引导**,直接进入下面的常规预检。
+18 -12
View File
@@ -496,6 +496,8 @@ export function apply(ctx) {
const markerFile = redteamDir + '/.setup-complete'
const setupScript = redteamDir + '/setup.sh'
const hasMarker = existsSync(markerFile)
const hasSetupScript = existsSync(setupScript)
const toolkitHint = '本插件不替用户下载或安装工具。Windows 与没有 setup.sh 时,到演练台「环境适配」填路径、FOFA_KEY 和 VPS;本机已有 `$DSH_HOME/redteam/setup.sh` 时,由用户自己执行 `--check`,不要由智能体跑 `--yes` 去下载二进制。'
let fofaKey = effectiveEnv.FOFA_KEY || ''
const vpsKey = effectiveEnv.REDTEAM_VPS_KEY || (toolkit + (plat.runtime.windows ? '\\vps\\id_rsa' : '/vps/id_rsa'))
const vpsHost = effectiveEnv.REDTEAM_VPS_HOST || ''
@@ -505,7 +507,7 @@ export function apply(ctx) {
if (!hasVps) {
missing.push(plat.runtime.windows
? 'VPS 私钥(在「环境适配」填写 REDTEAM_VPS_KEY 路径与 REDTEAM_VPS_HOST;Windows 不依赖 setup.sh)'
: 'VPS 登录方式——私钥放到 ' + vpsKey + ',并设 REDTEAM_VPS_HOST(可用 bash ' + setupScript + ' 引导)')
: 'VPS 登录方式——私钥放到 ' + vpsKey + ',并设 REDTEAM_VPS_HOST(步骤见技能 redteam-setup,或演练台「环境适配」)')
}
const fofaShown = fofaKey.length > 8 ? fofaKey.slice(0, 4) + '…' + fofaKey.slice(-4) : '(已配置)'
const runtimeHint = plat.runtime.windows
@@ -532,7 +534,8 @@ export function apply(ctx) {
runtime_hint: runtimeHint,
first_run: !hasMarker,
marker: { path: markerFile, exists: hasMarker },
setup_script: { path: setupScript, exists: existsSync(setupScript) },
setup_script: { path: setupScript, exists: hasSetupScript },
toolkit_hint: toolkitHint,
configured: {
fofa_key: fofaKey === '' ? 'missing' : 'configured(' + fofaShown + ')',
vps_key: hasVps ? 'configured(' + vpsKey + ')' : 'missing',
@@ -546,11 +549,13 @@ export function apply(ctx) {
ok: missing.length === 0 && toolMissing.length === 0,
onboarding,
platform: plat,
toolkit: { dir: toolkit, exists: existsSync(toolkit), entries: toolkitEntries },
toolkit: { dir: toolkit, exists: existsSync(toolkit), entries: toolkitEntries, hint: toolkitHint },
skills_root_hint: '宿主 skills 服务不可用:已跳过技能正文体检,仅返回平台工具探测。请到「环境适配」配置路径。',
next: plat.runtime.windows
? '打开演练台「环境适配」:① 填 binDirs(你的工具文件夹)或逐个 tools 路径 ② 填 FOFA_KEY / VPS ③ 保存后重新 preflight。'
: '可跑 bash "$DSH_HOME/redteam/setup.sh" --check,或到「环境适配」手填路径。',
? '打开演练台「环境适配」:① 填 binDirs(你的工具文件夹)或逐个 tools 路径 ② 填 FOFA_KEY / VPS ③ 保存后重新 preflight。不要替用户下载工具。'
: (hasSetupScript
? '可由用户自己执行 bash "$DSH_HOME/redteam/setup.sh" --check,或到「环境适配」手填路径。不要由智能体下载工具。'
: '本机没有 setup.sh,这是正常情况。到演练台「环境适配」手填路径,或按技能 redteam-setup 逐项配置。'),
}, null, 2)
}
@@ -604,7 +609,8 @@ export function apply(ctx) {
runtime_hint: runtimeHint,
first_run: !hasMarker,
marker: { path: markerFile, exists: hasMarker },
setup_script: { path: setupScript, exists: existsSync(setupScript) },
setup_script: { path: setupScript, exists: hasSetupScript },
toolkit_hint: toolkitHint,
configured: {
fofa_key: fofaKey === '' ? 'missing' : 'configured(' + fofaShown + ')',
vps_key: hasVps ? 'configured(' + vpsKey + ')' : 'missing',
@@ -617,13 +623,13 @@ export function apply(ctx) {
let next
if (plat.runtime.windows && (!hasMarker || missing.length > 0 || allBroken.length > 0)) {
next = 'Windows:打开演练台「环境适配」配置 toolkit/binDirs/tools 路径与 FOFA/VPS,保存后重跑 redteam_preflight;技能正文缺路径时优先用已解析的工具绝对路径。'
} else if (!hasMarker && !existsSync(setupScript)) {
next = '首次使用但没找到安装脚本 ' + setupScript + ':正常安装会由插件启动时自动落一份;'
+ '也可在「环境适配」手填工具路径。'
} else if (!hasMarker && !hasSetupScript) {
next = '首次使用,且本机没有安装脚本 ' + setupScript + '(这是正常情况,不是故障)。'
+ toolkitHint + ' 把 onboarding.missing 一次性列给用户;补不齐就说明降级:没有 FOFA 用 crt.sh / 被动 DNS,没有 VPS 只做不落地的成果。'
} else if (!hasMarker) {
next = '**首次使用**:Linux/Kali 可执行 `bash ' + setupScript + ' --check`;Windows 请用「环境适配」页。'
next = '**首次使用**:让用户自己执行 `bash ' + setupScript + ' --check`,或打开演练台「环境适配」。不要由智能体执行 --yes 去下载工具。'
} else if (missing.length > 0) {
next = '有缺口:把 onboarding.missing 一次性列给用户;Windows 走「环境适配」,Linux 可跑 setup.sh。'
next = '有缺口:把 onboarding.missing 一次性列给用户。Windows 或没有 setup.sh 时走「环境适配」;有脚本时也只让用户自己跑,不要替用户下载工具。'
} else if (allBroken.length > 0) {
next = '把 broken 里 needs_user 一次性列给用户;补不齐则说明降级方案。'
} else {
@@ -642,7 +648,7 @@ export function apply(ctx) {
available: available.map((s) => s.name),
broken: broken.map((s) => ({ name: s.name, problems: s.problems, needs_user: s.needs_user })),
unknown: checked.filter((s) => s.status === 'unknown').map((s) => s.name),
toolkit: { dir: toolkit, exists: existsSync(toolkit), entries: toolkitEntries },
toolkit: { dir: toolkit, exists: existsSync(toolkit), entries: toolkitEntries, hint: toolkitHint },
skills_root_hint: '技能来自 DSH 原生注册表或本包 skills/redteam;工具路径以「环境适配」config.json 为准。',
next,
needs_user_flat: needsUser,