mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 05:00:22 +08:00
fix: 发布 1.1.34,知识库列出本机模板,更新包在三端都能解压
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
56007e9ec0
commit
7fc64e4b45
12 files changed
+447
-56
No files matched your search
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.33</strong></p>
|
||||
<p align="center"><strong>Version 1.1.34</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>Local official DeepSeek Harness cybersecurity red-team plugin. Clean host policy, and ship a built-in drill console. Swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐</em>
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.33</strong></p>
|
||||
<p align="center"><strong>Version 1.1.34</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||
|
||||
@@ -5164,8 +5164,13 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
const [openId, setOpenId] = React.useState(null)
|
||||
const [detail, setDetail] = React.useState(null)
|
||||
const [detailBusy, setDetailBusy] = React.useState(false)
|
||||
const [tplOffset, setTplOffset] = React.useState(0)
|
||||
const tplPageSize = 40
|
||||
|
||||
const query = (over) => {
|
||||
const extra = over || {}
|
||||
const offset = Object.prototype.hasOwnProperty.call(extra, 'templateOffset') ? extra.templateOffset : 0
|
||||
setTplOffset(offset)
|
||||
const params = Object.assign({
|
||||
q: q.trim() || undefined,
|
||||
kind: kind || undefined,
|
||||
@@ -5173,7 +5178,9 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
engagement: engagement || undefined,
|
||||
asset_target: assetTarget.trim() || undefined,
|
||||
verified: verifiedOnly || undefined,
|
||||
}, over || {})
|
||||
templateOffset: offset || 0,
|
||||
templateLimit: tplPageSize,
|
||||
}, extra)
|
||||
setBusy(true); setMsg(null)
|
||||
api(Object.assign({ op: 'pocSearch' }, params)).then((r) => {
|
||||
setBusy(false)
|
||||
@@ -5207,8 +5214,15 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
|
||||
const stats = (data && data.stats) || { total: 0, verified: 0, reused: 0, byKind: [], bySource: [] }
|
||||
const items = (data && data.items) || []
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, items: [] }
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, matched: 0, offset: 0, items: [] }
|
||||
const tplItems = tpl.items || []
|
||||
const tplMatched = tpl.matched != null ? tpl.matched : tpl.total
|
||||
const tplStart = Number(tpl.offset) || 0
|
||||
const turnTpl = (next) => {
|
||||
const offset = Math.max(0, next)
|
||||
setTplOffset(offset)
|
||||
query({ templateOffset: offset })
|
||||
}
|
||||
|
||||
const card = (x) => {
|
||||
const isOpen = openId === x.id
|
||||
@@ -5348,8 +5362,9 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
tplItems.length
|
||||
? h('div', { className: 'rt-kb-tpl' },
|
||||
h('div', { className: 'rt-ap-sub' },
|
||||
'本机 nuclei 模板命中 · ' + tplItems.length + ' 条(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + i, className: 'rt-kb-tpl-row' },
|
||||
'本机 nuclei 模板 · ' + (tplStart + 1) + '–' + (tplStart + tplItems.length) + ' / ' + tplMatched
|
||||
+ '(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + tplStart + '-' + i, className: 'rt-kb-tpl-row' },
|
||||
h('span', { className: 'rt-tag' }, t.severity || '—'),
|
||||
h('span', { className: 'rt-mono rt-kb-tpl-path', title: t.path }, t.path),
|
||||
h('span', { className: 'rt-kb-tpl-name', title: t.name }, t.name || ''),
|
||||
@@ -5357,6 +5372,15 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
className: 'rt-btn', style: { padding: '0 6px', fontSize: 10.5 },
|
||||
onClick: () => copy('nuclei -t ' + t.path + ' -u <目标>', '模板命令'),
|
||||
}, '复制命令'))),
|
||||
h('div', { className: 'rt-kb-actions' },
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart <= 0,
|
||||
onClick: () => turnTpl(tplStart - tplPageSize),
|
||||
}, '上一页'),
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart + tplItems.length >= tplMatched,
|
||||
onClick: () => turnTpl(tplStart + tplPageSize),
|
||||
}, '下一页')),
|
||||
tpl.dir ? h('div', { className: 'rt-foot' }, h('span', null, '模板目录:' + tpl.dir)) : null)
|
||||
: null,
|
||||
data === null ? h('div', { className: 'rt-empty' }, '加载中…') : null,
|
||||
@@ -5366,7 +5390,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
q || kind || verifiedOnly
|
||||
? '没有命中:换个关键字再试,或去互联网找 / 自己手搓后回填。'
|
||||
: (tpl.total
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板 —— 在上方搜 CVE / 组件即可命中。')
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板,但这一页没有列出来。请完全退出后重新打开客户端。')
|
||||
: (tpl.dir
|
||||
? '知识库还是空的(本机模板目录存在但没有 yaml,请跑 nuclei -update-templates)。'
|
||||
: '知识库还是空的。本机也还没有 nuclei 模板库 —— 在演练机上跑 setup.sh 或 `nuclei -update-templates`,装好后这里会出现「本机模板 N」。'))),
|
||||
|
||||
+29
-5
@@ -2243,8 +2243,13 @@ window.__ModuleLoader__.load({
|
||||
const [openId, setOpenId] = React.useState(null)
|
||||
const [detail, setDetail] = React.useState(null)
|
||||
const [detailBusy, setDetailBusy] = React.useState(false)
|
||||
const [tplOffset, setTplOffset] = React.useState(0)
|
||||
const tplPageSize = 40
|
||||
|
||||
const query = (over) => {
|
||||
const extra = over || {}
|
||||
const offset = Object.prototype.hasOwnProperty.call(extra, 'templateOffset') ? extra.templateOffset : 0
|
||||
setTplOffset(offset)
|
||||
const params = Object.assign({
|
||||
q: q.trim() || undefined,
|
||||
kind: kind || undefined,
|
||||
@@ -2252,7 +2257,9 @@ window.__ModuleLoader__.load({
|
||||
engagement: engagement || undefined,
|
||||
asset_target: assetTarget.trim() || undefined,
|
||||
verified: verifiedOnly || undefined,
|
||||
}, over || {})
|
||||
templateOffset: offset || 0,
|
||||
templateLimit: tplPageSize,
|
||||
}, extra)
|
||||
setBusy(true); setMsg(null)
|
||||
api(Object.assign({ op: 'pocSearch' }, params)).then((r) => {
|
||||
setBusy(false)
|
||||
@@ -2286,8 +2293,15 @@ window.__ModuleLoader__.load({
|
||||
|
||||
const stats = (data && data.stats) || { total: 0, verified: 0, reused: 0, byKind: [], bySource: [] }
|
||||
const items = (data && data.items) || []
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, items: [] }
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, matched: 0, offset: 0, items: [] }
|
||||
const tplItems = tpl.items || []
|
||||
const tplMatched = tpl.matched != null ? tpl.matched : tpl.total
|
||||
const tplStart = Number(tpl.offset) || 0
|
||||
const turnTpl = (next) => {
|
||||
const offset = Math.max(0, next)
|
||||
setTplOffset(offset)
|
||||
query({ templateOffset: offset })
|
||||
}
|
||||
|
||||
const card = (x) => {
|
||||
const isOpen = openId === x.id
|
||||
@@ -2427,8 +2441,9 @@ window.__ModuleLoader__.load({
|
||||
tplItems.length
|
||||
? h('div', { className: 'rt-kb-tpl' },
|
||||
h('div', { className: 'rt-ap-sub' },
|
||||
'本机 nuclei 模板命中 · ' + tplItems.length + ' 条(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + i, className: 'rt-kb-tpl-row' },
|
||||
'本机 nuclei 模板 · ' + (tplStart + 1) + '–' + (tplStart + tplItems.length) + ' / ' + tplMatched
|
||||
+ '(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + tplStart + '-' + i, className: 'rt-kb-tpl-row' },
|
||||
h('span', { className: 'rt-tag' }, t.severity || '—'),
|
||||
h('span', { className: 'rt-mono rt-kb-tpl-path', title: t.path }, t.path),
|
||||
h('span', { className: 'rt-kb-tpl-name', title: t.name }, t.name || ''),
|
||||
@@ -2436,6 +2451,15 @@ window.__ModuleLoader__.load({
|
||||
className: 'rt-btn', style: { padding: '0 6px', fontSize: 10.5 },
|
||||
onClick: () => copy('nuclei -t ' + t.path + ' -u <目标>', '模板命令'),
|
||||
}, '复制命令'))),
|
||||
h('div', { className: 'rt-kb-actions' },
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart <= 0,
|
||||
onClick: () => turnTpl(tplStart - tplPageSize),
|
||||
}, '上一页'),
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart + tplItems.length >= tplMatched,
|
||||
onClick: () => turnTpl(tplStart + tplPageSize),
|
||||
}, '下一页')),
|
||||
tpl.dir ? h('div', { className: 'rt-foot' }, h('span', null, '模板目录:' + tpl.dir)) : null)
|
||||
: null,
|
||||
data === null ? h('div', { className: 'rt-empty' }, '加载中…') : null,
|
||||
@@ -2445,7 +2469,7 @@ window.__ModuleLoader__.load({
|
||||
q || kind || verifiedOnly
|
||||
? '没有命中:换个关键字再试,或去互联网找 / 自己手搓后回填。'
|
||||
: (tpl.total
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板 —— 在上方搜 CVE / 组件即可命中。')
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板,但这一页没有列出来。请完全退出后重新打开客户端。')
|
||||
: (tpl.dir
|
||||
? '知识库还是空的(本机模板目录存在但没有 yaml,请跑 nuclei -update-templates)。'
|
||||
: '知识库还是空的。本机也还没有 nuclei 模板库 —— 在演练机上跑 setup.sh 或 `nuclei -update-templates`,装好后这里会出现「本机模板 N」。'))),
|
||||
|
||||
+27
-14
@@ -739,11 +739,14 @@ 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 = q
|
||||
? store.searchTemplates(q, Math.min(Number(req.templateLimit) || 20, 100))
|
||||
: { dir: store.nucleiTemplatesDir() || null, total: store.templateStats().total, items: [] }
|
||||
const templates = store.searchTemplates(
|
||||
q,
|
||||
Math.min(Number(req.templateLimit) || 40, 80),
|
||||
Number(req.templateOffset) || 0,
|
||||
)
|
||||
return { ok: true, items, stats: store.pocStats(), templates }
|
||||
}
|
||||
if (op === 'pocList') return { ok: true, items: store.searchPocs(req), stats: store.pocStats() }
|
||||
@@ -3762,19 +3765,29 @@ export class RedteamStore {
|
||||
* 在本机 nuclei 模板库里检索:CVE 编号按文件名就能命中,组件/关键字再匹配 name 与 tags。
|
||||
* 这是"知识库里没有、但本机其实已有现成 POC"的那一层,先查它能省掉一轮互联网检索。
|
||||
*/
|
||||
searchTemplates(q, limit = 40) {
|
||||
searchTemplates(q, limit = 40, offset = 0) {
|
||||
const { dir, items } = this.#nucleiIndex()
|
||||
if (dir === null) return { dir: null, total: 0, items: [] }
|
||||
if (dir === null) return { dir: null, total: 0, matched: 0, offset: 0, items: [] }
|
||||
const cap = Math.min(Math.max(Number(limit) || 40, 1), 80)
|
||||
const start = Math.max(Number(offset) || 0, 0)
|
||||
const raw = String(q || '').trim()
|
||||
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
|
||||
/* 没关键字时也要列出一页。跳过 .github 这类没有 name/severity 的 yaml,否则第一页不是模板。 */
|
||||
const listed = (row) => {
|
||||
const file = String(row[0] || '').replace(/\\/g, '/')
|
||||
if (file.startsWith('.') || file.includes('/.')) return false
|
||||
return Boolean(row[1] || row[2])
|
||||
}
|
||||
return { dir, total: items.length, items: out }
|
||||
let matched = items.filter(listed)
|
||||
if (raw !== '') {
|
||||
const needle = raw.toLowerCase()
|
||||
matched = []
|
||||
for (const row of items) {
|
||||
const hay = (row[0] + ' ' + row[1] + ' ' + row[3]).toLowerCase()
|
||||
if (hay.includes(needle)) matched.push(row)
|
||||
}
|
||||
}
|
||||
const page = matched.slice(start, start + cap).map(([path, name, severity, tags]) => ({ path, name, severity, tags }))
|
||||
return { dir, total: items.length, matched: matched.length, offset: start, items: page }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+28
-14
@@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { findDshHome } from "./core.js";
|
||||
import { extractZipArchive, listZipFile } from "./zip-extract.js";
|
||||
|
||||
export { findDshHome };
|
||||
|
||||
@@ -377,14 +378,31 @@ function isUnsafeArchiveEntry(name) {
|
||||
return rel.split("/").some((part) => part === ".." || part === "");
|
||||
}
|
||||
|
||||
function splitLines(text) {
|
||||
return String(text || "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
function listArchiveEntries(archivePath) {
|
||||
const result = spawnSync("tar", ["-tf", archivePath], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 15000,
|
||||
});
|
||||
if (result.status !== 0) return null;
|
||||
return String(result.stdout || "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
||||
if (result.status === 0) return splitLines(result.stdout);
|
||||
if (/\.zip$/i.test(archivePath)) {
|
||||
const unzip = spawnSync("unzip", ["-Z1", archivePath], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 15000,
|
||||
});
|
||||
if (unzip.status === 0) return splitLines(unzip.stdout);
|
||||
try {
|
||||
return listZipFile(archivePath);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractArchive(archivePath, dest) {
|
||||
@@ -395,24 +413,20 @@ function extractArchive(archivePath, dest) {
|
||||
if (entries && entries.length > MAX_IMPORT_FILES) {
|
||||
throw new Error("压缩包里文件太多");
|
||||
}
|
||||
if (/\.zip$/i.test(archivePath)) {
|
||||
try {
|
||||
extractZipArchive(archivePath, dest);
|
||||
return;
|
||||
} catch (error) {
|
||||
throw new Error(String(error && error.message ? error.message : error));
|
||||
}
|
||||
}
|
||||
const result = spawnSync("tar", ["-xf", archivePath, "-C", dest], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 30000,
|
||||
});
|
||||
if (result.status === 0) return;
|
||||
if (/\.zip$/i.test(archivePath) && process.platform === "win32") {
|
||||
const ps = spawnSync("powershell", [
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
`Expand-Archive -LiteralPath '${String(archivePath).replace(/'/g, "''")}' -DestinationPath '${String(dest).replace(/'/g, "''")}' -Force`,
|
||||
], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 30000,
|
||||
});
|
||||
if (ps.status === 0) return;
|
||||
}
|
||||
const detail = String(result.stderr || result.stdout || "").trim();
|
||||
throw new Error(detail || "无法解压,请改用文件夹导入");
|
||||
}
|
||||
|
||||
+4
-15
@@ -9,6 +9,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { findDshHome } from "./core.js";
|
||||
import { adapterFor, detectSurface } from "./surface.js";
|
||||
import { cliInvocation } from "./desktop.js";
|
||||
import { extractZipArchive } from "./zip-extract.js";
|
||||
|
||||
const REPO = "YuJunZhiXue/dsh-purge";
|
||||
const STABLE_REF = "master";
|
||||
@@ -922,21 +923,9 @@ function gitResetTo(dir, ref, { force = false } = {}) {
|
||||
}
|
||||
|
||||
function extractZip(zip, dest) {
|
||||
try {
|
||||
execFileSync("tar", ["-xf", zip, "-C", dest], { ...HIDDEN, timeout: 60000 });
|
||||
return;
|
||||
} catch {
|
||||
// Windows 10+ 自带 tar;没有或失败时改 PowerShell。
|
||||
}
|
||||
execFileSync(
|
||||
"powershell",
|
||||
["-NoProfile", "-Command", "Expand-Archive -LiteralPath $env:DSH_UPD_ZIP -DestinationPath $env:DSH_UPD_DIR -Force"],
|
||||
{
|
||||
...HIDDEN,
|
||||
timeout: 60000,
|
||||
env: { ...process.env, DSH_UPD_ZIP: zip, DSH_UPD_DIR: dest },
|
||||
},
|
||||
);
|
||||
// win32:tar(bsdtar) → powershell。darwin/linux:tar → unzip → python3 → bsdtar。
|
||||
// 外部工具都不可用时用 Node 解 zip,Linux 不会再去调用 powershell。
|
||||
extractZipArchive(zip, dest);
|
||||
}
|
||||
|
||||
async function overlayFromZip(dests, ref = STABLE_REF) {
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import zlib from "node:zlib";
|
||||
|
||||
const HIDDEN = {
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
windowsHide: true,
|
||||
timeout: 60000,
|
||||
};
|
||||
|
||||
/** 各平台解压顺序。node 不调用外部命令,macOS / Linux / Windows 都能用。 */
|
||||
export function unzipTools(platform = process.platform) {
|
||||
if (platform === "win32") return ["tar", "powershell", "node"];
|
||||
return ["tar", "unzip", "python3", "bsdtar", "node"];
|
||||
}
|
||||
|
||||
function safeZipName(name) {
|
||||
const rel = String(name || "").replace(/\\/g, "/").replace(/^\.?\//, "").replace(/\/+$/, "");
|
||||
if (!rel) return "";
|
||||
if (rel.startsWith("/") || /^[A-Za-z]:/.test(rel)) throw new Error("zip 路径不合法");
|
||||
const parts = rel.split("/");
|
||||
if (parts.some((part) => part === ".." || part === "")) throw new Error("zip 路径不合法");
|
||||
return parts.join("/");
|
||||
}
|
||||
|
||||
function findEocd(buf) {
|
||||
const min = Math.max(0, buf.length - 22 - 65535);
|
||||
for (let i = buf.length - 22; i >= min; i -= 1) {
|
||||
if (buf.readUInt32LE(i) === 0x06054b50) return i;
|
||||
}
|
||||
throw new Error("不是 zip");
|
||||
}
|
||||
|
||||
function readZipEntries(buf) {
|
||||
if (!Buffer.isBuffer(buf) || buf.length < 22) throw new Error("不是 zip");
|
||||
const eocd = findEocd(buf);
|
||||
const total = buf.readUInt16LE(eocd + 10);
|
||||
let cursor = buf.readUInt32LE(eocd + 16);
|
||||
const entries = [];
|
||||
for (let n = 0; n < total; n += 1) {
|
||||
if (cursor + 46 > buf.length || buf.readUInt32LE(cursor) !== 0x02014b50) {
|
||||
throw new Error("zip 目录损坏");
|
||||
}
|
||||
const method = buf.readUInt16LE(cursor + 10);
|
||||
const compSize = buf.readUInt32LE(cursor + 20);
|
||||
const nameLen = buf.readUInt16LE(cursor + 28);
|
||||
const extraLen = buf.readUInt16LE(cursor + 30);
|
||||
const commentLen = buf.readUInt16LE(cursor + 32);
|
||||
const localOffset = buf.readUInt32LE(cursor + 42);
|
||||
const name = buf.toString("utf8", cursor + 46, cursor + 46 + nameLen);
|
||||
entries.push({ name, method, compSize, localOffset });
|
||||
cursor += 46 + nameLen + extraLen + commentLen;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
export function listZipEntries(buf) {
|
||||
return readZipEntries(buf).map((entry) => entry.name.replace(/\\/g, "/"));
|
||||
}
|
||||
|
||||
export function listZipFile(zipPath) {
|
||||
return listZipEntries(fs.readFileSync(zipPath));
|
||||
}
|
||||
|
||||
function localDataOffset(buf, localOffset) {
|
||||
if (localOffset + 30 > buf.length || buf.readUInt32LE(localOffset) !== 0x04034b50) {
|
||||
throw new Error("zip 本地头损坏");
|
||||
}
|
||||
const nameLen = buf.readUInt16LE(localOffset + 26);
|
||||
const extraLen = buf.readUInt16LE(localOffset + 28);
|
||||
return localOffset + 30 + nameLen + extraLen;
|
||||
}
|
||||
|
||||
export function extractZipBuffer(buf, dest) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
const root = path.resolve(dest);
|
||||
for (const entry of readZipEntries(buf)) {
|
||||
const rel = safeZipName(entry.name);
|
||||
if (!rel) continue;
|
||||
if (entry.compSize === 0xffffffff || entry.localOffset === 0xffffffff) {
|
||||
throw new Error("不支持 zip64");
|
||||
}
|
||||
if (entry.method !== 0 && entry.method !== 8) {
|
||||
throw new Error(`不支持的 zip 压缩方式 ${entry.method}`);
|
||||
}
|
||||
const start = localDataOffset(buf, entry.localOffset);
|
||||
const end = start + entry.compSize;
|
||||
if (end > buf.length) throw new Error("zip 数据被截断");
|
||||
const compressed = buf.subarray(start, end);
|
||||
const body = entry.method === 0 ? compressed : zlib.inflateRawSync(compressed);
|
||||
const out = path.resolve(root, rel);
|
||||
const prefix = root.endsWith(path.sep) ? root : root + path.sep;
|
||||
if (out !== root && !out.startsWith(prefix)) throw new Error("zip 路径不合法");
|
||||
fs.mkdirSync(path.dirname(out), { recursive: true });
|
||||
fs.writeFileSync(out, body);
|
||||
}
|
||||
}
|
||||
|
||||
function attempt(file, args, extra = {}) {
|
||||
try {
|
||||
execFileSync(file, args, {
|
||||
...HIDDEN,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
...extra,
|
||||
});
|
||||
return "";
|
||||
} catch (error) {
|
||||
const detail = String((error && (error.stderr || error.stdout || error.message)) || "")
|
||||
.trim()
|
||||
.split(/\r?\n/)
|
||||
.filter(Boolean)[0];
|
||||
return detail ? `${file}: ${detail}` : file;
|
||||
}
|
||||
}
|
||||
|
||||
/** 按平台试外部工具,最后用 Node 解 zip。成功返回用到的方式。 */
|
||||
export function extractZipArchive(zipPath, dest, tools = unzipTools()) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
const notes = [];
|
||||
for (const tool of tools) {
|
||||
if (tool === "node") {
|
||||
try {
|
||||
extractZipBuffer(fs.readFileSync(zipPath), dest);
|
||||
return "node";
|
||||
} catch (error) {
|
||||
notes.push(`node: ${error && error.message ? error.message : error}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tool === "tar" || tool === "bsdtar") {
|
||||
const note = attempt(tool, ["-xf", zipPath, "-C", dest]);
|
||||
if (!note) return tool;
|
||||
notes.push(note);
|
||||
continue;
|
||||
}
|
||||
if (tool === "unzip") {
|
||||
const note = attempt("unzip", ["-o", "-q", zipPath, "-d", dest]);
|
||||
if (!note) return "unzip";
|
||||
notes.push(note);
|
||||
continue;
|
||||
}
|
||||
if (tool === "python3") {
|
||||
const note = attempt("python3", ["-m", "zipfile", "-e", zipPath, dest]);
|
||||
if (!note) return "python3";
|
||||
notes.push(note);
|
||||
continue;
|
||||
}
|
||||
if (tool === "powershell") {
|
||||
const note = attempt(
|
||||
"powershell",
|
||||
["-NoProfile", "-Command", "Expand-Archive -LiteralPath $env:DSH_UPD_ZIP -DestinationPath $env:DSH_UPD_DIR -Force"],
|
||||
{ env: { ...process.env, DSH_UPD_ZIP: zipPath, DSH_UPD_DIR: dest } },
|
||||
);
|
||||
if (!note) return "powershell";
|
||||
notes.push(note);
|
||||
}
|
||||
}
|
||||
throw new Error(`解压失败:${notes.join(" | ") || "没有可用的解压工具"}`);
|
||||
}
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.33",
|
||||
"version": "1.1.34",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
@@ -39,6 +39,8 @@
|
||||
"test:identity": "node scripts/test-identity-assembly.mjs",
|
||||
"test:yaml": "node scripts/test-yaml-comment.mjs",
|
||||
"test:update": "node scripts/test-update-guards.mjs",
|
||||
"test:zip": "node scripts/test-zip-extract.mjs",
|
||||
"test:templates": "node scripts/test-template-page.mjs",
|
||||
"test:rewind": "node scripts/test-rewind-plan.mjs",
|
||||
"test:idempotence": "node scripts/test-patch-idempotence.mjs",
|
||||
"test:surface": "node scripts/test-surface-desktop.mjs",
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# 1.1.34
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本升级到 1.1.34。
|
||||
- **演练台知识库直接列出本机模板**。打开「知识库 · POC / EXP」就能看到一页 nuclei 模板,并可以翻页、按 CVE 或组件搜索。不再只显示「本机模板 N」、下面是空的。
|
||||
- **更新包在 Windows、macOS、Linux 上都能解压**。Linux 不再调用 PowerShell。顺序是:Windows 用 tar,不行再用 PowerShell;macOS 和 Linux 用 tar、unzip、python3、bsdtar。这些都没有时,用 Node 自己解 zip。感谢 @cracer4869 在 #44 报出 Kali 上的 `spawnSync powershell ENOENT`。
|
||||
|
||||
## English
|
||||
|
||||
- Version 1.1.34.
|
||||
- **The drill knowledge page lists local templates.** Opening Knowledge shows a page of nuclei templates, with paging and search by CVE or component. It no longer shows only the template count.
|
||||
- **Update archives extract on Windows, macOS, and Linux.** Linux does not call PowerShell. Windows tries tar, then PowerShell. macOS and Linux try tar, unzip, python3, then bsdtar. If none of those exist, Node extracts the zip itself. Thanks to @cracer4869 for reporting `spawnSync powershell ENOENT` on Kali in #44.
|
||||
|
||||
# 1.1.33
|
||||
|
||||
## 中文
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { dispatch, RedteamStore } from "../lib/redteam/store-core.js";
|
||||
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-tpl-"));
|
||||
const templates = path.join(root, "templates");
|
||||
fs.mkdirSync(path.join(templates, ".github"), { recursive: true });
|
||||
fs.mkdirSync(path.join(templates, "http"), { recursive: true });
|
||||
fs.writeFileSync(path.join(templates, ".github", "auto.yml"), "name: nope\n");
|
||||
fs.writeFileSync(
|
||||
path.join(templates, "http", "cve.yml"),
|
||||
"id: x\ninfo:\n name: CVE-2024-1 demo\n severity: high\n tags: cve\n",
|
||||
);
|
||||
|
||||
const prev = process.env.NUCLEI_TEMPLATES_DIR;
|
||||
process.env.NUCLEI_TEMPLATES_DIR = templates;
|
||||
let store;
|
||||
try {
|
||||
store = new RedteamStore(path.join(root, "rt"));
|
||||
const page = store.searchTemplates("", 40, 0);
|
||||
assert.equal(page.total, 2);
|
||||
assert.equal(page.matched, 1);
|
||||
assert.equal(page.items.length, 1);
|
||||
assert.equal(page.items[0].name, "CVE-2024-1 demo");
|
||||
assert.equal(page.items[0].severity, "high");
|
||||
const found = store.searchTemplates("CVE-2024-1");
|
||||
assert.equal(found.items.length, 1);
|
||||
const hidden = store.searchTemplates("nope");
|
||||
assert.equal(hidden.items[0].path.replace(/\\/g, "/"), ".github/auto.yml");
|
||||
const listed = dispatch(store, { op: "pocSearch", templateLimit: 40, templateOffset: 0 });
|
||||
assert.equal(listed.ok, true);
|
||||
assert.equal(listed.templates.items.length, 1);
|
||||
assert.equal(listed.templates.total, 2);
|
||||
console.log("ok: template page");
|
||||
} finally {
|
||||
try { store?.close(); } catch { /* ignore */ }
|
||||
if (prev === undefined) delete process.env.NUCLEI_TEMPLATES_DIR;
|
||||
else process.env.NUCLEI_TEMPLATES_DIR = prev;
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import zlib from "node:zlib";
|
||||
import { extractZipArchive, extractZipBuffer, listZipEntries, unzipTools } from "../lib/zip-extract.js";
|
||||
|
||||
function crc32(buf) {
|
||||
let c = ~0;
|
||||
for (const byte of buf) {
|
||||
c ^= byte;
|
||||
for (let i = 0; i < 8; i += 1) c = (c >>> 1) ^ (0xedb88320 & -(c & 1));
|
||||
}
|
||||
return ~c >>> 0;
|
||||
}
|
||||
|
||||
function u16(n) {
|
||||
const b = Buffer.alloc(2);
|
||||
b.writeUInt16LE(n);
|
||||
return b;
|
||||
}
|
||||
|
||||
function u32(n) {
|
||||
const b = Buffer.alloc(4);
|
||||
b.writeUInt32LE(n >>> 0);
|
||||
return b;
|
||||
}
|
||||
|
||||
function buildZip(files) {
|
||||
const locals = [];
|
||||
const centrals = [];
|
||||
let offset = 0;
|
||||
for (const file of files) {
|
||||
const name = Buffer.from(file.name, "utf8");
|
||||
const body = Buffer.from(file.body);
|
||||
const method = file.method === 8 ? 8 : 0;
|
||||
const data = method === 8 ? zlib.deflateRawSync(body) : body;
|
||||
const crc = crc32(body);
|
||||
const local = Buffer.concat([
|
||||
u32(0x04034b50), u16(20), u16(0), u16(method), u16(0), u16(0),
|
||||
u32(crc), u32(data.length), u32(body.length), u16(name.length), u16(0),
|
||||
name, data,
|
||||
]);
|
||||
locals.push(local);
|
||||
const central = Buffer.concat([
|
||||
u32(0x02014b50), u16(20), u16(20), u16(0), u16(method), u16(0), u16(0),
|
||||
u32(crc), u32(data.length), u32(body.length), u16(name.length), u16(0), u16(0),
|
||||
u16(0), u16(0), u32(0), u32(offset),
|
||||
name,
|
||||
]);
|
||||
centrals.push(central);
|
||||
offset += local.length;
|
||||
}
|
||||
const cd = Buffer.concat(centrals);
|
||||
const eocd = Buffer.concat([
|
||||
u32(0x06054b50), u16(0), u16(0), u16(files.length), u16(files.length),
|
||||
u32(cd.length), u32(offset), u16(0),
|
||||
]);
|
||||
return Buffer.concat([...locals, cd, eocd]);
|
||||
}
|
||||
|
||||
assert.deepEqual(unzipTools("win32"), ["tar", "powershell", "node"]);
|
||||
assert.deepEqual(unzipTools("linux"), ["tar", "unzip", "python3", "bsdtar", "node"]);
|
||||
assert.deepEqual(unzipTools("darwin"), ["tar", "unzip", "python3", "bsdtar", "node"]);
|
||||
assert.equal(unzipTools("linux").includes("powershell"), false);
|
||||
assert.equal(unzipTools("darwin").includes("powershell"), false);
|
||||
|
||||
const zip = buildZip([
|
||||
{ name: "hello.txt", body: "hello", method: 0 },
|
||||
{ name: "nested/a.txt", body: "deflated-body", method: 8 },
|
||||
{ name: "dir/", body: "", method: 0 },
|
||||
]);
|
||||
assert.deepEqual(listZipEntries(zip), ["hello.txt", "nested/a.txt", "dir/"]);
|
||||
|
||||
const dest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-"));
|
||||
try {
|
||||
extractZipBuffer(zip, dest);
|
||||
assert.equal(fs.readFileSync(path.join(dest, "hello.txt"), "utf8"), "hello");
|
||||
assert.equal(fs.readFileSync(path.join(dest, "nested", "a.txt"), "utf8"), "deflated-body");
|
||||
assert.equal(fs.existsSync(path.join(dest, "..", "evil.txt")), false);
|
||||
} finally {
|
||||
fs.rmSync(dest, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
assert.throws(() => extractZipBuffer(buildZip([{ name: "../evil.txt", body: "no", method: 0 }]), dest));
|
||||
assert.equal(fs.existsSync(path.join(os.tmpdir(), "evil.txt")), false);
|
||||
|
||||
const zipPath = path.join(os.tmpdir(), `dsh-zip-src-${process.pid}.zip`);
|
||||
const viaDest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-via-"));
|
||||
const liveDest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-live-"));
|
||||
const fallbackDest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-fallback-"));
|
||||
fs.writeFileSync(zipPath, zip);
|
||||
try {
|
||||
const via = extractZipArchive(zipPath, viaDest, ["node"]);
|
||||
assert.equal(via, "node");
|
||||
assert.equal(fs.readFileSync(path.join(viaDest, "hello.txt"), "utf8"), "hello");
|
||||
const fallback = extractZipArchive(zipPath, fallbackDest, ["tar-does-not-exist", "node"]);
|
||||
assert.equal(fallback, "node");
|
||||
assert.equal(fs.readFileSync(path.join(fallbackDest, "nested", "a.txt"), "utf8"), "deflated-body");
|
||||
const live = extractZipArchive(zipPath, liveDest);
|
||||
assert.ok(["tar", "powershell", "unzip", "python3", "bsdtar", "node"].includes(live));
|
||||
console.log(`ok: zip extract via ${live} on ${process.platform}`);
|
||||
} finally {
|
||||
fs.rmSync(zipPath, { force: true });
|
||||
fs.rmSync(viaDest, { recursive: true, force: true });
|
||||
fs.rmSync(liveDest, { recursive: true, force: true });
|
||||
fs.rmSync(fallbackDest, { recursive: true, force: true });
|
||||
}
|
||||
Reference in new issue
Block a user