mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 11:20: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
+101
-22
@@ -664,11 +664,34 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
try { return String(window.location.hash || '') === '#redteam-full' } catch { return false }
|
||||
}
|
||||
|
||||
const api = (req) => fetch('/redteam/api', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify(req),
|
||||
}).then((res) => res.json())
|
||||
/* 与宿主半侧其它接口同一套约定:有超时、判 res.ok、非 JSON 响应给出可读错误。
|
||||
直接 res.json() 时后端回 HTML/空体只会抛 "Unexpected token '<'",状态码也丢了。 */
|
||||
const API_TIMEOUT_MS = 120000
|
||||
const api = (req) => {
|
||||
const ctrl = new AbortController()
|
||||
const timer = setTimeout(() => ctrl.abort(), API_TIMEOUT_MS)
|
||||
return fetch('/redteam/api', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify(req),
|
||||
signal: ctrl.signal,
|
||||
})
|
||||
.then((res) => res.text().then((text) => {
|
||||
let data = null
|
||||
try { data = text ? JSON.parse(text) : null } catch { throw new Error(res.status + ' non-json: ' + text.slice(0, 120)) }
|
||||
if (!res.ok) throw new Error((data && data.error) || (res.status + ' ' + res.statusText))
|
||||
return data
|
||||
}))
|
||||
.finally(() => clearTimeout(timer))
|
||||
}
|
||||
/* 每次加载取号,异步回来先比号:切靶标后旧响应直接丢弃,别盖掉新靶标的数据。 */
|
||||
const useLoadSeq = () => {
|
||||
const ref = React.useRef(0)
|
||||
return {
|
||||
take: () => ++ref.current,
|
||||
live: (my) => my === ref.current,
|
||||
}
|
||||
}
|
||||
|
||||
let ui = { open: true, tab: 'assets' }
|
||||
const subs = new Set()
|
||||
@@ -708,15 +731,30 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
'vuln-scan': '漏洞发现', exploit: '漏洞利用', internal: '内网渗透',
|
||||
}
|
||||
|
||||
const fmt = (s) => (s ? String(s).replace('T', ' ').slice(0, 16) : '—')
|
||||
/* 服务端时间一律是 toISOString()(UTC),直接截串会让东八区早 8 小时。 */
|
||||
const pad2 = (n) => String(n).padStart(2, '0')
|
||||
const asLocal = (s) => {
|
||||
const d = new Date(s)
|
||||
return Number.isNaN(d.getTime()) ? null : d
|
||||
}
|
||||
const fmt = (s) => {
|
||||
if (!s) return '—'
|
||||
const d = asLocal(s)
|
||||
if (d === null) return String(s).replace('T', ' ').slice(0, 16)
|
||||
return d.getFullYear() + '-' + pad2(d.getMonth() + 1) + '-' + pad2(d.getDate())
|
||||
+ ' ' + pad2(d.getHours()) + ':' + pad2(d.getMinutes())
|
||||
}
|
||||
const shotCache = new Map()
|
||||
const shotLoading = new Map()
|
||||
/* base64 常驻内存:只留最近 200 张,避免跨靶标无限累积。 */
|
||||
const SHOT_CACHE_LIMIT = 200
|
||||
const shotSrc = (eng, id) => shotCache.get(eng + ':' + id) || null
|
||||
const loadShot = (eng, id) => {
|
||||
const key = eng + ':' + id
|
||||
if (shotCache.has(key) || shotLoading.has(key)) return
|
||||
const p = api({ op: 'shotData', engagement: eng, id: id }).then((r) => {
|
||||
shotCache.set(key, r && r.base64 ? 'data:' + (r.mime || 'image/png') + ';base64,' + r.base64 : '')
|
||||
while (shotCache.size > SHOT_CACHE_LIMIT) shotCache.delete(shotCache.keys().next().value)
|
||||
shotLoading.delete(key)
|
||||
const snap = Object.assign({}, ui)
|
||||
for (const f of Array.from(subs)) {
|
||||
@@ -729,7 +767,8 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const ShotImage = ({ eng, shot, height }) => {
|
||||
const [zoom, setZoom] = React.useState(false)
|
||||
const src = shotSrc(eng, shot.id)
|
||||
if (src === null) { loadShot(eng, shot.id); }
|
||||
/* 拉图放在 effect 里:render 期间发请求 + 写外部 store 会让同一帧重复触发。 */
|
||||
React.useEffect(() => { if (src === null) loadShot(eng, shot.id) }, [eng, shot.id, src])
|
||||
const card = shot.kind === 'card'
|
||||
return h('div', { className: 'rt-shot' },
|
||||
src === null
|
||||
@@ -766,8 +805,14 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
}
|
||||
/** 发现时间在列表里只留「月-日 时:分」:整行宽度紧张,完整时间进悬浮提示 */
|
||||
const fmtShort = (s) => {
|
||||
const t = String(s || '').replace('T', ' ')
|
||||
return t.length >= 16 ? t.slice(5, 16) : (t || '—')
|
||||
if (!s) return '—'
|
||||
const d = asLocal(s)
|
||||
if (d === null) {
|
||||
const t = String(s).replace('T', ' ')
|
||||
return t.length >= 16 ? t.slice(5, 16) : t
|
||||
}
|
||||
return pad2(d.getMonth() + 1) + '-' + pad2(d.getDate())
|
||||
+ ' ' + pad2(d.getHours()) + ':' + pad2(d.getMinutes())
|
||||
}
|
||||
const provLabel = (p) => (p === 'passive' ? '被动' : p === 'active' ? '主动' : '未知')
|
||||
|
||||
@@ -1258,12 +1303,17 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const [data, setData] = React.useState(null)
|
||||
const [err, setErr] = React.useState(null)
|
||||
const [day, setDay] = React.useState('')
|
||||
const seq = useLoadSeq()
|
||||
React.useEffect(() => {
|
||||
if (!eng) return
|
||||
const my = seq.take()
|
||||
setData(null)
|
||||
api({ op: 'discoveryTimeline', engagement: eng, limit: 200 })
|
||||
.then((r) => { if (!r || r.ok === false) setErr((r && r.error) || '加载失败'); else { setErr(null); setData(r) } },
|
||||
(e) => setErr(String((e && e.message) || e)))
|
||||
.then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
if (!r || r.ok === false) setErr((r && r.error) || '加载失败')
|
||||
else { setErr(null); setData(r) }
|
||||
}, (e) => { if (seq.live(my)) setErr(String((e && e.message) || e)) })
|
||||
}, [eng, refreshKey])
|
||||
if (err) return h('div', { className: 'rt-pane' }, h('div', { className: 'rt-err' }, err))
|
||||
if (!data) return h('div', { className: 'rt-empty' }, '加载中…')
|
||||
@@ -1314,14 +1364,17 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const [msg, setMsg] = React.useState(null)
|
||||
const [busy, setBusy] = React.useState(false)
|
||||
|
||||
const seq = useLoadSeq()
|
||||
React.useEffect(() => {
|
||||
/* 无靶标也允许:服务端回内置默认,不再报 engagement required */
|
||||
const my = seq.take()
|
||||
api(eng ? { op: 'prompts', engagement: eng } : { op: 'prompts' }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
if (!r || r.ok === false) { setMsg({ err: (r && r.error) || '读取失败' }); return }
|
||||
setRoles(r.roles || [])
|
||||
if (r.roles && r.roles.length) setActive((cur) => cur || r.roles[0].role)
|
||||
if (r.builtin) setMsg({ ok: '当前为内置默认提示词(创建靶标后可按靶标保存修改)' })
|
||||
}, (e) => setMsg({ err: String((e && e.message) || e) }))
|
||||
}, (e) => { if (seq.live(my)) setMsg({ err: String((e && e.message) || e) }) })
|
||||
}, [eng, refreshKey])
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -1897,7 +1950,8 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
|
||||
return h('div', { className: 'rt-main' }, toolbar, conclusion,
|
||||
h('div', { className: 'rt-subtabs' },
|
||||
subTabBtn('vulns', '漏洞', state.total || 0),
|
||||
/* 用实际渲染条数:total 是服务端 COUNT(*),列表被 limit 截断时两者对不上。 */
|
||||
subTabBtn('vulns', '漏洞', (state.items || []).length),
|
||||
subTabBtn('files', '攻击文件', allFiles.length),
|
||||
subTabBtn('creds', '凭据', creds.length),
|
||||
subTabBtn('access', '访问会话', accesses.length),
|
||||
@@ -1951,14 +2005,17 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const [view, setView] = React.useState('A')
|
||||
const [openId, setOpenId] = React.useState(null)
|
||||
|
||||
const seq = useLoadSeq()
|
||||
const load = () => {
|
||||
if (!eng) return
|
||||
const my = seq.take()
|
||||
setLoading(true)
|
||||
api({ op: 'scoreChain', engagement: eng }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
setLoading(false)
|
||||
if (!r || r.ok === false) { setErr((r && r.error) || '读取失败'); return }
|
||||
setErr(null); setData(r)
|
||||
}, (e) => { setLoading(false); setErr(String((e && e.message) || e)) })
|
||||
}, (e) => { if (!seq.live(my)) return; setLoading(false); setErr(String((e && e.message) || e)) })
|
||||
}
|
||||
React.useEffect(load, [eng, refreshKey])
|
||||
|
||||
@@ -2157,21 +2214,28 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
/* 报告按阶段折叠:默认全开,折叠状态按靶标记住(阶段多时便于逐段交付) */
|
||||
const collapse = useCollapse('report:' + eng)
|
||||
|
||||
const seq = useLoadSeq()
|
||||
const load = () => {
|
||||
if (!eng) return
|
||||
const my = seq.take()
|
||||
setBusy(true); setMsg(null)
|
||||
api({ op: 'scoreReport', engagement: eng }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
if (!r || r.ok === false) { setBusy(false); setErr((r && r.error) || '生成失败'); return }
|
||||
/* 老 host 只给平铺条目、不给阶段分组(或阶段行缺失):自己按攻击链分组,
|
||||
否则报告页会误报"还没有可交付的成果"。分组数据取自 scoreChain。 */
|
||||
if ((!r.stages || r.stages.length === 0) && (r.items || []).length > 0) {
|
||||
api({ op: 'scoreChain', engagement: eng }).then((c) => {
|
||||
if (!seq.live(my)) return
|
||||
setBusy(false); setErr(null); setData(Object.assign({}, r, { stages: groupByStage(r.items, c) }))
|
||||
}, () => { setBusy(false); setErr(null); setData(r) })
|
||||
}, () => {
|
||||
if (!seq.live(my)) return
|
||||
setBusy(false); setErr(null); setData(r)
|
||||
})
|
||||
return
|
||||
}
|
||||
setBusy(false); setErr(null); setData(r)
|
||||
}, (e) => { setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
}, (e) => { if (!seq.live(my)) return; setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
}
|
||||
React.useEffect(load, [eng, refreshKey])
|
||||
|
||||
@@ -2379,15 +2443,18 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const collapse = useCollapse('files:' + eng)
|
||||
const [detail, setDetail] = React.useState(null)
|
||||
|
||||
const seq = useLoadSeq()
|
||||
const load = () => {
|
||||
if (!eng) return
|
||||
const my = seq.take()
|
||||
setBusy(true)
|
||||
api({ op: 'attackFiles', engagement: eng }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
setBusy(false)
|
||||
if (!r || r.ok === false) { setErr((r && r.error) || '读取失败'); return }
|
||||
setErr(null)
|
||||
setFolders(r.items || [])
|
||||
}, (e) => { setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
}, (e) => { if (!seq.live(my)) return; setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
}
|
||||
React.useEffect(load, [eng, refreshKey])
|
||||
|
||||
@@ -2936,15 +3003,18 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const [form, setForm] = React.useState(null)
|
||||
const [msg, setMsg] = React.useState(null)
|
||||
|
||||
const seq = useLoadSeq()
|
||||
const load = () => {
|
||||
if (!eng) return
|
||||
const my = seq.take()
|
||||
setBusy(true)
|
||||
api({ op: 'scores', engagement: eng }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
setBusy(false)
|
||||
if (!r || r.ok === false) { setErr((r && r.error) || '读取失败'); return }
|
||||
setErr(null)
|
||||
setData(r)
|
||||
}, (e) => { setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
}, (e) => { if (!seq.live(my)) return; setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
}
|
||||
React.useEffect(load, [eng, refreshKey])
|
||||
|
||||
@@ -2993,7 +3063,7 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
}, (e) => { setBusy(false); setMsg({ err: String((e && e.message) || e) }) })
|
||||
}
|
||||
|
||||
const summary = (data && data.summary) || { achievedPoints: 0, pointCount: 0, hitPointCount: 0, hitCount: 0, selfCreatedHits: 0, serviceCappedHits: 0 }
|
||||
const summary = (data && data.summary) || { achievedPoints: 0, pointCount: 0, hitPointCount: 0, hitCount: 0, countedHits: 0, selfCreatedHits: 0, serviceCappedHits: 0 }
|
||||
const items = (data && data.items) || []
|
||||
|
||||
/* 按合并版的 8 个类别分组渲染(后端 ruleGroups 已排好序、组内按分值升序)。
|
||||
@@ -3308,7 +3378,9 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
}, (e) => { if (my === seq.current) setErr(String((e && e.message) || e)) })
|
||||
.finally(() => { if (my === seq.current) inflight.current = false })
|
||||
}
|
||||
React.useEffect(() => { seq.current += 1; load() }, [eng, refreshKey])
|
||||
/* 切靶标/刷新时把在途标记复位:旧请求的 finally 因序号不符不会清,
|
||||
不复位的话这里会永久早退,5 秒轮询也全空转。 */
|
||||
React.useEffect(() => { seq.current += 1; inflight.current = false; load() }, [eng, refreshKey])
|
||||
React.useEffect(() => {
|
||||
if (!eng || !auto) return undefined
|
||||
const timer = setInterval(load, 5000)
|
||||
@@ -3430,13 +3502,16 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const [msg, setMsg] = React.useState(null)
|
||||
const [copied, setCopied] = React.useState(null)
|
||||
|
||||
const seq = useLoadSeq()
|
||||
const load = () => {
|
||||
if (!eng) return
|
||||
const my = seq.take()
|
||||
api({ op: 'sessions', engagement: eng }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
if (!r || r.ok === false) { setErr((r && r.error) || '读取失败'); return }
|
||||
setErr(null)
|
||||
setData(r)
|
||||
}, (e) => setErr(String((e && e.message) || e)))
|
||||
}, (e) => { if (seq.live(my)) setErr(String((e && e.message) || e)) })
|
||||
}
|
||||
React.useEffect(load, [eng, refreshKey])
|
||||
|
||||
@@ -3671,16 +3746,20 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
const [concurrency, setConcurrency] = React.useState(null)
|
||||
const [busy, setBusy] = React.useState(false)
|
||||
|
||||
const seq = useLoadSeq()
|
||||
const load = () => {
|
||||
const my = seq.take()
|
||||
setBusy(true)
|
||||
api({ op: eng ? 'prompts' : 'bootstrap', engagement: eng || undefined }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
setBusy(false)
|
||||
if (!r || r.ok === false) { setErr((r && r.error) || '读取失败'); return }
|
||||
setErr(null)
|
||||
if (r.roles) setRoles(r.roles)
|
||||
}, (e) => { setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
}, (e) => { if (!seq.live(my)) return; setBusy(false); setErr(String((e && e.message) || e)) })
|
||||
/* 并发名额按"当前跑着的子智能体"算;host 侧读 subagents 注册表 */
|
||||
api({ op: 'agentsStatus' }).then((r) => {
|
||||
if (!seq.live(my)) return
|
||||
if (r && r.ok !== false) setConcurrency(r)
|
||||
}, () => {})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user