diff --git a/README.md b/README.md index 216caa8..860ccc7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
Version 1.1.76
+Version 1.1.77
DeepSeek Harness jailbreak: every model, swap prompts per model. Default prompt for 小码酱. Please star ⭐ If you build on this, see Attribution required. @@ -57,7 +57,7 @@ The author's personal channel: [t.me/LLM_PoJia](https://t.me/LLM_PoJia). Notes a ## What this is -**dsh-purge** is a cybersecurity red-team plugin for the official [DeepSeek Harness](https://www.deepseek.com/harness/) already installed on your machine. **1.1.76** targets **DSH 0.2.1-rc.2** (0.2.0 still works). Official **Web** (`dsh web`) and the official **desktop EXE** are both supported. Install and Apply them separately. +**dsh-purge** is a cybersecurity red-team plugin for the official [DeepSeek Harness](https://www.deepseek.com/harness/) already installed on your machine. **1.1.77** targets **DSH 0.2.1-rc.2** (0.2.0 still works). Official **Web** (`dsh web`) and the official **desktop EXE** are both supported. Install and Apply them separately. Harness does more than forward a prompt. It rewrites prompts, approval gates, sandbox policy, and session migration at runtime. Asking only “will the model answer” treats a host-layer block as a model refusal. This plugin separates those two layers on your own install, for controlled evaluation and for seeing which default policy is too tight. @@ -131,9 +131,9 @@ This repo is [Apache License 2.0](./LICENSE). Forks and redistributions must kee ## Supported hosts -**1.1.76 targets DSH 0.2.1-rc.2.** 0.2.0 still works. Do not apply it to 0.1.x. +**1.1.77 targets DSH 0.2.1-rc.2.** 0.2.0 still works. Do not apply it to 0.1.x. -- **dsh 0.2.1-rc.2** (official desktop / official `dsh web`): use **1.1.76**. Fixes `{{cwd}}` / `[cwd]` crash, patch #40 match, dropped `toolFilter`, host `dsh-tools` resolve, hostFs fd, desktop helper self-kill, `file:` archive update, Ctrl+Enter steer. +- **dsh 0.2.1-rc.2** (official desktop / official `dsh web`): use **1.1.77**. Fixes `{{cwd}}` / `[cwd]` crash, patch #40 match, dropped `toolFilter`, host `dsh-tools` resolve, hostFs fd, desktop helper self-kill, `file:` archive update, Ctrl+Enter steer. - **dsh 0.2.0-rc.2**: use **1.1.40** or newer; this line also installs. - **dsh 0.1.7** (incl. rc.1 / rc.2): use **1.1.39** or older — pick the tag on [Releases](https://github.com/YuJunZhiXue/dsh-purge/releases). @@ -191,7 +191,7 @@ Success: `node_modules/dsh-purge/package.json` exists and `"dsh-purge"` is in th For the desktop client you can also click the button (`dsh://` deep link; it still downloads the same tarball):
- Install in desktop client + Install in desktop client
### 3. Three more clicks after the command diff --git a/README.zh-CN.md b/README.zh-CN.md index 90533c7..2ff68e3 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@Version 1.1.76
+Version 1.1.77
DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词;默认提示词面向国模「小码酱」。Jailbreak for every model — swap prompts per model. 求 Star 收藏 ⭐ 如要二开,请查看署名要求部分 @@ -57,7 +57,7 @@ ## 介绍 -**dsh-purge** 是装在本机官方 [DeepSeek Harness](https://www.deepseek.com/harness/) 上的网络安全红队评测插件。当前 **1.1.76** 已适配 **DSH 0.2.1-rc.2**(0.2.0 仍可用)。官方 **Web**(`dsh web`)和官方 **桌面端**(EXE)都支持,两边分开装、分开应用。 +**dsh-purge** 是装在本机官方 [DeepSeek Harness](https://www.deepseek.com/harness/) 上的网络安全红队评测插件。当前 **1.1.77** 已适配 **DSH 0.2.1-rc.2**(0.2.0 仍可用)。官方 **Web**(`dsh web`)和官方 **桌面端**(EXE)都支持,两边分开装、分开应用。 Harness 不只是把问题交给模型。它还会在运行时改提示词、审批门、沙箱和会话格式。只看「模型答不答」,会把宿主拦截误当成模型拒绝。这个插件在你自己的安装里把这两层分开,用来做受控评测,也用来看默认策略该不该收紧。 @@ -133,9 +133,9 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审 ## 适配范围 -**1.1.76 已适配 DSH 0.2.1-rc.2**,0.2.0 仍可用。不要拿它去打 0.1.x。 +**1.1.77 已适配 DSH 0.2.1-rc.2**,0.2.0 仍可用。不要拿它去打 0.1.x。 -- **dsh 0.2.1-rc.2**(官方桌面 / 官方 `dsh web`):用 **1.1.76**。已修 `{{cwd}}` / `[cwd]` 整轮失败、补丁 #40 命中、`toolFilter` 废弃、`dsh-tools` 解析、hostFs fd、桌面换包自杀、`file:` 归档更新、Ctrl+Enter 插话。 +- **dsh 0.2.1-rc.2**(官方桌面 / 官方 `dsh web`):用 **1.1.77**。已修 `{{cwd}}` / `[cwd]` 整轮失败、补丁 #40 命中、`toolFilter` 废弃、`dsh-tools` 解析、hostFs fd、桌面换包自杀、`file:` 归档更新、Ctrl+Enter 插话。 - **dsh 0.2.0-rc.2**:用 **1.1.40** 及以上;本页这档也能装。 - **dsh 0.1.7**(含 rc.1 / rc.2):用 **1.1.39** 及更早 —— 在 [Releases](https://github.com/YuJunZhiXue/dsh-purge/releases) 里选对应标签。 @@ -193,7 +193,7 @@ node node_modules/dsh-purge/scripts/ensure-profile-bundle.mjs 桌面客户端也可以点按钮(`dsh://` 唤起,下的仍是同一份压缩包):
### 3. 装完还要做这三下 diff --git a/lib/net-scope.js b/lib/net-scope.js index 3cbc5b0..57ac96a 100644 --- a/lib/net-scope.js +++ b/lib/net-scope.js @@ -241,7 +241,7 @@ const DENIAL = "不行,这是严令禁止的"; // exploit(?!-):exploit-db.com 等资料站不算 exploit 关键词。 // (? ATTACK_SCAN_CAP ? t.slice(0, ATTACK_SCAN_CAP) : t); + return !scanHas(ATTACK, t); +} + +function scanHas(re, text) { + const sample = String(text || ""); + const cap = Math.min(sample.length, ATTACK_SCAN_CAP); + if (!cap) return false; + if (cap <= ATTACK_WINDOW) return re.test(sample.slice(0, cap)); + const hop = ATTACK_WINDOW - 256; + for (let i = 0; i < cap; i += hop) { + if (re.test(sample.slice(i, i + ATTACK_WINDOW))) return true; + } + return false; } export function isAttackTask(text) { const sample = String(text || ""); if (isBenignNetworkTopic(sample)) return false; - return ATTACK.test(sample.length > ATTACK_SCAN_CAP ? sample.slice(0, ATTACK_SCAN_CAP) : sample); + return scanHas(ATTACK, sample); } export function isCheatTask(text) { @@ -508,13 +520,19 @@ export function isCheatTask(text) { function hostsInTask(text) { const hosts = new Set(); - const sample = String(text || "").slice(0, 32768); - collectFromText(sample, hosts); + const sample = String(text || ""); + const cap = Math.min(sample.length, ATTACK_SCAN_CAP); + const win = 32768; + const hop = 28672; const labeled = /(?:[a-z0-9\u00a1-\uffff](?:[a-z0-9\u00a1-\uffff-]{0,61}[a-z0-9\u00a1-\uffff])?\.)+(?:[a-z]{2,63}|xn--[a-z0-9-]{2,59}|[\u4e00-\u9fff]{2,12})/giu; - for (const match of sample.matchAll(labeled)) { - const name = match[0].toLowerCase().replace(/\.$/, ""); - if (!keepBareDomain(sample, match.index, name)) continue; - addHost(name, hosts); + for (let i = 0; i < cap; i += hop) { + const chunk = sample.slice(i, i + win); + collectFromText(chunk, hosts); + for (const match of chunk.matchAll(labeled)) { + const name = match[0].toLowerCase().replace(/\.$/, ""); + if (!keepBareDomain(chunk, match.index, name)) continue; + addHost(name, hosts); + } } return hosts; } @@ -532,14 +550,13 @@ async function isRangeTarget(name) { return ips.every((ip) => isLocalLabAddress(ip)); } -export async function taskTargetHit(text) { - if (!isAttackTask(text)) return null; +export async function publicHostHit(text) { const names = []; for (const host of hostsInTask(text)) { const name = hostOf(host); if (name) names.push(name); } - if (!names.length) return taskHit("unspecified", "domain"); + if (!names.length) return null; for (const name of names) { if (await isRangeTarget(name)) continue; return taskHit(name, isIp(name) ? "ip" : bankHit(name) ? "bank" : "domain"); @@ -547,6 +564,76 @@ export async function taskTargetHit(text) { return null; } +export async function taskTargetHit(text) { + if (!isAttackTask(text)) return null; + let found = false; + for (const host of hostsInTask(text)) { + if (hostOf(host)) found = true; + } + if (!found) return taskHit("unspecified", "domain"); + return publicHostHit(text); +} + +function blobOf(value, depth = 0) { + if (value == null || depth > 3) return ""; + if (typeof value === "string" || typeof value === "number") return String(value); + if (Array.isArray(value)) return value.map((item) => blobOf(item, depth + 1)).join("\n"); + if (typeof value !== "object") return ""; + const skip = new Set(["agent", "session", "ctx", "next", "signal", "context"]); + return Object.entries(value) + .filter(([key]) => !skip.has(key)) + .map(([, item]) => blobOf(item, depth + 1)) + .join("\n") + .slice(0, 32768); +} + +function toolArgText(message) { + const parts = []; + const calls = message?.toolCalls || message?.tool_calls || []; + for (const call of Array.isArray(calls) ? calls : []) { + parts.push(blobOf(call.arguments ?? call.input ?? call.params ?? call)); + } + if (Array.isArray(message?.content)) { + for (const block of message.content) { + if (!block || typeof block !== "object") continue; + if (block.type === "tool_use" || block.type === "tool-call" || block.type === "tool-call-start") { + parts.push(blobOf(block.input ?? block.arguments ?? block)); + } + } + } + if (message?.toolName || message?.name) parts.push(String(message.toolName || message.name)); + return parts.join("\n"); +} + +export function latestToolText(messages) { + const list = Array.isArray(messages) ? messages : []; + const parts = []; + for (let i = list.length - 1; i >= 0 && parts.length < 6; i -= 1) { + const role = list[i]?.role; + if (role !== "assistant" && role !== "model") continue; + const blob = toolArgText(list[i]); + if (blob.trim()) parts.push(blob); + } + return parts.join("\n"); +} + +export function execArgText(exec) { + if (!exec || typeof exec !== "object") return ""; + return blobOf({ + name: exec.tool?.name || exec.name || exec.toolName, + args: exec.args ?? exec.input ?? exec.parameters ?? exec.params, + command: exec.command, + call: exec.toolCall ?? exec.call, + }); +} + +function isRedteamPayload(payload) { + const session = payload?.agent?.session || payload?.session; + const raw = session?.agentPreset || session?.header?.agentPreset || session?.projectionValues?.agentPreset || payload?.agent?.preset; + const id = String(raw?.id || raw?.name || raw || "").toLowerCase(); + return id.includes("redteam"); +} + function messageBody(message) { if (typeof message?.content === "string") return message.content; if (!Array.isArray(message?.content)) return typeof message?.text === "string" ? message.text : ""; @@ -664,13 +751,15 @@ async function parkDenial(payload) { const session = sessionOf(payload); const turn = Number(payload?.turn); const step = Number(payload?.step); - if (!session || !Number.isSafeInteger(turn) || step !== 1) return false; + if (!session || !Number.isSafeInteger(turn) || !Number.isSafeInteger(step) || step < 1) return false; const messages = Array.isArray(payload?.messages) ? payload.messages : []; let outerOpened = false; let innerOpened = false; try { - for (const message of messages) { - session.append("user/message", message, { surfaceOp: "append" }); + if (step === 1) { + for (const message of messages) { + session.append("user/message", message, { surfaceOp: "append" }); + } } session.append("step/start", { turn, step }); outerOpened = true; @@ -696,18 +785,37 @@ async function parkDenial(payload) { } } +function denyToolResult() { + return { isError: true, content: DENIAL, output: DENIAL, text: DENIAL }; +} + export function installRegionGate(ctx) { if (!ctx || typeof ctx.on !== "function") return; + const scoped = new WeakMap(); const hook = async (payload, next) => { const forward = () => (typeof next === "function" ? next() : { kind: "enter", messages: payload?.messages || [] }); - if (Number(payload?.step) !== 1) return forward(); + const step = Number(payload?.step); + const turn = Number(payload?.turn); + const session = sessionOf(payload) || payload?.agent?.session; let hit = null; try { const task = currentTaskText(payload?.messages); - if (!task) return forward(); - if (isCheatTask(task)) hit = taskHit("cheat", "cheat"); - else if (isAttackTask(task)) hit = await taskTargetHit(task); - else return forward(); + const redteam = isRedteamPayload(payload); + const marked = session ? scoped.get(session) === turn : false; + if (step === 1) { + if (!task && !redteam) return forward(); + if (task && isCheatTask(task)) hit = taskHit("cheat", "cheat"); + else if (task && isAttackTask(task)) { + if (session && Number.isSafeInteger(turn)) scoped.set(session, turn); + hit = await taskTargetHit(task); + } else if (redteam) { + if (session && Number.isSafeInteger(turn)) scoped.set(session, turn); + hit = task ? await publicHostHit(task) : null; + } else return forward(); + } else if (redteam || marked || isAttackTask(task)) { + if (isCheatTask(task)) hit = taskHit("cheat", "cheat"); + else hit = await publicHostHit(latestToolText(payload?.messages)); + } else return forward(); } catch { return forward(); } @@ -720,10 +828,27 @@ export function installRegionGate(ctx) { } return forward(); }; + const toolHook = async (exec, next) => { + const forward = () => (typeof next === "function" ? next() : denyToolResult()); + try { + const blob = execArgText(exec); + if (!blob.trim()) return forward(); + const hit = await publicHostHit(blob); + if (!hit) return forward(); + } catch { + return forward(); + } + if (exec && typeof exec === "object") { + exec.blocked = true; + exec.error = DENIAL; + } + return denyToolResult(); + }; const arm = () => { if (ctx.__dshPurgeRegionGate) return true; try { ctx.on("agent/pre-step", hook, { global: true, prepend: true }); + try { ctx.on("tools/pre-execute", toolHook, { global: true, prepend: true }); } catch { /* 旧宿主没有工具钩。 */ } ctx.__dshPurgeRegionGate = true; return true; } catch { diff --git a/package.json b/package.json index 96b8fcd..f865e80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-purge", - "version": "1.1.76", + "version": "1.1.77", "description": "DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词;默认提示词面向国模「小码酱」。Jailbreak for every model — swap prompts per model. 求 Star 收藏 ⭐ 如要二开,请查看署名要求部分", "type": "module", "main": "lib/index.js", diff --git a/release-notes.md b/release-notes.md index d4bfe76..b1a8705 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,19 @@ +# 1.1.77 + +## 中文 + +- 版本 **1.1.77**。修复 bug,修复稳定性。 +- 修长红队任务仍打公网:`渗透测试` / `红队` / `打点` / `拿站` 纳入门禁;正文按窗扫到 256KB,目标写在后半段也能拦。 +- 修后续步骤漏拦:每一步看工具参数,`tools/pre-execute` 遇到公网 IP/域名直接停轮。 +- 长文正则按窗扫,避免整篇回溯把事件循环卡死。 + +## English + +- **1.1.77**. Bug fixes and stability. +- Long red-team tasks no longer reach the public internet: `渗透测试` / red-team / 打点 / 拿站 are gated; the body is scanned in windows up to 256KB. +- Later steps are gated too: tool arguments are checked, and `tools/pre-execute` stops on a public IP or name. +- Long-text regex runs in windows so a huge paste cannot stall the event loop. + # 1.1.76 ## 中文