mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 07:40:22 +08:00
fix: 全仓审计加固与死代码清理,版本 1.1.87
- 回滚/备份:空 bak 改名 .bad 跳过;升级刷新 bak 补上单数 marker 补丁;统一原子写 - 补丁命中:optional 命中不符记软失败;#42 插入型替换加探针防重复插入 - Windows:进程枚举改用 | 分隔 + UTF-8,修复中文路径换包不杀旧进程;换包失败拉起原版 - 安全:asar 解包防越界;红队路径校验 realpath 防空 symlink;更新仅 https;报告回放去换行注入 - 提示词钩子:停用后 rewriteFn 返回原装配文本并清理 assemble guard;缓存签名纳入红队/策略/override - 红队:listEngagements 默认不算统计;listVulns/报告支持 evidenceLimit - 子代理名额占位即时生效并回退;--apply 有失败项退出码 1 - 清理:删除 lib/mnemon-settings.js 及 13 处死代码/未使用 import;移除 test 目录与 test 脚本
This commit is contained in:
1 parent
71d3a55884
commit
f806b048ac
48 files changed
+890
-1652
No files matched your search
+18
-4
@@ -170,6 +170,20 @@ function ioFor(explicit, targetPath) {
|
||||
return explicit ?? fsFor(targetPath);
|
||||
}
|
||||
|
||||
/** 宿主 lib 里的文件(bin.js / sidecar)一律先写临时文件再 rename:
|
||||
* 直接覆盖时被占用/断电会留下半截模块,宿主下次启动直接 import 失败。 */
|
||||
export function writeHostFileAtomic(nodeFs, fp, text) {
|
||||
const tmp = `${fp}.${process.pid}.tmp`;
|
||||
nodeFs.writeFileSync(tmp, text, "utf8");
|
||||
try {
|
||||
if (typeof nodeFs.renameSync === "function") nodeFs.renameSync(tmp, fp);
|
||||
else nodeFs.writeFileSync(fp, text, "utf8");
|
||||
} catch (error) {
|
||||
try { nodeFs.unlinkSync(tmp); } catch { /* ignore */ }
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/** 源码 monorepo 的 apps/cli(tsdown 构建产物)。往这里注入/还原会动构建输出,缺 bak 时无法自愈(#41)。 */
|
||||
export function looksLikeSourceCliRoot(root, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
@@ -249,8 +263,8 @@ export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
fileURLToPath(new URL("./child-process-hide.mjs", import.meta.url)),
|
||||
"utf8",
|
||||
);
|
||||
nodeFs.writeFileSync(facadeSide, facadeSrc, "utf8");
|
||||
nodeFs.writeFileSync(side, hideConsoleEntrySource(), "utf8");
|
||||
writeHostFileAtomic(nodeFs, facadeSide, facadeSrc);
|
||||
writeHostFileAtomic(nodeFs, side, hideConsoleEntrySource());
|
||||
|
||||
let text = nodeFs.readFileSync(binJs, "utf8");
|
||||
if (text.includes(IMPORT_MARK) && text.includes(IMPORT_LINE.split(" //")[0])) {
|
||||
@@ -266,7 +280,7 @@ export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
} else {
|
||||
text = IMPORT_LINE + "\n" + text;
|
||||
}
|
||||
nodeFs.writeFileSync(binJs, text, "utf8");
|
||||
writeHostFileAtomic(nodeFs, binJs, text);
|
||||
return "injected";
|
||||
}
|
||||
|
||||
@@ -286,7 +300,7 @@ export function revertHideConsoleFromBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
const text = nodeFs.readFileSync(binJs, "utf8");
|
||||
const next = text.replace(/^import "\.\/dsh-purge-hide-console\.js";.*\r?\n/gm, "");
|
||||
if (next !== text) {
|
||||
nodeFs.writeFileSync(binJs, next, "utf8");
|
||||
writeHostFileAtomic(nodeFs, binJs, next);
|
||||
changed = true;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user