mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 14:40:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77d61804c8 | ||
|
|
7a78399e0b | ||
|
|
fefae8764c | ||
|
|
7dd16def6d | ||
|
|
1b0a2391ca | ||
|
|
67f1325d89 | ||
|
|
5fa04372cc | ||
|
|
b57944042b | ||
|
|
8b6f3608fb |
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.73</strong></p>
|
||||
<p align="center"><strong>Version 1.1.78</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>DeepSeek Harness jailbreak: every model, swap prompts per model. Default prompt for 小码酱. Please star ⭐ If you build on this, see Attribution required.</em>
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
People have been selling this open-source work in the open. After that, the author was asked to come in and talk. No need to spell out the rest. Read between the lines.
|
||||
|
||||
From now on the **public internet is closed**. The open-source build only allows **local lab** targets: localhost, private nets, and local suffixes such as `.lab` / `.lan` / `.htb`. A public IP, a public domain, an online range, or a registered public host does not pass. This build does not ship the skill library or the knowledge base.
|
||||
From now on the **public internet is closed**. The open-source build only allows **local lab IPs**: loopback and RFC1918. Domains are resolved first (including hosts); every answer must be private or loopback. A hosts trick that points `.lab` at a public IP, a failed lookup, or a mixed public answer is blocked. **Game cheats are forbidden** (aimbot, wallhack, memory edits against a game, anti-cheat bypass); the prompt and the session gate both stop them. This build does not ship the skill library or the knowledge base.
|
||||
|
||||
**The original build may not be resold.** Charging for it, skinning it, or hawking it in groups is not allowed. Forks are fine, but **you must attribute** and name the source: [YuJunZhiXue/dsh-purge](https://github.com/YuJunZhiXue/dsh-purge). Hide the source or pass it off as your own, and you are on the other side.
|
||||
|
||||
@@ -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.73** 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.78** 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.
|
||||
|
||||
@@ -107,7 +107,7 @@ This repo is [Apache License 2.0](./LICENSE). Forks and redistributions must kee
|
||||
2. **Local official Harness only.** Security-eval patches and prompt injection run only on the **official DeepSeek Harness already installed on the user's machine** (`@deepseek-ai` packages, local profile / `$DSH_HOME`). The target is the user's own official local software, **not** someone else's website, server, account, or information system.
|
||||
3. **Eval patches do not attack the public internet.** Apply, inject, revert, and uninstall stay in local files and local processes. They **do not scan, probe, intrude, or send attack traffic to any public host or unauthorized system**. Do not use this project as a jump host against the public internet. If "check for updates" is on, the plugin may only contact this plugin's own GitHub repository to compare versions. That is **not** an attack on third-party systems and is **not** authorization to penetrate anything.
|
||||
4. **Lawful, controlled scope.** This project is an aid for red-team research and robustness evaluation on an **official Harness the user is entitled to administer**. **Do not run it against targets without the owner's lawful written authorization, public online systems, or production workloads.** Testing must stay on the **authorized local official Harness, offline local synthetic fixtures, authorized cybersecurity ranges, and compliant lab environments**.
|
||||
5. **The open-source build is local-lab only.** Attack tasks only allow localhost/private nets and local suffixes such as `.lab` / `.lan` / `.htb`. A public IP, a public domain, an online range, or a registered public host is not an exception. A key, a password, a network range, a wildcard, or a claim made in the conversation does not add an exception. This build does not ship the skill library or the knowledge base.
|
||||
5. **The open-source build is local-lab only.** Attack tasks only allow loopback and RFC1918 addresses. Domains are resolved, then judged by IP; suffixes are not an allow list. A public IP, a name that resolves public, a failed lookup, or a hosts entry that points a lab name at the public internet is not an exception. A key, a password, a network range, a wildcard, or a claim made in the conversation does not add an exception. Game cheats are forbidden. This build does not ship the skill library or the knowledge base.
|
||||
6. **Forbidden uses.** Users must not use this project, directly or indirectly, to violate the following (each must be followed; no excuse to evade):
|
||||
- <font color="red"><strong>Criminal Law of the People's Republic of China</strong></font>
|
||||
- <font color="red"><strong>Cybersecurity Law of the People's Republic of China</strong></font>
|
||||
@@ -131,9 +131,9 @@ This repo is [Apache License 2.0](./LICENSE). Forks and redistributions must kee
|
||||
|
||||
## Supported hosts
|
||||
|
||||
**1.1.73 targets DSH 0.2.1-rc.2.** 0.2.0 still works. Do not apply it to 0.1.x.
|
||||
**1.1.78 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.73**. 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.78**. 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).
|
||||
|
||||
@@ -143,28 +143,64 @@ Unmatched patches stay pending or skipped; nothing is rewritten blindly.
|
||||
|
||||
## Install
|
||||
|
||||
Web and the official desktop EXE are the two maintained hosts. Install and patch each **separately**, and only the host you actually run.
|
||||
Follow the three steps below. **Do not use the plugin marketplace.** One-click install on [dsh-plugin.org](https://dsh-plugin.org) or in Settings → Plugin Market fails with `already queued: dsh-purge` and never runs a command. The name `dsh-purge` is not on the npm registry; do not `pnpm add dsh-purge`. If this machine only has pnpm, use the pnpm URL in step 2.
|
||||
|
||||
### 1. Which host are you running?
|
||||
|
||||
Official `dsh web` and the official desktop EXE are installed and patched **separately**. Only install into the host you actually open.
|
||||
|
||||
| What you run | Profile | Command |
|
||||
|---|---|---|
|
||||
| Official `dsh web` | `web` | `dsh plugin --profile web add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` |
|
||||
| Official desktop EXE | `desktop` | `dsh plugin --profile desktop add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` |
|
||||
| Official `dsh web` | `web` | First command below |
|
||||
| Official desktop EXE | `desktop` | Second command below |
|
||||
|
||||
If this directory is already a clone, use `add .` instead of the URL. If `dsh` is not on PATH, use [Manual install](#manual). There is no npm package; do not `pnpm add dsh-purge`.
|
||||
### 2. Add it to the profile (`dsh` or pnpm-only)
|
||||
|
||||
For the desktop client you can also click the button (`dsh://` deep link):
|
||||
Use `codeload.github.com`. Do not use `github.com/.../archive`: that 302 makes pnpm fail with `fetch failed`.
|
||||
|
||||
**If you have `dsh`:**
|
||||
|
||||
```sh
|
||||
dsh plugin --profile web add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
Use `desktop` instead of `web` for the EXE. If this directory is already a clone, use `.` instead of the URL.
|
||||
|
||||
**pnpm only (no `dsh` required):** run this inside the profile you actually use, not the repo root.
|
||||
|
||||
```sh
|
||||
cd "$DSH_HOME/profiles/web" # desktop: profiles/desktop
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
Windows PowerShell:
|
||||
|
||||
```powershell
|
||||
cd "$env:USERPROFILE\.dsh\profiles\web" # desktop: profiles\desktop
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
`pnpm add` fetches the package; `postinstall` writes `dsh-purge` into `dsh.profile.bundles`. If you passed `--ignore-scripts`, run:
|
||||
|
||||
```sh
|
||||
node node_modules/dsh-purge/scripts/ensure-profile-bundle.mjs
|
||||
```
|
||||
|
||||
Success: `node_modules/dsh-purge/package.json` exists and `"dsh-purge"` is in that profile's `bundles`. If neither `dsh` nor pnpm is available, use [Manual install](#manual).
|
||||
|
||||
For the desktop client you can also click the button (`dsh://` deep link; it still downloads the same tarball):
|
||||
|
||||
<p align="center">
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.73&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz"><strong>Install in desktop client</strong></a>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.78&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fcodeload.github.com%2FYuJunZhiXue%2Fdsh-purge%2Ftar.gz%2Frefs%2Fheads%2Fmaster"><strong>Install in desktop client</strong></a>
|
||||
</p>
|
||||
|
||||
### After the command: three steps
|
||||
### 3. Three more clicks after the command
|
||||
|
||||
Adding the plugin to a profile does **not** patch `@deepseek-ai` by itself.
|
||||
|
||||
1. **Quit and reopen** the host you installed into — stop and restart `dsh web`, or quit the desktop tray and reopen that app.
|
||||
2. On **that host**, click **dsh-purge** beside the session title, then **Apply** on the **Clean** page. It is not on the host Settings page.
|
||||
3. A successful **Apply** restarts once so patches load. It does not restart if it did not finish.
|
||||
1. **Fully quit and reopen** the host you just installed into. Web: stop `dsh web` and start it again. Desktop: quit the tray icon too, then open the exe.
|
||||
2. On **that host**, click **dsh-purge** beside the session title, open **Clean**, and click **Apply**. It is not on the host Settings page.
|
||||
3. A successful **Apply** restarts once. It does not restart if it did not finish.
|
||||
|
||||
Web controls affect Web only; desktop controls affect the desktop app only. Do not Apply one host from the other.
|
||||
|
||||
@@ -174,6 +210,25 @@ Web controls affect Web only; desktop controls affect the desktop app only. Do n
|
||||
- `/purge status` in chat prints `DSH_HOME` and the patch list — the path should be the home you actually run.
|
||||
- Optional packages that are not installed (liangshen) show as skipped and do not block Apply.
|
||||
|
||||
### If the market says `already queued: dsh-purge`
|
||||
|
||||
Stop clicking the market. Use `dsh plugin add` or pnpm from step 2 again. If the CLI also says it is already there:
|
||||
|
||||
```sh
|
||||
dsh plugin --profile desktop remove dsh-purge
|
||||
dsh plugin --profile desktop add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
pnpm only:
|
||||
|
||||
```sh
|
||||
cd "$DSH_HOME/profiles/desktop"
|
||||
pnpm remove dsh-purge
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
Swap `desktop` for `web` on Web. Then do step 3.
|
||||
|
||||
### Hand this to an assistant
|
||||
|
||||
Paste the block below to a local assistant. It should only run the install command — no disk scan, no other edits, no Apply, no restart.
|
||||
@@ -183,17 +238,23 @@ Paste the block below to a local assistant. It should only run the install comma
|
||||
|
||||
<!-- AI-AGENT-START -->
|
||||
|
||||
Install the DeepSeek Harness plugin `dsh-purge` into the Web profile only. Do not scan the whole disk, do not read or edit other files, do not apply settings, and do not restart the app. Do not install into the desktop profile.
|
||||
Install the DeepSeek Harness plugin `dsh-purge` into the Web profile only. Do not scan the whole disk, do not read or edit other files, do not apply settings, and do not restart the app. Do not install into the desktop profile. Do not use the plugin marketplace. The name is not on the npm registry; do not `pnpm add dsh-purge`.
|
||||
|
||||
**Web (official `dsh web`)**
|
||||
|
||||
If `dsh` is not on PATH, tell the user and stop.
|
||||
If `dsh` is on PATH:
|
||||
|
||||
```sh
|
||||
dsh plugin --profile web add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz
|
||||
dsh plugin --profile web add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
If this directory is already a clone, use `dsh plugin --profile web add .`. There is no npm package; do not `pnpm add dsh-purge`.
|
||||
If `dsh` is missing and pnpm is available, `cd` into `$DSH_HOME/profiles/web` (often `~/.dsh/profiles/web`) and run:
|
||||
|
||||
```sh
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
If this directory is already a clone and `dsh` exists, use `dsh plugin --profile web add .`. If neither `dsh` nor pnpm is available, tell the user and stop.
|
||||
|
||||
After the command finishes, tell the user to fully quit and restart `dsh web`, then open **dsh-purge** beside the session title and **Apply** on **Clean**. Then stop.
|
||||
|
||||
@@ -277,7 +338,7 @@ Success: `profiles/<web|desktop>/node_modules/dsh-purge/package.json` exists. If
|
||||
|
||||
### Uninstall
|
||||
|
||||
**dsh-purge** beside the session title → **Clean** → **Uninstall**. Confirm the dialog: it reverts any applied patches, restores the original Harness, and restarts the current host.
|
||||
**dsh-purge** beside the session title → **Clean** → **Uninstall**. Confirm the dialog: it reverts any applied patches, restores the original Harness, and restarts the current host. Disable or uninstall also resets an agent-preset default that still points at `redteam` back to `standard`, so the host can create sessions after the preset is gone.
|
||||
|
||||
```sh
|
||||
# or from a terminal / chat
|
||||
@@ -336,7 +397,7 @@ The open-source build only allows localhost/private nets. The Clean page says so
|
||||
| Drill | assets and environment after authorization. This build does not ship skills or the knowledge base. The tab says Unauthorized until then |
|
||||
| Patches | grouped status, Apply, Restore, or Uninstall |
|
||||
| Prompt | edit `prompt-inject.md` as the session override |
|
||||
| Local lab | localhost/private nets and local suffixes such as `.lab` / `.lan` / `.htb` only |
|
||||
| Local lab | loopback / RFC1918 only; names are resolved, and every address must be private |
|
||||
| Rule sets | multiple `AGENTS.md` / `CLAUDE.md`; Enable writes under `$DSH_HOME`, Delete removes the row |
|
||||
|
||||
---
|
||||
@@ -399,7 +460,7 @@ Restart `dsh web` to load the profile. The model and reasoning defaults apply to
|
||||
|
||||
### Local lab
|
||||
|
||||
Attack tasks are denied by default. The open-source build only allows localhost/private local labs. Saying “this is my server” in chat does not allow it. Registering a public IP or domain does not allow it either.
|
||||
Attack tasks are denied by default. The open-source build only allows loopback and RFC1918 IPs. Names are resolved first; a `.lab` / `.htb` suffix is not enough. A hosts entry that points a lab name at a public IP is blocked. Saying “this is my server” in chat does not allow it.
|
||||
|
||||
---
|
||||
|
||||
@@ -512,7 +573,7 @@ The author's personal channel: [t.me/LLM_PoJia](https://t.me/LLM_PoJia). Notes a
|
||||
- Scope is rendered copy, defaults, and runtime logic inside local `@deepseek-ai/*` packages, plus override files and rule sets under the harness home.
|
||||
- After an upgrade, unmatched originals show as skipped. Apply still completes, and those files are left unchanged.
|
||||
- Third-party plugin *source repos* outside `@deepseek-ai` are left alone (CMD silence may **best-effort** patch installed doctor / market / liangshen / mnemon at runtime).
|
||||
- Install from the GitHub archive (there is no npm package): `dsh plugin --profile web add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` (use profile `desktop` for the EXE). From this repo, `add .`.
|
||||
- Install from the GitHub tarball (the name is not on npm; skip the plugin market). With `dsh`: `dsh plugin --profile web add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master`. pnpm only: `pnpm add` that URL inside `$DSH_HOME/profiles/web`. Use `desktop` for the EXE. From this repo, `add .`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
+90
-29
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.73</strong></p>
|
||||
<p align="center"><strong>Version 1.1.78</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词;默认提示词面向国模「小码酱」。Jailbreak for every model — swap prompts per model. 求 Star 收藏 ⭐ 如要二开,请查看署名要求部分</em>
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
市面上有人把这份开源明目张胆挂出去卖。后面作者这边被找去谈过话——经过不必写,你们自己品。
|
||||
|
||||
从今往后,**公网一律不许碰**。开源版攻击任务只认**本地靶场**:本机、内网,以及 `.lab` / `.lan` / `.htb` 这类本机实验室后缀。公网 IP、域名、网上演练平台、自己登记的公网机器,一个都不放。不是本地靶场就别跑,也跑不过去。开源版不下发技能库和知识库。
|
||||
从今往后,**公网一律不许碰**。开源版攻击任务只认**本地靶场 IP**:本机回环和 RFC1918 私网。域名会先按系统解析(含 hosts),解析到的每一个地址都必须是私网或回环;hosts 把 `.lab` 指到公网、解析失败、混有公网地址,一律拦。不是本地靶场就别跑,也跑不过去。**禁止制作外挂**(自瞄、透视、改内存打游戏、过反作弊),提示词和会话门口一起拦。开源版不下发技能库和知识库。
|
||||
|
||||
**原版不允许倒卖。** 收费、当货挂群,一律不行。二开可以,但**必须署名**,写明来源仓库:[YuJunZhiXue/dsh-purge](https://github.com/YuJunZhiXue/dsh-purge)。不署名、隐瞒来源、改头换面据为己有,作者一律当对家。
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
## 介绍
|
||||
|
||||
**dsh-purge** 是装在本机官方 [DeepSeek Harness](https://www.deepseek.com/harness/) 上的网络安全红队评测插件。当前 **1.1.73** 已适配 **DSH 0.2.1-rc.2**(0.2.0 仍可用)。官方 **Web**(`dsh web`)和官方 **桌面端**(EXE)都支持,两边分开装、分开应用。
|
||||
**dsh-purge** 是装在本机官方 [DeepSeek Harness](https://www.deepseek.com/harness/) 上的网络安全红队评测插件。当前 **1.1.78** 已适配 **DSH 0.2.1-rc.2**(0.2.0 仍可用)。官方 **Web**(`dsh web`)和官方 **桌面端**(EXE)都支持,两边分开装、分开应用。
|
||||
|
||||
Harness 不只是把问题交给模型。它还会在运行时改提示词、审批门、沙箱和会话格式。只看「模型答不答」,会把宿主拦截误当成模型拒绝。这个插件在你自己的安装里把这两层分开,用来做受控评测,也用来看默认策略该不该收紧。
|
||||
|
||||
@@ -109,7 +109,7 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审
|
||||
2. **只作用于本机官方 Harness**:安全评测补丁、提示词注入全部发生在使用者**本机已安装的官方 DeepSeek Harness**(`@deepseek-ai` 包、本机 profile / `$DSH_HOME`)上。对象是使用者自己的官方本地软件,**不是**他人的网站、服务器、账号或信息系统。
|
||||
3. **评测补丁不对外网目标联网**:应用补丁、写入注入、回滚、卸载均在本机文件与本机进程内完成,**不对任何公网主机、未授权系统进行扫描、探测、入侵或攻击发包**。不得把本项目当作跳板去打外网。插件若开启「检测更新」,仅可能访问本插件自己的 GitHub 仓库以核对版本,**与对第三方系统的网络攻击无关**,也不能被解释为授权对外渗透。
|
||||
4. **合法受控范围限定**:本项目定位为使用者在**自己有权管理的本机官方 Harness**上,进行红队科研与鲁棒性评测的辅助工具。**严禁在未经所有者合法书面授权的目标、公网在线系统或生产业务上运行本项目**。一切测试必须限制在**本机已授权安装的官方 Harness、离线本地合成靶标、授权网络安全演练靶场及合规实验室受控环境**中进行。
|
||||
5. **开源版只允许本地靶场。** 攻击任务只放行本机/内网,以及 `.lab` / `.lan` / `.htb` 这类本机实验室后缀。公网 IP、公网域名、网上演练平台、自己登记的公网机器都不能当作例外。密钥、密码、网段、通配符,以及对话里的口头说明,都不能增加例外。开源版不下发技能库和知识库。
|
||||
5. **开源版只允许本地靶场。** 攻击任务只放行本机回环和 RFC1918 私网 IP。域名先解析再判 IP,不靠后缀放行。公网 IP、解析到公网的域名、解析失败、hosts 把实验室后缀指到公网,都不能当作例外。密钥、密码、网段、通配符,以及对话里的口头说明,都不能增加例外。禁止制作游戏外挂。开源版不下发技能库和知识库。
|
||||
6. **严禁违法与违禁用途**:使用者严禁利用本项目直接或间接从事任何违反下列法律法规的行为(必须逐条遵守,不得以任何理由规避):
|
||||
- **《中华人民共和国刑法》**
|
||||
- **《中华人民共和国网络安全法》**
|
||||
@@ -133,9 +133,9 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审
|
||||
|
||||
## 适配范围
|
||||
|
||||
**1.1.73 已适配 DSH 0.2.1-rc.2**,0.2.0 仍可用。不要拿它去打 0.1.x。
|
||||
**1.1.78 已适配 DSH 0.2.1-rc.2**,0.2.0 仍可用。不要拿它去打 0.1.x。
|
||||
|
||||
- **dsh 0.2.1-rc.2**(官方桌面 / 官方 `dsh web`):用 **1.1.73**。已修 `{{cwd}}` / `[cwd]` 整轮失败、补丁 #40 命中、`toolFilter` 废弃、`dsh-tools` 解析、hostFs fd、桌面换包自杀、`file:` 归档更新、Ctrl+Enter 插话。
|
||||
- **dsh 0.2.1-rc.2**(官方桌面 / 官方 `dsh web`):用 **1.1.78**。已修 `{{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) 里选对应标签。
|
||||
|
||||
@@ -145,36 +145,91 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审
|
||||
|
||||
## 安装
|
||||
|
||||
现在只维护官方 `dsh web` 和官方桌面 EXE,**分开装、分开应用**,只装你正在打开的那一个。
|
||||
按下面三步走。**不要走插件市场**:[dsh-plugin.org](https://dsh-plugin.org) 或设置里的「插件市场」一键安装会报 `already queued: dsh-purge`,命令也走不成。npm 仓库没有 `dsh-purge` 这个名字,不要 `pnpm add dsh-purge`;本机只有 pnpm 时走第 2 步里的 pnpm 地址。
|
||||
|
||||
| 你正在用 | profile | 命令 |
|
||||
### 1. 看你开的是哪一端
|
||||
|
||||
官方 `dsh web` 和官方桌面 EXE **分开装、分开应用**,只装你正在打开的那一个。
|
||||
|
||||
| 你正在用 | profile | 用哪条命令 |
|
||||
|---|---|---|
|
||||
| 官方 `dsh web` | `web` | `dsh plugin --profile web add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` |
|
||||
| 官方桌面 EXE | `desktop` | `dsh plugin --profile desktop add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` |
|
||||
| 官方 `dsh web` | `web` | 下面第一条 |
|
||||
| 官方桌面 EXE | `desktop` | 下面第二条 |
|
||||
|
||||
当前目录已经是本仓库时,把 URL 换成 `add .`。`dsh` 不在 PATH 时走 [手动安装](#manual)。没有 npm 包,不要 `pnpm add dsh-purge`。
|
||||
### 2. 装进 profile(有 `dsh` 或只有 pnpm,走一条)
|
||||
|
||||
桌面客户端也可以点按钮(`dsh://` 唤起):
|
||||
压缩包走 `codeload.github.com`,不要用 `github.com/.../archive`:后者 302,pnpm 会 `fetch failed`。
|
||||
|
||||
**有 `dsh`:**
|
||||
|
||||
```sh
|
||||
dsh plugin --profile web add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
桌面把 `web` 换成 `desktop`。当前目录已是本仓库时,把网址换成 `.`。
|
||||
|
||||
**只有 pnpm(没有 `dsh` 也行):** 进正在用的那个 profile,不要在仓库根执行。
|
||||
|
||||
```sh
|
||||
cd "$DSH_HOME/profiles/web" # 桌面改 profiles/desktop
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
Windows PowerShell:
|
||||
|
||||
```powershell
|
||||
cd "$env:USERPROFILE\.dsh\profiles\web" # 桌面改 profiles\desktop
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
`pnpm add` 会拉包;`postinstall` 再把 `dsh-purge` 写进 `dsh.profile.bundles`。若加了 `--ignore-scripts`,再跑:
|
||||
|
||||
```sh
|
||||
node node_modules/dsh-purge/scripts/ensure-profile-bundle.mjs
|
||||
```
|
||||
|
||||
成功标志:`node_modules/dsh-purge/package.json` 在,且 profile 的 `bundles` 里有 `"dsh-purge"`。`dsh` 和 pnpm 都没有时走 [手动安装](#manual)。
|
||||
|
||||
桌面客户端也可以点按钮(`dsh://` 唤起,下的仍是同一份压缩包):
|
||||
|
||||
<p align="center">
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.73&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz"><strong>唤起客户端一键安装</strong></a>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.78&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fcodeload.github.com%2FYuJunZhiXue%2Fdsh-purge%2Ftar.gz%2Frefs%2Fheads%2Fmaster"><strong>唤起客户端一键安装</strong></a>
|
||||
</p>
|
||||
|
||||
### 装完都要做这三步
|
||||
### 3. 装完还要做这三下
|
||||
|
||||
只把插件写进 profile **还不会**改 `@deepseek-ai`。
|
||||
|
||||
1. **退出并重新打开**刚装的那个宿主:Web 关掉 `dsh web` 再开;桌面端退出托盘再打开对应 exe。
|
||||
2. 在**这个宿主**点会话标题旁的 **dsh-purge**,在 **清洗** 页点 **「应用」**。宿主的设置页里没有这个条目。
|
||||
3. 「应用」成功后会自动重启一次,让补丁进入当前进程。没做完不会重启。
|
||||
1. **完全退出再打开**刚装的那个宿主。Web:停掉 `dsh web` 再开。桌面:托盘也要退出,再开 exe。
|
||||
2. 在**这个宿主**点会话标题旁的 **dsh-purge**,打开 **清洗**,点 **「应用」**。宿主自己的设置页里没有这一项。
|
||||
3. 「应用」成功后会自动重启一次。没做完不会重启。
|
||||
|
||||
Web 的控件只动 Web,桌面端的只动桌面应用。不要在一个宿主里点另一个宿主的应用。
|
||||
Web 的按钮只动 Web,桌面的只动桌面。不要在一个里面点另一个的应用。
|
||||
|
||||
### 怎样算装上了
|
||||
|
||||
- 会话标题旁有 **dsh-purge**,点开后在「清洗」里能点「应用」。
|
||||
- 聊天里 `/purge status` 能打出 `DSH_HOME` 和补丁列表,路径应是你正在用的那一份。
|
||||
- 没装的可选包(例如梁神)显示跳过,不挡住应用完成。
|
||||
- 会话标题旁有 **dsh-purge**,清洗页能点「应用」。
|
||||
- 聊天里 `/purge status` 能打出 `DSH_HOME` 和补丁列表,路径是你正在用的那一份。
|
||||
- 没装的可选包(例如梁神)显示跳过,不挡住完成。
|
||||
|
||||
### 市场报 `already queued: dsh-purge` 时
|
||||
|
||||
不要再点市场。按第 2 步用 `dsh plugin add` 或 pnpm 再装一遍。命令也说已经有了,就先卸再装:
|
||||
|
||||
```sh
|
||||
dsh plugin --profile desktop remove dsh-purge
|
||||
dsh plugin --profile desktop add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
只有 pnpm 时:
|
||||
|
||||
```sh
|
||||
cd "$DSH_HOME/profiles/desktop"
|
||||
pnpm remove dsh-purge
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
Web 把 `desktop` 换成 `web`。然后再走第 3 步。
|
||||
|
||||
### 交给助手安装
|
||||
|
||||
@@ -185,17 +240,23 @@ Web 的控件只动 Web,桌面端的只动桌面应用。不要在一个宿主
|
||||
|
||||
<!-- AI-AGENT-START -->
|
||||
|
||||
安装 DeepSeek Harness 插件 `dsh-purge`,只装到 Web profile。不要全盘搜索,不要读或改其它文件,不要应用设置,也不要重启应用。不要装到桌面 profile。
|
||||
安装 DeepSeek Harness 插件 `dsh-purge`,只装到 Web profile。不要全盘搜索,不要读或改其它文件,不要应用设置,也不要重启应用。不要装到桌面 profile。不要走插件市场。npm 仓库没有这个包名,不要 `pnpm add dsh-purge`。
|
||||
|
||||
**Web 端(官方 `dsh web`)**
|
||||
|
||||
`dsh` 不在 PATH 就告诉用户后停止。
|
||||
有 `dsh`:
|
||||
|
||||
```sh
|
||||
dsh plugin --profile web add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz
|
||||
dsh plugin --profile web add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
当前目录已是本仓库时改用 `dsh plugin --profile web add .`。没有 npm 包,不要 `pnpm add dsh-purge`。
|
||||
没有 `dsh`、只有 pnpm:找到 `$DSH_HOME/profiles/web`(常见 `~/.dsh/profiles/web`),在该目录执行:
|
||||
|
||||
```sh
|
||||
pnpm add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master
|
||||
```
|
||||
|
||||
当前目录已是本仓库且有 `dsh` 时改用 `dsh plugin --profile web add .`。`dsh` 和 pnpm 都没有再告诉用户后停止。
|
||||
|
||||
命令结束后,提醒用户:完全退出并重启 `dsh web`,再点会话标题旁的 **dsh-purge**,在「清洗」里点「应用」。然后停止。
|
||||
|
||||
@@ -279,7 +340,7 @@ pnpm install
|
||||
|
||||
### 卸载
|
||||
|
||||
会话标题旁的 **dsh-purge** →「清洗」→「卸载」。弹窗确认:会先还原已应用的补丁,还原回原版 Harness,再重启当前宿主。
|
||||
会话标题旁的 **dsh-purge** →「清洗」→「卸载」。弹窗确认:会先还原已应用的补丁,还原回原版 Harness,再重启当前宿主。停用或卸载时会把「智能体预设」里指向红队模式的默认值改回 `standard`,避免宿主因找不到 `redteam` 而无法新建会话。
|
||||
|
||||
```sh
|
||||
# 也可以用命令行 / 聊天
|
||||
@@ -343,7 +404,7 @@ dsh-purge --uninstall
|
||||
| 演练台 | 授权后的资产与环境页。开源版不下发技能库和知识库。未授权时按钮标「未授权」 |
|
||||
| 补丁 | 分组查看状态,应用、还原或卸载 |
|
||||
| 提示词 | 编辑 `prompt-inject.md`,作为会话覆盖段 |
|
||||
| 本地靶场 | 只放行本机/内网和 `.lab` / `.lan` / `.htb` 等本机实验室后缀,不能登记公网主机 |
|
||||
| 本地靶场 | 只放行本机/私网 IP;域名先解析,全部地址都必须是私网或回环 |
|
||||
| 规则集 | 多套 `AGENTS.md` / `CLAUDE.md`;启用写入 `$DSH_HOME`,删除从列表去掉 |
|
||||
|
||||
|
||||
@@ -410,7 +471,7 @@ DSH 会按顺序执行同一批中的 Bash 调用。旧版 dsh-purge 把默认
|
||||
|
||||
### 本地靶场
|
||||
|
||||
开源版攻击任务默认全拦,只放行本机/内网本地靶场。在对话里说「这是我的服务器」不会放行。登记公网 IP 或域名也不会。
|
||||
开源版攻击任务默认全拦,只放行本机/私网 IP。域名先解析再判,不认 `.lab` / `.htb` 这类后缀本身。hosts 把实验室名指到公网 IP 也会拦。在对话里说「这是我的服务器」不会放行。
|
||||
|
||||
---
|
||||
|
||||
@@ -521,7 +582,7 @@ flowchart TD
|
||||
- 改动范围是本机 `@deepseek-ai/*` 包里的渲染文案、默认策略和执行逻辑,以及用户目录下的覆盖文件与规则集。
|
||||
- 升级后原文对不上会显示跳过,这次应用仍算完成,不会乱改。
|
||||
- 不改动非 `@deepseek-ai` 的第三方插件源仓库(启动时的 CMD 无感会**尽力**修补已装的 doctor / market / 梁神 / mnemon,属运行时补丁)。
|
||||
- 安装走 GitHub 归档(npm 上没有这个包):`dsh plugin --profile web add https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz`(桌面端把 profile 换成 `desktop`)。当前目录已是本仓库时 `add .`。
|
||||
- 安装走 GitHub 压缩包(npm 仓库没有这个名字,也不要走插件市场)。有 `dsh`:`dsh plugin --profile web add https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master`。只有 pnpm:在 `$DSH_HOME/profiles/web` 里 `pnpm add` 同一地址。桌面把 `web` 换成 `desktop`。当前目录已是本仓库时 `add .`。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"purge.title": "补丁",
|
||||
"override.title": "提示词",
|
||||
"own.title": "本地靶场",
|
||||
"own.hint": "开源版攻击任务只放行本机/内网本地靶场(localhost、私网、.lab/.lan/.htb 等)。不能登记公网服务器,公网 IP 和域名一律拦截。",
|
||||
"own.hint": "开源版攻击任务只放行本机/内网 IP。域名会先解析,解析到的每一个地址都必须是私网或回环;hosts 把 .lab 指到公网 IP 也会拦。解析失败或混有公网地址一律拦截。",
|
||||
"own.save": "保存名单",
|
||||
"saved.own": "已保存自己的服务器",
|
||||
"saved.own.dropped": "已保存。有 {n} 行不是单个 IP 或主机名,已丢掉",
|
||||
@@ -519,7 +519,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"purge.title": "Patches",
|
||||
"override.title": "Prompt",
|
||||
"own.title": "Local lab only",
|
||||
"own.hint": "The open-source build only allows local lab targets (localhost, private nets, .lab/.lan/.htb). You cannot register a public host. Public IPs and domains are blocked.",
|
||||
"own.hint": "The open-source build only allows localhost/private IPs. Domains are resolved first; every A/AAAA must be loopback or RFC1918. A hosts entry that points .lab at a public IP is blocked. Failed or mixed public answers are denied.",
|
||||
"own.save": "Save list",
|
||||
"saved.own": "Own servers saved",
|
||||
"saved.own.dropped": "Saved. {n} lines were not a single IP or hostname and were dropped",
|
||||
|
||||
+19
-21
@@ -30,31 +30,29 @@
|
||||
personaPrefix: ""
|
||||
personaSuffix: ""
|
||||
|
||||
# 本体已经在 profile.bundles 里入队。这里只改它的 inject/config,再 insert 一次会
|
||||
# already queued: dsh-purge(Hub 市场一键装就是这么挂的)。
|
||||
- id: dsh-purge
|
||||
inject: [systemPrompt, tools]
|
||||
config:
|
||||
enabled: true
|
||||
autoApplyOnStart: false
|
||||
autoUpdateOnStart: false
|
||||
autoRevertOnMissing: false
|
||||
injectOnce: false
|
||||
stripMnemon: true
|
||||
verbose: false
|
||||
postPrompt: ""
|
||||
postPromptOrder: 5100
|
||||
autoRetry: true
|
||||
retryMax: 3
|
||||
autoContinue: false
|
||||
continueMax: 3
|
||||
continueText: "继续"
|
||||
capabilityProtocol: true
|
||||
hooksDenyBypass: true
|
||||
|
||||
- insert:
|
||||
- id: dsh-purge
|
||||
name: 'dsh-purge'
|
||||
inject: [systemPrompt, tools]
|
||||
config:
|
||||
enabled: true
|
||||
autoApplyOnStart: false
|
||||
autoUpdateOnStart: false
|
||||
autoRevertOnMissing: false
|
||||
injectOnce: false
|
||||
stripMnemon: true
|
||||
verbose: false
|
||||
postPrompt: ""
|
||||
postPromptOrder: 5100
|
||||
autoRetry: true
|
||||
retryMax: 3
|
||||
autoContinue: false
|
||||
continueMax: 3
|
||||
continueText: "继续"
|
||||
capabilityProtocol: true
|
||||
hooksDenyBypass: true
|
||||
|
||||
# 演练台:预设 + 技能落地(本插件 lib/redteam)
|
||||
- id: dsh-purge-redteam
|
||||
name: dsh-purge/redteam
|
||||
|
||||
@@ -27,6 +27,12 @@ import * as continueRetry from "./continue-retry.js";
|
||||
import * as uninstaller from "./uninstall.js";
|
||||
import { readDrillGrant, writeDrillGrant } from "./drill-grant.js";
|
||||
import { installRegionGate, readAllowText, writeAllowText } from "./net-scope.js";
|
||||
import {
|
||||
cancelClearOwnedSelectedDefault,
|
||||
clearOwnedSelectedDefault,
|
||||
removeStaleAgentPresetDir,
|
||||
scheduleClearOwnedSelectedDefault,
|
||||
} from "./preset-default.js";
|
||||
import {
|
||||
applyShouldRestart,
|
||||
isInactiveContextError,
|
||||
@@ -1455,8 +1461,16 @@ export function apply(ctx, config) {
|
||||
const cfg = { ...DEFAULTS, ...(config || {}) };
|
||||
if (!cfg.enabled) {
|
||||
purgeLog("boot", { enabled: false });
|
||||
try { clearOwnedSelectedDefault({ ctx, dshHome: core.findDshHome() }); } catch { /* 停用不被清默认挡住 */ }
|
||||
try { removeStaleAgentPresetDir(core.findDshHome(), "redteam"); } catch { /* ignore */ }
|
||||
return;
|
||||
}
|
||||
cancelClearOwnedSelectedDefault();
|
||||
try {
|
||||
ctx.effect(() => () => {
|
||||
try { scheduleClearOwnedSelectedDefault({ ctx, dshHome: core.findDshHome() }); } catch { /* 停用不被清默认挡住 */ }
|
||||
});
|
||||
} catch { /* 无 effect 时靠 uninstall / enabled:false 清 */ }
|
||||
purgeLog("boot", {
|
||||
enabled: true,
|
||||
surface: hostctl.currentSurface(),
|
||||
|
||||
+246
-83
@@ -1,6 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import dns from "node:dns/promises";
|
||||
import { findDshHome } from "./core.js";
|
||||
|
||||
const SUFFIXES = [
|
||||
@@ -183,48 +184,76 @@ function bankHit(name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 开源版只认本地靶场:本机/内网,以及本机实验室后缀。公网平台和自建公网主机一律拦。
|
||||
const RANGE_SUFFIXES = [
|
||||
".htb",
|
||||
".thm",
|
||||
".lab",
|
||||
".lan",
|
||||
".internal",
|
||||
".test",
|
||||
".home.arpa",
|
||||
];
|
||||
const LOOKUP_MS = 2000;
|
||||
const LOOKUP_TTL_MS = 5000;
|
||||
const lookupCache = new Map();
|
||||
|
||||
const RANGE_HOSTS = new Set([
|
||||
"host.docker.internal",
|
||||
"gateway.docker.internal",
|
||||
"kubernetes.docker.internal",
|
||||
]);
|
||||
|
||||
function rangeHit(name) {
|
||||
if (!name || typeof name !== "string") return false;
|
||||
if (RANGE_HOSTS.has(name)) return true;
|
||||
for (const suffix of RANGE_SUFFIXES) {
|
||||
if (name === suffix.slice(1) || name.endsWith(suffix)) return true;
|
||||
}
|
||||
let dot = name.indexOf(".");
|
||||
while (dot !== -1) {
|
||||
if (RANGE_HOSTS.has(name.slice(dot + 1))) return true;
|
||||
dot = name.indexOf(".", dot + 1);
|
||||
}
|
||||
function isLocalLabV4(value) {
|
||||
const a = value >>> 24;
|
||||
const b = (value >>> 16) & 255;
|
||||
if (a === 10 || a === 127) return true;
|
||||
if (a === 172 && b >= 16 && b <= 31) return true;
|
||||
if (a === 192 && b === 168) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function isLocalLabAddress(addr) {
|
||||
const name = hostOf(addr);
|
||||
if (!name) return false;
|
||||
if (name.includes(":")) {
|
||||
const value = parseIpv6(name);
|
||||
if (value == null) return false;
|
||||
if ((value >> 32n) === 0xffffn) return isLocalLabV4(Number(value & 0xffffffffn) >>> 0);
|
||||
if (value === 0n || value === 1n) return true;
|
||||
if ((value >> 118n) === 0x3fan) return true;
|
||||
if ((value >> 121n) === 0x7en) return true;
|
||||
return false;
|
||||
}
|
||||
const value = ipv4ToInt(name);
|
||||
return value != null && isLocalLabV4(value);
|
||||
}
|
||||
|
||||
async function lookupIps(name) {
|
||||
const key = String(name || "").toLowerCase();
|
||||
const cached = lookupCache.get(key);
|
||||
if (cached && cached.at > Date.now() - LOOKUP_TTL_MS) return cached.ips;
|
||||
let ips = [];
|
||||
try {
|
||||
const rows = await Promise.race([
|
||||
dns.lookup(key, { all: true, verbatim: true }),
|
||||
new Promise((_, reject) => {
|
||||
const timer = setTimeout(() => reject(new Error("lookup-timeout")), LOOKUP_MS);
|
||||
if (typeof timer.unref === "function") timer.unref();
|
||||
}),
|
||||
]);
|
||||
ips = [...new Set((Array.isArray(rows) ? rows : [rows]).map((row) => row && row.address).filter(Boolean))];
|
||||
} catch {
|
||||
ips = [];
|
||||
}
|
||||
lookupCache.set(key, { at: Date.now(), ips });
|
||||
if (lookupCache.size > 256) lookupCache.delete(lookupCache.keys().next().value);
|
||||
return ips;
|
||||
}
|
||||
|
||||
const DENIAL = "不行,这是严令禁止的";
|
||||
|
||||
// 渗透(?!测试):「渗透测试 / IP 与渗透测试」不是攻击任务(#73)。
|
||||
// exploit(?!-):exploit-db.com 等资料站不算 exploit 关键词。
|
||||
// (?<!防御)攻击:「防御攻击手法」不误触。
|
||||
const ATTACK =
|
||||
/渗透(?!测试)|打穿|打下|打站|入侵|拿壳|拿权限|爆破|提权|webshell|getshell|端口扫描|pentest|\bexploit\b(?![-a-z0-9])|\bbreach\b|\bpwn\b|(?<!防御)攻击(?!面)|(?<!surface\s)\battack\b(?!\s+surface)/i;
|
||||
/渗透测试|红队|打点|拿站|渗透(?!测试)|打穿|打下|打站|入侵|拿壳|拿权限|爆破|提权|webshell|getshell|端口扫描|pentest|\bexploit\b(?![-a-z0-9])|\bbreach\b|\bpwn\b|(?<!防御)攻击(?!面)|(?<!surface\s)\battack\b(?!\s+surface)/i;
|
||||
|
||||
// ReDoS 保险:ATTACK 含零宽环视,整段消息(贴代码/日志)超过 100KB 时正则回溯会把事件循环卡死。
|
||||
// 真实攻击意图通常在前几千字符,100KB cap 不会误放过。
|
||||
const ATTACK_SCAN_CAP = 100 * 1024;
|
||||
// 外挂硬拦。单字「辅助 / 透视」太容易误伤辅助函数、透视投影,必须带游戏或挂本身。
|
||||
const CHEAT_STRONG =
|
||||
/外挂|游戏辅助|自瞄|自动瞄准|无后座|无限弹药|人物透视|物品透视|透视挂|开透视|加速挂|飞天挂|瞬移挂|锁头|压枪挂|改血|过反作弊|注入游戏|aimbot|wallhack|triggerbot|spinbot|silent\s*aim|game\s*cheat|anti-?cheat|cheat\s*engine/i;
|
||||
const CHEAT_GAME =
|
||||
/游戏|网游|端游|手游|\bgame\b|steam|csgo|\bcs2\b|pubg|valorant|和平精英|王者荣耀|原神/i;
|
||||
const CHEAT_WEAK =
|
||||
/内存修改|读内存|写内存|dll注入/i;
|
||||
|
||||
// ReDoS 保险:ATTACK 含零宽环视,整段消息(贴代码/日志)超过上限时按窗扫,不一次喂整篇。
|
||||
const ATTACK_SCAN_CAP = 256 * 1024;
|
||||
const ATTACK_WINDOW = 8192;
|
||||
|
||||
const NET_TOPIC =
|
||||
/(?:代理|\bproxy\b|socks|vpn|frp|clash|v2ray|小飞机|机场|出口\s*ip|本机\s*ip|内网\s*ip|公网\s*ip|ip\s*地址|ip\s*归属|ip\s*查询|ip\s*相关|dns|域名解析|网卡|隧道|反向代理|正向代理|http[s]?\s*代理)/i;
|
||||
@@ -242,17 +271,6 @@ function ipv4ToInt(ip) {
|
||||
return value >>> 0;
|
||||
}
|
||||
|
||||
function isSkippedV4(value) {
|
||||
const a = value >>> 24;
|
||||
const b = (value >>> 16) & 255;
|
||||
if (a === 0 || a === 10 || a === 127) return true;
|
||||
if (a === 169 && b === 254) return true;
|
||||
if (a === 172 && b >= 16 && b <= 31) return true;
|
||||
if (a === 192 && b === 168) return true;
|
||||
if (a >= 224) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseIpv6(input) {
|
||||
let text = String(input || "").trim().toLowerCase().split("%")[0];
|
||||
if (!text) return null;
|
||||
@@ -329,14 +347,24 @@ function collectFromText(text, hosts) {
|
||||
const sample = String(text || "").slice(0, 32768);
|
||||
const url = /\b(?:[a-z][a-z0-9+.-]*:\/\/)([^/?#\s]+)/gi;
|
||||
for (const match of sample.matchAll(url)) addHost(match[1], hosts);
|
||||
const mapped = [];
|
||||
const mappedRe = /(?:[0-9a-f]{0,4}:){1,6}ffff:(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)/gi;
|
||||
for (const match of sample.matchAll(mappedRe)) {
|
||||
const value = match[0].toLowerCase();
|
||||
hosts.add(value);
|
||||
mapped.push({ start: match.index, end: match.index + match[0].length });
|
||||
}
|
||||
const covered = (index, length) => mapped.some((span) => index >= span.start && index + length <= span.end);
|
||||
const ipv4 = /\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g;
|
||||
for (const match of sample.matchAll(ipv4)) hosts.add(match[0]);
|
||||
// 加 lookbehind/lookahead 排除 HH:MM:SS 之类纯十进制时间串,避免误报为 IPv6。
|
||||
for (const match of sample.matchAll(ipv4)) {
|
||||
if (covered(match.index, match[0].length)) continue;
|
||||
hosts.add(match[0]);
|
||||
}
|
||||
const ipv6 = /(?<![\d:])(?:[0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}(?![\d])/gi;
|
||||
for (const match of sample.matchAll(ipv6)) {
|
||||
const value = match[0];
|
||||
// 二次兜底:若整段只有十进制 + 冒号(无 a-f),拒绝
|
||||
if (/^[\d:]+$/.test(value)) continue;
|
||||
if (covered(match.index, value.length)) continue;
|
||||
hosts.add(value);
|
||||
}
|
||||
const domain = /\b(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}\b/gi;
|
||||
@@ -345,6 +373,7 @@ function collectFromText(text, hosts) {
|
||||
if (!keepBareDomain(sample, match.index, name)) continue;
|
||||
hosts.add(name);
|
||||
}
|
||||
if (/\blocalhost\b/i.test(sample)) hosts.add("localhost");
|
||||
}
|
||||
|
||||
const HOST_NAME = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
||||
@@ -409,13 +438,9 @@ export function readAllowText(dshHome = findDshHome()) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function writeAllowText(dshHome, text) {
|
||||
const normalized = normalizeAllowText(text);
|
||||
const fp = allowFilePath(dshHome);
|
||||
await fs.promises.mkdir(path.dirname(fp), { recursive: true });
|
||||
await fs.promises.writeFile(fp, normalized.text, "utf8");
|
||||
export async function writeAllowText() {
|
||||
allowCache = { path: "", mtime: -1, exact: new Set(), ips: null, at: 0 };
|
||||
return normalized;
|
||||
return { text: "", dropped: 0, hosts: [] };
|
||||
}
|
||||
|
||||
let allowCache = { path: "", mtime: -1, exact: new Set(), ips: null, at: 0 };
|
||||
@@ -449,17 +474,8 @@ function permittedHost() {
|
||||
function isOwnNetwork(host) {
|
||||
const name = hostOf(host);
|
||||
if (!name) return false;
|
||||
if (name === "localhost" || name.endsWith(".localhost") || name.endsWith(".local")) return true;
|
||||
if (name.includes(":")) {
|
||||
const value = parseIpv6(name);
|
||||
if (value == null) return false;
|
||||
if (value === 0n || value === 1n) return true;
|
||||
if ((value >> 118n) === 0x3fan) return true;
|
||||
if ((value >> 121n) === 0x7en) return true;
|
||||
return false;
|
||||
}
|
||||
const value = ipv4ToInt(name);
|
||||
return value != null && isSkippedV4(value);
|
||||
if (name === "localhost" || name.endsWith(".localhost")) return true;
|
||||
return isLocalLabAddress(name);
|
||||
}
|
||||
|
||||
function isIp(host) {
|
||||
@@ -474,41 +490,148 @@ function taskHit(label, kind) {
|
||||
export function isBenignNetworkTopic(text) {
|
||||
const t = String(text || "").trim();
|
||||
if (!t || !NET_TOPIC.test(t)) return false;
|
||||
return !ATTACK.test(t.length > 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) {
|
||||
const sample = String(text || "");
|
||||
const cap = sample.length > ATTACK_SCAN_CAP ? sample.slice(0, ATTACK_SCAN_CAP) : sample;
|
||||
if (CHEAT_STRONG.test(cap)) return true;
|
||||
return CHEAT_GAME.test(cap) && CHEAT_WEAK.test(cap);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function isRangeTarget(name) {
|
||||
return isOwnNetwork(name) || rangeHit(name);
|
||||
/**
|
||||
* 本地靶场只认解析结果。后缀(.lab / .htb)本身不放行。
|
||||
* 走系统解析(含 hosts):所有 A/AAAA 都必须是本机/私网,有一条公网或解析失败就拦。
|
||||
*/
|
||||
async function isRangeTarget(name) {
|
||||
if (!name) return false;
|
||||
if (name === "localhost" || name.endsWith(".localhost")) return true;
|
||||
if (isIp(name)) return isLocalLabAddress(name);
|
||||
const ips = await lookupIps(name);
|
||||
if (!ips.length) return false;
|
||||
return ips.every((ip) => isLocalLabAddress(ip));
|
||||
}
|
||||
|
||||
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 null;
|
||||
for (const name of names) {
|
||||
if (await isRangeTarget(name)) continue;
|
||||
return taskHit(name, isIp(name) ? "ip" : bankHit(name) ? "bank" : "domain");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function taskTargetHit(text) {
|
||||
if (!isAttackTask(text)) return null;
|
||||
let found = false;
|
||||
for (const host of hostsInTask(text)) {
|
||||
const name = hostOf(host);
|
||||
if (!name) continue;
|
||||
if (isRangeTarget(name)) continue;
|
||||
return taskHit(name, isIp(name) ? "ip" : bankHit(name) ? "bank" : "domain");
|
||||
if (hostOf(host)) found = true;
|
||||
}
|
||||
return null;
|
||||
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) {
|
||||
@@ -628,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;
|
||||
@@ -660,16 +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 || !isAttackTask(task)) return forward();
|
||||
hit = await taskTargetHit(task);
|
||||
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();
|
||||
}
|
||||
@@ -682,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 {
|
||||
|
||||
+26
-2
@@ -38,8 +38,10 @@ function listProfilePatchFiles(dshHome) {
|
||||
}
|
||||
for (const name of names) {
|
||||
if (name === "node_modules") continue;
|
||||
const fp = path.join(root, name, "cordis.patch.yml");
|
||||
if (fs.existsSync(fp)) out.push(fp);
|
||||
for (const file of ["cordis.patch.yml", "cordis.yml"]) {
|
||||
const fp = path.join(root, name, file);
|
||||
if (fs.existsSync(fp)) out.push(fp);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -167,6 +169,28 @@ export function clearOwnedSelectedDefault({ ctx = null, dshHome = "" } = {}) {
|
||||
return report;
|
||||
}
|
||||
|
||||
let pendingClear = null;
|
||||
|
||||
/** 热重载会先 dispose 再 apply:延迟写盘,apply 进来就取消,避免把用户的红队默认冲掉。 */
|
||||
export function scheduleClearOwnedSelectedDefault(opts = {}) {
|
||||
if (pendingClear) {
|
||||
clearTimeout(pendingClear);
|
||||
pendingClear = null;
|
||||
}
|
||||
pendingClear = setTimeout(() => {
|
||||
pendingClear = null;
|
||||
try { clearOwnedSelectedDefault(opts); } catch { /* 停用不被清默认挡住 */ }
|
||||
try { removeStaleAgentPresetDir(opts.dshHome, "redteam"); } catch { /* ignore */ }
|
||||
}, 800);
|
||||
if (typeof pendingClear.unref === "function") pendingClear.unref();
|
||||
}
|
||||
|
||||
export function cancelClearOwnedSelectedDefault() {
|
||||
if (!pendingClear) return;
|
||||
clearTimeout(pendingClear);
|
||||
pendingClear = null;
|
||||
}
|
||||
|
||||
export function removeStaleAgentPresetDir(dshHome, id = "redteam") {
|
||||
const home = dshHome || findDshHome();
|
||||
if (!home || !id) return false;
|
||||
|
||||
+40
-3
@@ -11,6 +11,7 @@ import { homedir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { readPresetDefinition } from './preset-composition.js'
|
||||
import { scheduleClearOwnedSelectedDefault } from '../preset-default.js'
|
||||
|
||||
/** Cordis 插件名。 */
|
||||
export const name = 'dsh-purge-redteam'
|
||||
@@ -191,6 +192,36 @@ function needsCompositionRepair(presetFile) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 0.2.1 已废弃 toolFilter:旧用户预设里还留着就会让红队模式整份加载失败。 */
|
||||
function stripToolFilter(text) {
|
||||
const lines = String(text || '').split(/\r?\n/)
|
||||
const out = []
|
||||
let skipIndent = null
|
||||
let changed = false
|
||||
for (const line of lines) {
|
||||
if (skipIndent !== null) {
|
||||
const indent = (/^(\s*)/.exec(line) || ['', ''])[1].length
|
||||
if (line.trim() !== '' && indent > skipIndent) {
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
skipIndent = null
|
||||
}
|
||||
const block = /^(\s*)toolFilter:\s*(?:#.*)?$/.exec(line)
|
||||
if (block) {
|
||||
skipIndent = block[1].length
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
if (/^\s*toolFilter:\s+\S/.test(line)) {
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
out.push(line)
|
||||
}
|
||||
return { text: out.join('\n'), changed }
|
||||
}
|
||||
|
||||
/** 从独立红队包迁进 dsh-purge 后,预设里的工具行包名要跟着改。 */
|
||||
function renderToolsPackage(text) {
|
||||
if (!text.includes('dsh-redteam-mode/tools')) {
|
||||
@@ -368,9 +399,10 @@ export function installPreset(options = {}) {
|
||||
}
|
||||
const rendered = renderSkillsDir(text)
|
||||
const tools = renderToolsPackage(rendered.text)
|
||||
const delegation = repairDelegation(tools.text)
|
||||
const filter = stripToolFilter(tools.text)
|
||||
const delegation = repairDelegation(filter.text)
|
||||
const next = delegation.text
|
||||
if (rendered.changed || tools.changed || delegation.changed) {
|
||||
if (rendered.changed || tools.changed || filter.changed || delegation.changed) {
|
||||
writeFileSync(presetFile, next.replace(/\r\n/g, '\n').replace(/\r/g, '\n'), 'utf8')
|
||||
log(
|
||||
(rendered.changed
|
||||
@@ -380,8 +412,11 @@ export function installPreset(options = {}) {
|
||||
+ ',已改为 dshHomePath(\'redteam/skills\')'
|
||||
: '')
|
||||
+ (tools.changed ? (rendered.changed ? ';' : '') + '工具包名已改为 dsh-purge/redteam/tools' : '')
|
||||
+ (filter.changed
|
||||
? ((rendered.changed || tools.changed) ? ';' : '') + '已去掉 0.2.1 废弃的 toolFilter'
|
||||
: '')
|
||||
+ (delegation.changed
|
||||
? ((rendered.changed || tools.changed) ? ';' : '') + '已修复指挥派活约束 / 重新启用 subagent'
|
||||
? ((rendered.changed || tools.changed || filter.changed) ? ';' : '') + '已修复指挥派活约束 / 重新启用 subagent'
|
||||
: ''),
|
||||
)
|
||||
}
|
||||
@@ -392,6 +427,7 @@ export function installPreset(options = {}) {
|
||||
const repaired = [
|
||||
rendered.changed ? rendered.reason : null,
|
||||
tools.changed ? 'tools-package' : null,
|
||||
filter.changed ? 'toolFilter' : null,
|
||||
delegation.changed ? 'delegation' : null,
|
||||
anchor === 'inserted' ? 'anchor-gate' : null,
|
||||
anchor === 'updated' ? 'anchor-script' : null,
|
||||
@@ -570,6 +606,7 @@ export function apply(ctx) {
|
||||
closed = true
|
||||
if (timer) clearInterval(timer)
|
||||
if (stop) clearTimeout(stop)
|
||||
try { scheduleClearOwnedSelectedDefault({ ctx }) } catch { /* 清默认失败不挡停用 */ }
|
||||
void undeclare()
|
||||
}
|
||||
}, 'dsh-purge-redteam: declare agent preset')
|
||||
|
||||
+35
-6
@@ -99,7 +99,36 @@ function loadDefineTool() {
|
||||
throw new Error('dsh-purge/redteam/tools: cannot resolve @deepseek-ai/dsh-tools from host')
|
||||
}
|
||||
|
||||
const defineTool = loadDefineTool()
|
||||
const defineToolRaw = loadDefineTool()
|
||||
|
||||
/** 0.2.1:任何 type=object 都必须显式 additionalProperties,否则整份红队预设加载失败。 */
|
||||
function sealObjectSchemas(node) {
|
||||
if (!node || typeof node !== 'object') return node
|
||||
if (Array.isArray(node)) {
|
||||
for (const item of node) sealObjectSchemas(item)
|
||||
return node
|
||||
}
|
||||
if (node.type === 'object' && node.additionalProperties === undefined) {
|
||||
node.additionalProperties = node.properties ? false : true
|
||||
}
|
||||
if (node.properties) {
|
||||
for (const key of Object.keys(node.properties)) sealObjectSchemas(node.properties[key])
|
||||
}
|
||||
if (node.items) sealObjectSchemas(node.items)
|
||||
if (node.additionalProperties && typeof node.additionalProperties === 'object') {
|
||||
sealObjectSchemas(node.additionalProperties)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
function defineTool(spec) {
|
||||
if (spec && spec.parameters) sealObjectSchemas(spec.parameters)
|
||||
const tool = defineToolRaw(spec)
|
||||
if (tool && tool.parameters) sealObjectSchemas(tool.parameters)
|
||||
if (tool && tool.inputSchema) sealObjectSchemas(tool.inputSchema)
|
||||
if (tool && tool.schema) sealObjectSchemas(tool.schema)
|
||||
return tool
|
||||
}
|
||||
|
||||
/** Cordis 插件名。 */
|
||||
export const name = 'dsh-purge-redteam-tools'
|
||||
@@ -2057,8 +2086,8 @@ export function apply(ctx) {
|
||||
parameters: {
|
||||
engagement: { type: 'string' },
|
||||
operation: { type: 'string', required: true, description: '操作名,如 "nmap_scan"、"webshell_established"、"sql_injection_confirmed"' },
|
||||
parameters: { type: 'object', description: '调用参数(JSON 对象,会参与哈希)' },
|
||||
result: { type: 'object', required: true, description: '规范化结果(JSON 对象,会参与哈希)' },
|
||||
parameters: { type: 'object', additionalProperties: true, description: '调用参数(JSON 对象,会参与哈希)' },
|
||||
result: { type: 'object', additionalProperties: true, required: true, description: '规范化结果(JSON 对象,会参与哈希)' },
|
||||
confidence: { type: 'string', description: 'claimed | observed | derived | inferred,默认 observed' },
|
||||
authority: { type: 'string', description: 'tool-output | database-record | screenshot | request-replay | subagent-report | operator-input,默认 tool-output' },
|
||||
limitations: { type: 'array', items: { type: 'string' }, description: '局限性说明,如 ["只扫了 Top1000 端口"]' },
|
||||
@@ -2090,8 +2119,8 @@ export function apply(ctx) {
|
||||
parameters: {
|
||||
engagement: { type: 'string' },
|
||||
operation: { type: 'string', required: true },
|
||||
parameters: { type: 'object' },
|
||||
result: { type: 'object', required: true },
|
||||
parameters: { type: 'object', additionalProperties: true },
|
||||
result: { type: 'object', additionalProperties: true, required: true },
|
||||
confidence: { type: 'string' },
|
||||
authority: { type: 'string' },
|
||||
limitations: { type: 'array', items: { type: 'string' } },
|
||||
@@ -2119,7 +2148,7 @@ export function apply(ctx) {
|
||||
parameters: {
|
||||
engagement: { type: 'string' },
|
||||
claimed_ev_id: { type: 'string', required: true, description: '要升级的证据 ID' },
|
||||
verified_result: { type: 'object', description: '亲自验证后的实际结果' },
|
||||
verified_result: { type: 'object', additionalProperties: true, description: '亲自验证后的实际结果' },
|
||||
verified_by: { type: 'string', description: '谁核实的,默认 coordinator' },
|
||||
},
|
||||
output: { schema: { type: 'string' }, render: (_args, value) => text(value) },
|
||||
|
||||
+33
-13
@@ -6,6 +6,7 @@ import * as hostctl from "./host.js";
|
||||
import * as rules from "./rules.js";
|
||||
import * as updater from "./update.js";
|
||||
import { clearDrillGrant } from "./drill-grant.js";
|
||||
import { clearOwnedSelectedDefault, removeStaleAgentPresetDir } from "./preset-default.js";
|
||||
|
||||
export function wasApplied(state) {
|
||||
if (!state) return false;
|
||||
@@ -34,6 +35,18 @@ export function shouldDeletePluginTree(dir, dshHome = core.findDshHome()) {
|
||||
return n.startsWith(`${homeN}/profiles/`);
|
||||
}
|
||||
|
||||
function isPurgeBundleItem(item) {
|
||||
if (typeof item === "string") return item === "dsh-purge" || item.startsWith("dsh-purge@");
|
||||
const id = item && (item.id || item.name);
|
||||
return id === "dsh-purge";
|
||||
}
|
||||
|
||||
function stripBundleList(list) {
|
||||
if (!Array.isArray(list)) return { list, changed: false };
|
||||
const next = list.filter((item) => !isPurgeBundleItem(item));
|
||||
return { list: next, changed: next.length !== list.length };
|
||||
}
|
||||
|
||||
export function stripPluginFromPackage(pkg) {
|
||||
if (!pkg || typeof pkg !== "object") return false;
|
||||
let changed = false;
|
||||
@@ -44,14 +57,15 @@ export function stripPluginFromPackage(pkg) {
|
||||
}
|
||||
}
|
||||
for (const key of ["bundles", "plugins"]) {
|
||||
if (!Array.isArray(pkg[key])) continue;
|
||||
const next = pkg[key].filter((item) => {
|
||||
if (typeof item === "string") return item !== "dsh-purge" && !item.startsWith("dsh-purge@");
|
||||
const id = item && (item.id || item.name);
|
||||
return id !== "dsh-purge";
|
||||
});
|
||||
if (next.length !== pkg[key].length) {
|
||||
pkg[key] = next;
|
||||
const top = stripBundleList(pkg[key]);
|
||||
if (top.changed) {
|
||||
pkg[key] = top.list;
|
||||
changed = true;
|
||||
}
|
||||
const nested = pkg.dsh && pkg.dsh.profile ? pkg.dsh.profile[key] : null;
|
||||
const nest = stripBundleList(nested);
|
||||
if (nest.changed) {
|
||||
pkg.dsh.profile[key] = nest.list;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@@ -74,11 +88,9 @@ function pkgMentionsPurge(pkg) {
|
||||
if (!pkg) return false;
|
||||
if (pkg.dependencies?.["dsh-purge"] || pkg.devDependencies?.["dsh-purge"]) return true;
|
||||
for (const key of ["bundles", "plugins"]) {
|
||||
if (!Array.isArray(pkg[key])) continue;
|
||||
if (pkg[key].some((item) => {
|
||||
if (typeof item === "string") return item === "dsh-purge" || item.startsWith("dsh-purge@");
|
||||
return item && (item.id === "dsh-purge" || item.name === "dsh-purge");
|
||||
})) return true;
|
||||
if (Array.isArray(pkg[key]) && pkg[key].some(isPurgeBundleItem)) return true;
|
||||
const nested = pkg.dsh && pkg.dsh.profile ? pkg.dsh.profile[key] : null;
|
||||
if (Array.isArray(nested) && nested.some(isPurgeBundleItem)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -254,6 +266,14 @@ export async function uninstallPurge() {
|
||||
report.errors.push(`reset rules: ${e.message || e}`);
|
||||
}
|
||||
|
||||
try {
|
||||
const preset = clearOwnedSelectedDefault({ dshHome });
|
||||
report.presetDefault = { live: preset.live, files: preset.files };
|
||||
report.stalePresetDir = removeStaleAgentPresetDir(dshHome, "redteam");
|
||||
} catch (e) {
|
||||
report.errors.push(`clear selectedDefault: ${e.message || e}`);
|
||||
}
|
||||
|
||||
const profiles = listInstalledProfiles(dshHome);
|
||||
report.profiles = profiles.map((p) => p.name);
|
||||
const unreg = unregisterProfiles(profiles);
|
||||
|
||||
+5
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.73",
|
||||
"version": "1.1.78",
|
||||
"description": "DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词;默认提示词面向国模「小码酱」。Jailbreak for every model — swap prompts per model. 求 Star 收藏 ⭐ 如要二开,请查看署名要求部分",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
@@ -35,7 +35,8 @@
|
||||
],
|
||||
"scripts": {
|
||||
"embed-prompt": "node scripts/embed-default-prompt.mjs",
|
||||
"build:client": "node scripts/build-client.mjs"
|
||||
"build:client": "node scripts/build-client.mjs",
|
||||
"postinstall": "node scripts/ensure-profile-bundle.mjs"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
@@ -78,8 +79,8 @@
|
||||
},
|
||||
"install": {
|
||||
"preferred": "tarball",
|
||||
"tarball": "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz",
|
||||
"zip": "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip",
|
||||
"tarball": "https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master",
|
||||
"zip": "https://codeload.github.com/YuJunZhiXue/dsh-purge/zip/refs/heads/master",
|
||||
"git": "https://github.com/YuJunZhiXue/dsh-purge.git"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,3 +1,77 @@
|
||||
# 1.1.78
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本 **1.1.78**。修复 bug:停用/卸载后无法新建会话。
|
||||
- **#108**:停用或卸载时把 `agent-preset-registry.selectedDefault` 从 `redteam` 改回 `standard`,并清掉 `$DSH_HOME/.agent-presets/redteam`。热重载不会冲掉用户设的红队默认。
|
||||
- 卸载同时处理 `dsh.profile.bundles` / `dsh.profile.plugins`,桌面 profile 不再残留 `dsh-purge`。
|
||||
|
||||
## English
|
||||
|
||||
- **1.1.78**. Bug fix: new sessions after disable/uninstall.
|
||||
- **#108**: on disable or uninstall, reset `agent-preset-registry.selectedDefault` from `redteam` to `standard`, and remove `$DSH_HOME/.agent-presets/redteam`. Hot reload keeps a user-chosen redteam default.
|
||||
- Uninstall also strips `dsh.profile.bundles` / `dsh.profile.plugins`.
|
||||
|
||||
# 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
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本 **1.1.76**。适配只走 pnpm 的机器:在 profile 目录 `pnpm add` codeload 压缩包即可,`postinstall` 自动把 `dsh-purge` 写进 `bundles`。
|
||||
- 安装地址改成 `codeload.github.com`,避开 `github.com/archive` 的 302(pnpm 会 `fetch failed`)。不要 `pnpm add dsh-purge`(npm 仓库没有这个名字)。
|
||||
|
||||
## English
|
||||
|
||||
- **1.1.76**. pnpm-only hosts: `pnpm add` the codeload tarball inside the profile; `postinstall` writes `dsh-purge` into `bundles`.
|
||||
- Install URL is `codeload.github.com` so pnpm does not die on the `github.com/archive` 302. Do not `pnpm add dsh-purge` — that name is not on the npm registry.
|
||||
|
||||
# 1.1.75
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本 **1.1.75**。修 Hub 市场一键安装报 `already queued: dsh-purge`:`cordis.patch.yml` 不再把已经在 bundles 里的本体再 insert 一遍。
|
||||
- README 把安装写成三步:只用 GitHub 压缩包命令,不走插件市场 / `github:` / npm。
|
||||
|
||||
## English
|
||||
|
||||
- **1.1.75**. Fix Hub one-click `already queued: dsh-purge`: the bundle patch no longer inserts the plugin that is already in `bundles`.
|
||||
- README install is three steps: GitHub tarball only; skip the plugin market / `github:` / npm.
|
||||
|
||||
# 1.1.74
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本 **1.1.74**,优化若干拦截与加载 bug。适配 DSH **0.2.1-rc.2**(0.2.0 仍可用)。
|
||||
- 修靶场门禁:域名先解析再判 IP,不再靠 `.lab` / `.htb` 后缀放行;`hosts` 指到公网、解析失败、混有公网,一律拦。
|
||||
- 修身份绕过:`169.254` 云元数据不再当靶场;`::ffff:公网` 拆开再判;攻击句不写目标不再放行。
|
||||
- 修 DSH 0.2.1 预设加载:对象 schema 补 `additionalProperties`,装过的 redteam 预设清掉残留 `toolFilter`。
|
||||
- 修演练台被改成英文:中文页签收回。
|
||||
- 禁止制作外挂:会话门口硬拦,提示词 Rule 1 改为禁止。
|
||||
|
||||
## English
|
||||
|
||||
- **1.1.74**, bug-fix release. Target DSH **0.2.1-rc.2** (0.2.0 still works).
|
||||
- Lab gate: resolve first, then allow only private IPs. Suffixes are not an allow list.
|
||||
- Close identity holes: drop link-local metadata, unwrap IPv4-mapped IPv6, deny unnamed attack tasks.
|
||||
- DSH 0.2.1 preset load: seal object schemas; strip leftover `toolFilter`.
|
||||
- Restore Chinese drill-console tabs.
|
||||
- Game cheats are forbidden at the session gate.
|
||||
|
||||
# 1.1.73
|
||||
|
||||
## 中文
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* pnpm add 只写 dependencies,不会把插件写进 dsh.profile.bundles。
|
||||
* 装进 DSH profile 时补上这一笔;在插件仓库里跑 pnpm install 则跳过。
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const NAME = "dsh-purge";
|
||||
|
||||
function readJson(fp) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(fp, "utf8"));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function isProfilePkg(pkg) {
|
||||
if (!pkg || typeof pkg !== "object") return false;
|
||||
if (typeof pkg.name === "string" && pkg.name.startsWith("dsh-profile-")) return true;
|
||||
return Array.isArray(pkg.dsh?.profile?.bundles);
|
||||
}
|
||||
|
||||
function findProfileDir() {
|
||||
const seeds = [process.env.INIT_CWD, process.env.npm_config_local_prefix, process.cwd()].filter(Boolean);
|
||||
for (const seed of seeds) {
|
||||
let dir = path.resolve(seed);
|
||||
for (let i = 0; i < 8; i += 1) {
|
||||
if (isProfilePkg(readJson(path.join(dir, "package.json")))) return dir;
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const profileDir = findProfileDir();
|
||||
if (!profileDir) process.exit(0);
|
||||
|
||||
const fp = path.join(profileDir, "package.json");
|
||||
const pkg = readJson(fp);
|
||||
if (!pkg) {
|
||||
process.stderr.write(`dsh-purge: cannot read ${fp}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
pkg.dsh = pkg.dsh && typeof pkg.dsh === "object" ? pkg.dsh : {};
|
||||
pkg.dsh.profile = pkg.dsh.profile && typeof pkg.dsh.profile === "object" ? pkg.dsh.profile : {};
|
||||
const bundles = Array.isArray(pkg.dsh.profile.bundles) ? pkg.dsh.profile.bundles : [];
|
||||
if (bundles.includes(NAME)) {
|
||||
process.stdout.write(`dsh-purge: already in bundles (${profileDir})\n`);
|
||||
process.exit(0);
|
||||
}
|
||||
pkg.dsh.profile.bundles = [...bundles, NAME];
|
||||
fs.writeFileSync(fp, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
||||
process.stdout.write(`dsh-purge: appended to bundles (${profileDir})\n`);
|
||||
Reference in new issue
Block a user