mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 17:50:22 +08:00
fix: 发布 1.1.45,稳住默认注入并修正清洗进度显示。
点应用即写入默认提示词,不必先保存。剥掉外层 project_instructions 壳并钉死会话系统提示,避免第二轮注入失效。未定位宿主不再显示 0/63,本机不需要的项计入已就绪。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
21dfd934a4
commit
f2c244c78f
36 files changed
+2309
-738
No files matched your search
+61
-153
@@ -9,16 +9,6 @@ import { DatabaseSync } from 'node:sqlite'
|
||||
import { connect as tcpConnect } from 'node:net'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { homedir } from 'node:os'
|
||||
import {
|
||||
loadPlatformConfig,
|
||||
savePlatformConfig,
|
||||
platformSummary,
|
||||
nucleiTemplatesDirOf,
|
||||
toolkitDirOf,
|
||||
envAdaptStatus,
|
||||
assignToolkitFolder,
|
||||
markEnvAdaptSkip,
|
||||
} from './platform-config.js'
|
||||
import {
|
||||
mkdirSync, readFileSync, writeFileSync, readdirSync, existsSync, rmSync, statSync,
|
||||
copyFileSync,
|
||||
@@ -40,7 +30,7 @@ import {
|
||||
} from './report-replay.js'
|
||||
import {
|
||||
DDL, KNOWLEDGE_DDL, ASSET_FTS_DDL, POC_FTS_DDL, HAS_FTS5,
|
||||
POC_CATEGORIES, pocCategoryName, guessPocCategory, classifyNucleiTemplate,
|
||||
POC_CATEGORIES, pocCategoryName, guessPocCategory,
|
||||
migrate, migrateKnowledge,
|
||||
} from './schema.js'
|
||||
import {
|
||||
@@ -61,7 +51,7 @@ export {
|
||||
ipToInt, cidrOf, isIpv6, expandIpv6, scopeOfIp, slugify, slugTarget, slugPoc,
|
||||
defaultPocFilename, nowIso,
|
||||
DDL, KNOWLEDGE_DDL, ASSET_FTS_DDL, POC_FTS_DDL, HAS_FTS5,
|
||||
POC_CATEGORIES, pocCategoryName, guessPocCategory, classifyNucleiTemplate,
|
||||
POC_CATEGORIES, pocCategoryName, guessPocCategory,
|
||||
migrate, migrateKnowledge,
|
||||
WEBSHELL_TYPES, WEBSHELL_STATUSES, normalizeShellType, normalizeShellStatus, assertPathWithin,
|
||||
TUNNEL_ENTRY_KINDS, tunnelIsLegit, ACCOUNT_POINT_CODES, SERVICE_CAPPED_POINT_CODES,
|
||||
@@ -363,6 +353,9 @@ function promptHash(text) {
|
||||
return createHash('sha1').update(String(text === undefined || text === null ? '' : text).trim()).digest('hex').slice(0, 12)
|
||||
}
|
||||
|
||||
// __REDTEAM_PROMPTS_BLOCK__
|
||||
// __REDTEAM_PROMPTS_BLOCK__
|
||||
// __REDTEAM_PROMPTS_BLOCK__
|
||||
// __REDTEAM_PROMPTS_BLOCK__
|
||||
// __REDTEAM_PROMPTS_BLOCK__
|
||||
// __REDTEAM_PROMPTS_BLOCK__
|
||||
@@ -452,7 +445,7 @@ export const DEFAULT_PROMPTS = {
|
||||
1. 先跑 \`redteam_preflight\`,看返回里的 \`onboarding\` 字段:
|
||||
- \`onboarding.complete=false\` 或 \`first_run=true\` → **这是用户第一次用红队模式**,必须先加载技能 \`redteam-setup\` 走一遍引导;
|
||||
- \`onboarding.missing\` 列的就是缺的东西(如 \`FOFA_KEY\`、VPS 登录方式),**一次性列给用户**(要什么、为什么、给到哪),然后等补齐。
|
||||
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\`。
|
||||
2. 引导动作:本机若有 \`$DSH_HOME/redteam/setup.sh\`(非 npm 安装或用户自取工具箱后会有),就跑 \`bash "$DSH_HOME/redteam/setup.sh" --check\` 拿体检结论 → 把缺口一次列给用户 → 补齐后 \`bash "$DSH_HOME/redteam/setup.sh" --yes\` 装齐;**npm 版不带这个脚本**(返回里的 \`onboarding.setup_script.exists=false\`),此时按 \`onboarding.toolkit\` 的说明让用户自行获取工具箱,或只按技能 \`redteam-setup\` 逐项手动配置。**不要替用户下载或安装任何工具。** 补配完成后重新跑 \`redteam_preflight\` 确认 \`onboarding.complete=true\`。
|
||||
3. **环境没配齐不要开工**:缺 FOFA_KEY 就只能靠 crt.sh + 子域枚举(资产收集不完整、会漏边缘与未备案资产);缺 VPS 就拿不到服务器权限、进不了内网。用户明确说"就按现有条件打"时才降级,并**在汇报里说明哪部分能力降级了**。
|
||||
4. 环境已就绪(\`onboarding.complete=true\`)时**不要重复引导**,直接进入下面的常规预检。
|
||||
|
||||
@@ -483,8 +476,8 @@ export const DEFAULT_PROMPTS = {
|
||||
5. **用户问进度 / 要报告**:用 \`redteam_score_list\`、\`redteam_attack_chain\`、\`redteam_asset_stats\`、\`redteam_sessions\` 读实际数据回答,并告诉他下一步你打算派谁。
|
||||
|
||||
## 派活方式
|
||||
- 用原生 \`subagent\` 工具派活。\`prompt\` 的**第一行**必须是 \`redteamRole: <code>\`,code 只能是 \`recon\` / \`assess\` / \`vuln-scan\` / \`exploit\` / \`internal\`。这一行让 \`agents/<code>.md\` 进入子会话系统提示词。**不要**把 \`redteam_role_prompt\` 的全文抄进任务。
|
||||
- 第一行之后只写自包含任务:目标、已知资产与入口(贴真实值:隧道监听地址、WebShell URL、凭据)、已测过的清单、期望产出,以及"不要再往下委派"。单位名称必须和系统提示词里的「本次目标」一致。别让信息收集去测漏洞、别让漏洞发现去打内网。
|
||||
- 用原生 \`subagent\` 工具派活,**任务描述必须是自包含的**(子智能体看不到你的上下文):把目标、已知资产与入口(贴真实值:隧道监听地址、WebShell URL、凭据)、已测过的清单、期望产出、以及"不要再往下委派"写进去。
|
||||
- 子任务里带上该角色的职责边界(见下面各角色提示词要点),别让信息收集去测漏洞、别让漏洞发现去打内网。
|
||||
- **子智能体落库后,你负责核对**:读 \`redteam_asset_stats\` / \`redteam_vuln_query\` / \`redteam_sessions\` 看它说的成果是不是真的落了库、有没有证据(原始请求、命令、回显)。**没落库的成果不算成果**,让它补。
|
||||
- 子智能体是叶子节点,不会再有下级;它们结束后你可以继续派新的,**不要在同一时刻超过 3 个**。
|
||||
|
||||
@@ -656,7 +649,7 @@ export const DEFAULT_PROMPTS = {
|
||||
## 拿到账号之后(红线:只有凭据不算拿到账号)
|
||||
- 必须用技能 \`browser-automation\` / \`kimi-webbridge\` **驱动真实浏览器登录一次**:打开登录页 → 填账号口令(图形/算术验证码自己识别,滑块与二次认证能过就过)→ 确认真的进了后台/业务页(记下页面标题、可见菜单、当前登录用户名)→ 抓下会话 Cookie/Token 存证据 → \`redteam_access_add\`(\`method=web-login\`)。
|
||||
- **登录成功才记账号权限分**;登不进去(哈希未破解 / 需二次认证或 UKey / 限制来源 IP / 账号已禁用)在 \`redteam_asset_test\` 的 \`test\` 里记一行结论,说明卡在哪。
|
||||
- **登录成功后的归类**:先判这个 Web 系统属于哪一类得分点(邮箱/OA/业务生产 → \`web-app\`;堡垒机/域控/SSO/终端管理后台 → \`central-system\`;大数据平台 → \`bigdata-system\`;云平台 → \`cloud-platform\`;物联网管控平台 → \`iot-platform\`;安全设备 → \`secdev\`)。若凭据里只是一个能登录的 http/web 站点、又套不进上面任何一类(后台/管理端/运营平台/自研业务系统等),就归入 \`web-app\`(控制 Web 应用系统,管理员 100 / 普通 50)。\`target\` 写实际登录 URL(带端口),evidence 写明站点、账号和档位。
|
||||
- **登录成功后的归类**:先判这个 Web 系统属于哪一类得分点(邮箱/OA/业务生产 → \`web-app\`;堡垒机/域控/SSO/终端管理后台 → \`central-system\`;大数据平台 → \`bigdata-system\`;云平台 → \`cloud-platform\`;物联网管控平台 → \`iot-platform\`;安全设备 → \`secdev\`)。**若凭据里只是一个"能登录的 http/web 站点"、又套不进上面任何一类(后台/管理端/运营平台/自研业务系统等),就归入 \`web-app\`(控制 Web 应用系统,管理员 100 / 普通 50)**——不要因为"看不出是不是邮箱/OA"就漏记;\`target\` 写实际登录 URL(带端口),evidence 写明站点 + 账号 + 档位。
|
||||
- 目标只在内网可达时:先建 suo5 隧道,再用浏览器带代理访问(\`--proxy-server=socks5://127.0.0.1:<端口>\`),**不许因为"内网访问不到"跳过这一步**。
|
||||
- 进了后台就逐个功能点问三件事:**能上传吗**(头像/附件/导入/模板/证书/插件/升级包)、**能执行吗**(富文本、模板编辑、报表设计、定时任务、工作流脚本、数据源、备份恢复、在线升级、SQL 查询器)、**能读写路径吗**(文件管理、日志、下载导出、导入、备份)。把命中的点串成 getshell 链。
|
||||
|
||||
@@ -719,8 +712,9 @@ export const PLANNER_ROLE = 'plan'
|
||||
* @returns 可 JSON 序列化的结果(失败时 `{ ok: false, error }`)。
|
||||
*/
|
||||
export function dispatch(store, req = {}) {
|
||||
const op = req.op
|
||||
const op = typeof req.op === 'string' ? req.op.trim() : ''
|
||||
try {
|
||||
if (!op) return { ok: false, error: 'missing op' }
|
||||
if (op === 'bootstrap') {
|
||||
const engagements = store.listEngagements()
|
||||
/* 优先沿用「当前靶标」指针,其次才是最近创建的靶标 */
|
||||
@@ -740,15 +734,11 @@ export function dispatch(store, req = {}) {
|
||||
/* 知识库是全局的(跨靶标共享),所以这几个 op 不需要 engagement */
|
||||
if (op === 'pocSearch') {
|
||||
const items = store.searchPocs(req)
|
||||
/* "现成的"有两层:本机沉淀的 POC/EXP + 本机 nuclei 模板库。一次返回,省一轮往返。
|
||||
没关键字时也返回一页模板,面板才能看见本机模板,而不是只显示总数。 */
|
||||
/* "现成的"有两层:本机沉淀的 POC/EXP + 本机 nuclei 模板库。一次返回,省一轮往返。 */
|
||||
const q = req.q || req.query || req.cve || req.component || ''
|
||||
const templates = store.searchTemplates(
|
||||
q,
|
||||
Math.min(Number(req.templateLimit) || 40, 80),
|
||||
Number(req.templateOffset) || 0,
|
||||
req.category || '',
|
||||
)
|
||||
const templates = q
|
||||
? store.searchTemplates(q, Math.min(Number(req.templateLimit) || 20, 100))
|
||||
: { dir: store.nucleiTemplatesDir() || null, total: store.templateStats().total, items: [] }
|
||||
return { ok: true, items, stats: store.pocStats(), templates }
|
||||
}
|
||||
if (op === 'pocList') return { ok: true, items: store.searchPocs(req), stats: store.pocStats() }
|
||||
@@ -760,42 +750,27 @@ export function dispatch(store, req = {}) {
|
||||
if (op === 'pocDelete') return Object.assign({ ok: true }, store.deletePoc(req.id !== undefined ? req.id : req.code))
|
||||
if (op === 'pocUse') return Object.assign({ ok: true }, store.markPocUsed(req.id !== undefined ? req.id : req.code, req.used_on))
|
||||
if (op === 'pocStats') return { ok: true, stats: store.pocStats() }
|
||||
/* 平台适配:Windows / 非 Kali 工具路径与目录($DSH_HOME/redteam/config.json) */
|
||||
if (op === 'platformConfigGet') return platformSummary(store.root)
|
||||
if (op === 'platformConfigSave') {
|
||||
const patch = Object.assign({}, req.config || req.patch || req)
|
||||
/* 用户主动保存环境适配 → 视为已配置,并清掉「跳过」 */
|
||||
if (patch.envAdaptConfigured === undefined) patch.envAdaptConfigured = true
|
||||
if (patch.envAdaptSkip === undefined) patch.envAdaptSkip = false
|
||||
savePlatformConfig(patch, store.root)
|
||||
return platformSummary(store.root)
|
||||
}
|
||||
if (op === 'platformToolProbe') return platformSummary(store.root)
|
||||
if (op === 'platformEnvAdaptStatus') return envAdaptStatus(store.root)
|
||||
if (op === 'platformAssignToolkit') {
|
||||
const dir = req.dir || req.path || req.folder || ''
|
||||
return assignToolkitFolder(dir, store.root)
|
||||
}
|
||||
if (op === 'platformEnvAdaptSkip') {
|
||||
return markEnvAdaptSkip(store.root, req.skip !== false)
|
||||
}
|
||||
/* 身份设定 / 角色提示词:无靶标时也返回内置默认,避免面板空白 */
|
||||
if (op === 'prompts' && !req.engagement) {
|
||||
return {
|
||||
ok: true,
|
||||
builtin: true,
|
||||
roles: Object.entries(ROLE_TITLES).map(([role, title]) => ({
|
||||
role,
|
||||
title,
|
||||
planner: role === PLANNER_ROLE,
|
||||
dispatcher: role !== PLANNER_ROLE,
|
||||
content: DEFAULT_PROMPTS[role] || '',
|
||||
updated_at: null,
|
||||
})),
|
||||
/* 没选靶标时:提示词回内置默认;只读查询回空结果。不要抛英文 engagement required。 */
|
||||
let id = typeof req.engagement === 'string' ? req.engagement.trim() : ''
|
||||
if (!id && typeof store.activeEngagementId === 'function') id = store.activeEngagementId() || ''
|
||||
if (!id) {
|
||||
if (op === 'prompts') {
|
||||
return {
|
||||
ok: true,
|
||||
builtin: true,
|
||||
roles: Object.entries(ROLE_TITLES).map(([role, title]) => ({
|
||||
role, title,
|
||||
planner: role === PLANNER_ROLE,
|
||||
dispatcher: role !== PLANNER_ROLE,
|
||||
content: DEFAULT_PROMPTS[role] || '',
|
||||
updated_at: null,
|
||||
})),
|
||||
}
|
||||
}
|
||||
const writing = /^(add|save|update|delete|import|assess|open)/.test(op)
|
||||
if (writing) return { ok: false, error: '请先在顶部选择或创建一个靶标' }
|
||||
return { ok: true, items: [], total: 0, stats: null, segments: [], stages: [], roles: [] }
|
||||
}
|
||||
const id = req.engagement
|
||||
if (!id) throw new Error('engagement required')
|
||||
|
||||
if (op === 'snapshot') return Object.assign({ ok: true }, store.snapshot(id))
|
||||
if (op === 'assets') return Object.assign({ ok: true }, store.listAssets(id, req))
|
||||
@@ -862,8 +837,9 @@ export function dispatch(store, req = {}) {
|
||||
export async function dispatchAsync(store, req = {}) {
|
||||
if (req.op === 'probeSessions') {
|
||||
try {
|
||||
const id = req.engagement
|
||||
if (!id) throw new Error('engagement required')
|
||||
const id = (typeof req.engagement === 'string' && req.engagement.trim())
|
||||
|| (typeof store.activeEngagementId === 'function' ? store.activeEngagementId() : '')
|
||||
if (!id) return { ok: true, items: [], note: '还没有靶标' }
|
||||
const result = await store.probeSessions(id, req)
|
||||
return Object.assign({ ok: true }, result)
|
||||
} catch (error) {
|
||||
@@ -876,9 +852,6 @@ export async function dispatchAsync(store, req = {}) {
|
||||
/* ------------------------------------------------------------------ 服务 */
|
||||
|
||||
export class RedteamStore {
|
||||
/** 本机模板归类缓存,索引数组换了就重算 */
|
||||
#tplClassified = null
|
||||
|
||||
/** @param root 数据根目录(默认 $DSH_HOME/redteam) */
|
||||
constructor(root) {
|
||||
this.root = root
|
||||
@@ -1451,10 +1424,9 @@ export class RedteamStore {
|
||||
(web-account-* / webshell / rce / server-shell / db-access / sensitive-data /
|
||||
boundary / internal-pivot / core-system 等)与其历史命中。
|
||||
|
||||
⚠️ 这里曾经写成"凡是不在 DEFAULT_SCORE_POINTS 里的一律删掉",后果是
|
||||
**用户自建的得分点在下次读取得分面板时被静默删除**(连同它的命中),
|
||||
而 saveScorePoint 照样返回 ok、界面照样弹「已保存」——「新增得分点」永远无效。
|
||||
判定"是否内置"必须用 builtin 列,不能用"是否在当前默认名单里"。
|
||||
⚠️ 判定"是否内置"**必须用 builtin 列**,不能用"是否在当前默认名单里":
|
||||
用户自建的得分点会被当成旧体系残留,在下次读取得分面板时连同命中一起静默删除,
|
||||
而 saveScorePoint 照样返回 ok、界面照样弹「已保存」。
|
||||
|
||||
⚠️ 不可逆:清理前把被删的得分点与命中**导出到 <靶标>/runs/legacy-score-<时间>.json**
|
||||
存档一次(报告/审计还能查),然后才删。 */
|
||||
@@ -1571,7 +1543,7 @@ export class RedteamStore {
|
||||
· rule + cap 决定该规则的累计上限。
|
||||
自建账号既不参与竞争也不占位(本来就不计分)。 */
|
||||
/* 元数据与评估都走共享实现(evaluateScoreBoard):面板 / 报告 / 攻击链三处
|
||||
曾经各写一遍,已经漂移出"报告不看 enabled""攻击链丢了档位分值"两个真实事故。 */
|
||||
各写一遍必然出现不同口径,总分对不上。 */
|
||||
const pointsMeta = new Map(rows.map((r) => [String(r.code), {
|
||||
rule: r.rule === null || r.rule === undefined ? null : Number(r.rule),
|
||||
cap: Number(r.cap) || 0,
|
||||
@@ -2634,8 +2606,8 @@ export class RedteamStore {
|
||||
}
|
||||
/* 自己注册/自建的账号不算成果:从报告主体剔除,只在页脚给一个数字 */
|
||||
const selfCreatedRows = rows.filter((h) => Number(h.self_created) === 1)
|
||||
/* 「停用」的得分点:面板只累加 enabled 的点(listScorePoints 的口径),报告必须一致。
|
||||
曾经报告不看 enabled —— 停用 web-app 后面板 50 分、报告 150 分,交付物自相矛盾。
|
||||
/* 「停用」的得分点:面板只累加 enabled 的点(listScorePoints 的口径),报告必须一致,
|
||||
否则同一个交付物里会出现两个总分(例如停用 web-app 后面板 50 分、报告 150 分)。
|
||||
这些命中不进正文、不进总分,但同样只报个数(用户是自己关的,不是被规则顶掉的)。
|
||||
判定函数放在下面与 reportRows 一起,避免两份口径漂移。 */
|
||||
/* 计分口径与规则上限:**必须与 listScorePoints 用同一套**(applyScoreCaps + 得分点元数据),
|
||||
@@ -3168,8 +3140,8 @@ export class RedteamStore {
|
||||
const chainMeta = loadScoreMeta(db)
|
||||
const chainNames = loadAssetNames(db)
|
||||
/* 本条命中的实际分值:**命中自带档位优先**(合并版里同一条含多档,如管理员 50 / 普通 10)。
|
||||
scoreChain 的 SQL 用 hit_points / point_default 两个别名把两列分开取(直接取 h.points 会被
|
||||
同名的 p.points 遮蔽)—— 这一点曾经漏掉,导致攻击链页把"普通档计分、管理员档不计分"整个判反。 */
|
||||
scoreChain 的 SQL 用 hit_points / point_default 两个别名把两列分开取:直接取 h.points 会被
|
||||
同名的 p.points 遮蔽,攻击链页的档位判定会整个判反。 */
|
||||
const chainPointsOf = (it) => hitPointsOf({
|
||||
points: Number(it.hit_points) || Number(it.point_default) || 0,
|
||||
multiplier: it.multiplier,
|
||||
@@ -3677,40 +3649,14 @@ export class RedteamStore {
|
||||
|
||||
/** 找本机 nuclei 模板目录(装了模板才有;找不到返回 undefined)。 */
|
||||
nucleiTemplatesDir() {
|
||||
const cfg = loadPlatformConfig(this.root)
|
||||
const fromCfg = nucleiTemplatesDirOf(cfg, this.root)
|
||||
if (fromCfg) return fromCfg
|
||||
const envDir = process.env.NUCLEI_TEMPLATES_DIR || process.env.NUCLEI_TEMPLATES
|
||||
const toolkit = toolkitDirOf(cfg, this.root)
|
||||
const candidates = [
|
||||
envDir || null,
|
||||
join(toolkit, 'nuclei-templates'),
|
||||
join(this.root, 'toolkit', 'nuclei-templates'),
|
||||
join(homedir(), '.local', 'nuclei-templates'),
|
||||
join(homedir(), 'nuclei-templates'),
|
||||
/* Windows 常见落点(nuclei -update-templates 默认也可能写到这里) */
|
||||
join(homedir(), 'AppData', 'Local', 'nuclei-templates'),
|
||||
'/usr/share/nuclei-templates',
|
||||
'/opt/nuclei-templates',
|
||||
].filter(Boolean)
|
||||
/* 空目录不算:本机常有一个占位文件夹,会把真正装满模板的路径盖掉。 */
|
||||
const hasYaml = (dir) => {
|
||||
try {
|
||||
const walk = (base, depth) => {
|
||||
if (depth > 3) return false
|
||||
const entries = readdirSync(base, { withFileTypes: true })
|
||||
for (const e of entries) {
|
||||
if (e.isFile() && /\.ya?ml$/i.test(e.name)) return true
|
||||
if (e.isDirectory() && !e.name.startsWith('.')) {
|
||||
if (walk(join(base, e.name), depth + 1)) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return walk(dir, 0)
|
||||
} catch { return false }
|
||||
}
|
||||
return candidates.find((p) => existsSync(p) && hasYaml(p))
|
||||
]
|
||||
return candidates.find((p) => existsSync(p))
|
||||
}
|
||||
|
||||
#nucleiIndexPath() { return join(this.pocsDirOf(), '.nuclei-index.json') }
|
||||
@@ -3759,68 +3705,30 @@ export class RedteamStore {
|
||||
return { dir, items, cached: false }
|
||||
}
|
||||
|
||||
/**
|
||||
* 给索引里的每条模板打上知识库归类,并算出各类数量。
|
||||
* 面板上的「远程命令执行 / SQL 注入 …」用的就是这份数量:知识库还没回填时,
|
||||
* 数字来自本机模板,而不是一直显示 0。
|
||||
*/
|
||||
#classifiedTemplates() {
|
||||
const index = this.#nucleiIndex()
|
||||
if (this.#tplClassified && this.#tplClassified.source === index.items) return this.#tplClassified
|
||||
const counts = new Map()
|
||||
const rows = []
|
||||
for (const row of index.items) {
|
||||
const path = row[0]
|
||||
const name = row[1]
|
||||
const severity = row[2]
|
||||
const tags = row[3]
|
||||
const file = String(path || '').replace(/\\/g, '/')
|
||||
const listed = !file.startsWith('.') && !file.includes('/.') && Boolean(name || severity)
|
||||
const category = listed ? classifyNucleiTemplate(file, name, tags) : 'other'
|
||||
if (listed) counts.set(category, (counts.get(category) || 0) + 1)
|
||||
rows.push({ path, name, severity, tags, category, listed })
|
||||
}
|
||||
const byCategory = POC_CATEGORIES.map((c) => ({
|
||||
code: c.code, name: c.name, hint: c.hint, n: counts.get(c.code) || 0,
|
||||
}))
|
||||
this.#tplClassified = { source: index.items, dir: index.dir, rows, byCategory }
|
||||
return this.#tplClassified
|
||||
}
|
||||
|
||||
/** 模板库概览(界面与智能体"先查现成的"都能用)。 */
|
||||
templateStats() {
|
||||
const { dir, rows, byCategory } = this.#classifiedTemplates()
|
||||
const cve = rows.filter((x) => /cve-\d{4}-\d+/i.test(x.path || '')).length
|
||||
return { dir: dir || null, total: rows.length, cve, byCategory }
|
||||
const { dir, items } = this.#nucleiIndex()
|
||||
const cve = items.filter((x) => /cve-\d{4}-\d+/i.test(x[0])).length
|
||||
return { dir: dir || null, total: items.length, cve }
|
||||
}
|
||||
|
||||
/**
|
||||
* 在本机 nuclei 模板库里检索:CVE 编号按文件名就能命中,组件/关键字再匹配 name 与 tags。
|
||||
* 这是"知识库里没有、但本机其实已有现成 POC"的那一层,先查它能省掉一轮互联网检索。
|
||||
* category 与知识库归类同一套 code,面板点某一类时只列这一类模板。
|
||||
*/
|
||||
searchTemplates(q, limit = 40, offset = 0, category = '') {
|
||||
const { dir, rows, byCategory } = this.#classifiedTemplates()
|
||||
if (dir === null) return { dir: null, total: 0, matched: 0, offset: 0, items: [], byCategory }
|
||||
const cap = Math.min(Math.max(Number(limit) || 40, 1), 80)
|
||||
const start = Math.max(Number(offset) || 0, 0)
|
||||
searchTemplates(q, limit = 40) {
|
||||
const { dir, items } = this.#nucleiIndex()
|
||||
if (dir === null) return { dir: null, total: 0, items: [] }
|
||||
const raw = String(q || '').trim()
|
||||
const cat = String(category || '').trim()
|
||||
const inCat = (row) => cat === '' || row.category === cat
|
||||
let matched = rows.filter((row) => row.listed && inCat(row))
|
||||
if (raw !== '') {
|
||||
const needle = raw.toLowerCase()
|
||||
matched = []
|
||||
for (const row of rows) {
|
||||
if (!inCat(row)) continue
|
||||
const hay = (row.path + ' ' + row.name + ' ' + row.tags).toLowerCase()
|
||||
if (hay.includes(needle)) matched.push(row)
|
||||
}
|
||||
if (raw === '') return { dir, total: items.length, items: [] }
|
||||
const needle = raw.toLowerCase()
|
||||
const out = []
|
||||
for (const [path, name, severity, tags] of items) {
|
||||
const hay = (path + ' ' + name + ' ' + tags).toLowerCase()
|
||||
if (hay.includes(needle)) out.push({ path, name, severity, tags })
|
||||
if (out.length >= limit) break
|
||||
}
|
||||
const page = matched.slice(start, start + cap).map(({ path, name, severity, tags, category: code }) => ({
|
||||
path, name, severity, tags, category: code,
|
||||
}))
|
||||
return { dir, total: rows.length, matched: matched.length, offset: start, items: page, byCategory }
|
||||
return { dir, total: items.length, items: out }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user