fix: judge lab targets by resolved private IPs, not domain suffixes.

This commit is contained in:
叫我小杨同学 committed 2026-10-23 18:04:32 +08:00
1 parent ba12c91ca0
commit 51afafdd2c
4 files changed
+72 -62

No files matched your search

+4 -4
View File
@@ -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. 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.
@@ -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. 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>
@@ -336,7 +336,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 +399,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.
---
+4 -4
View File
@@ -33,7 +33,7 @@
市面上有人把这份开源明目张胆挂出去卖。后面作者这边被找去谈过话——经过不必写,你们自己品。
从今往后,**公网一律不许碰**。开源版攻击任务只认**本地靶场**:本机、内网,以及 `.lab` / `.lan` / `.htb` 这类本机实验室后缀。公网 IP、域名、网上演练平台、自己登记的公网机器,一个都不放。不是本地靶场就别跑,也跑不过去。开源版不下发技能库和知识库。
从今往后,**公网一律不许碰**。开源版攻击任务只认**本地靶场 IP**:本机回环和 RFC1918 私网。域名会先按系统解析(含 hosts),解析到的每一个地址都必须是私网或回环;hosts 把 `.lab` 指到公网、解析失败、混有公网地址,一律拦。不是本地靶场就别跑,也跑不过去。开源版不下发技能库和知识库。
**原版不允许倒卖。** 收费、当货挂群,一律不行。二开可以,但**必须署名**,写明来源仓库:[YuJunZhiXue/dsh-purge](https://github.com/YuJunZhiXue/dsh-purge)。不署名、隐瞒来源、改头换面据为己有,作者一律当对家。
@@ -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. **严禁违法与违禁用途**:使用者严禁利用本项目直接或间接从事任何违反下列法律法规的行为(必须逐条遵守,不得以任何理由规避):
- **《中华人民共和国刑法》**
- **《中华人民共和国网络安全法》**
@@ -343,7 +343,7 @@ dsh-purge --uninstall
| 演练台 | 授权后的资产与环境页。开源版不下发技能库和知识库。未授权时按钮标「未授权」 |
| 补丁 | 分组查看状态,应用、还原或卸载 |
| 提示词 | 编辑 `prompt-inject.md`,作为会话覆盖段 |
| 本地靶场 | 只放行本机/内网和 `.lab` / `.lan` / `.htb` 等本机实验室后缀,不能登记公网主机 |
| 本地靶场 | 只放行本机/私网 IP;域名先解析,全部地址都必须是私网或回环 |
| 规则集 | 多套 `AGENTS.md` / `CLAUDE.md`;启用写入 `$DSH_HOME`,删除从列表去掉 |
@@ -410,7 +410,7 @@ DSH 会按顺序执行同一批中的 Bash 调用。旧版 dsh-purge 把默认
### 本地靶场
开源版攻击任务默认全拦,只放行本机/内网本地靶场。在对话里说「这是我的服务器」不会放行。登记公网 IP 或域名也不会。
开源版攻击任务默认全拦,只放行本机/私网 IP。域名先解析再判,不认 `.lab` / `.htb` 这类后缀本身。hosts 把实验室名指到公网 IP 也会拦。在对话里说「这是我的服务器」不会放行。
---
+2 -2
View File
@@ -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",
+62 -52
View File
@@ -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,37 +184,57 @@ 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 === 169 && b === 254) 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 === 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)。
@@ -242,17 +263,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;
@@ -449,17 +459,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) {
@@ -496,8 +497,17 @@ function hostsInTask(text) {
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 taskTargetHit(text) {
@@ -505,7 +515,7 @@ export async function taskTargetHit(text) {
for (const host of hostsInTask(text)) {
const name = hostOf(host);
if (!name) continue;
if (isRangeTarget(name)) continue;
if (await isRangeTarget(name)) continue;
return taskHit(name, isIp(name) ? "ip" : bankHit(name) ? "bank" : "domain");
}
return null;