dsh-blue-team-mode 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,13 +52,13 @@ dsh plugin --profile desktop add dsh-blue-team-mode
52
52
  plugin_manager action=install_bundle target="dsh-blue-team-mode"
53
53
  ```
54
54
 
55
- 包名 `dsh-blue-team-mode`,当前版本 `1.2.0`;`dsh.bundle` 指向包内的 `cordis.patch.yml`。npm 安装不需要 `allowBuilds`,也不依赖本机源码目录。
55
+ 包名 `dsh-blue-team-mode`,当前版本 `1.3.1`;`dsh.bundle` 指向包内的 `cordis.patch.yml`。npm 安装不需要 `allowBuilds`,也不依赖本机源码目录。
56
56
 
57
57
  ### 从本地 tarball 安装
58
58
 
59
59
  ```sh
60
60
  npm pack --pack-destination dist
61
- dsh plugin --profile desktop add .\dist\dsh-blue-team-mode-1.2.0.tgz
61
+ dsh plugin --profile desktop add .\dist\dsh-blue-team-mode-1.3.1.tgz
62
62
  ```
63
63
 
64
64
  ### 从本地目录安装
@@ -187,6 +187,30 @@ blue_defense_selfcheck phrase="防御自检"
187
187
 
188
188
  详见 `skills/honeypot-tarpit.md`。
189
189
 
190
+ ## 可选诱饵程序
191
+
192
+ 包内自带一个独立、手动启动的 HTTP 诱饵程序:
193
+
194
+ ```powershell
195
+ node scripts/decoy-server.mjs --host 127.0.0.1 --port 8080
196
+ ```
197
+
198
+ npm 安装后:
199
+
200
+ ```powershell
201
+ npx --yes --package dsh-blue-team-mode dsh-blue-decoy --host 127.0.0.1 --port 8080
202
+ ```
203
+
204
+ 默认只监听本机;公开/内网监听必须显式:
205
+
206
+ ```powershell
207
+ node scripts/decoy-server.mjs --host 0.0.0.0 --port 8080 --allow-public
208
+ ```
209
+
210
+ 提供 `/admin`、`/.git/config`、`/phpmyadmin`、`/backup.sql`、`/shell.php` 等静态假路径;`/shell.php` 只返回文本,不执行。事件写 `$DSH_HOME/blue/decoy-events.jsonl`,不主动外传;body 中的 password/token/secret/cookie 会脱敏。不会自动启动,是否部署由用户决定。
211
+
212
+ 详见 `skills/decoy-server.md`。
213
+
190
214
  ---
191
215
 
192
216
  ## 独立控制台(右侧常驻面板)
@@ -339,7 +363,7 @@ Host 半侧通过 `POST /blue/api` 提供同源 JSON 桥接(Origin/Host 校验
339
363
  | 工具 | 作用 |
340
364
  | --- | --- |
341
365
  | `blue_timeline` | 记录/查看事件时间线 |
342
- | `blue_playbook_list` | 列出 18 个随包蓝队技能 |
366
+ | `blue_playbook_list` | 列出 19 个随包蓝队技能 |
343
367
  | `blue_log_scan` | 日志/文本攻击特征 + IOC 扫描 |
344
368
  | `blue_artifact_triage` | 样本只读初筛:哈希/类型/熵/字符串/可疑 API |
345
369
  | `blue_hardening_check` | 本机加固基线快检(端口/防火墙/账号/SSH/审计) |
@@ -433,9 +457,9 @@ node scripts/check-compliance.mjs --selftest
433
457
 
434
458
  ---
435
459
 
436
- ## 随包技能(18 个)
460
+ ## 随包技能(19 个)
437
461
 
438
- `blue-setup`、`incident-response`、`log-analysis`、`webshell-hunt`、`threat-hunting`、`host-forensics`、`memory-forensics`、`malware-triage`、`network-forensics`、`hardening`、`ioc-management`、`ctf-defense`、`reporting`、`containment`、`web-attack-triage`、`cloud-k8s-defense`、`deception-defense`、`honeypot-tarpit`。
462
+ `blue-setup`、`incident-response`、`log-analysis`、`webshell-hunt`、`threat-hunting`、`host-forensics`、`memory-forensics`、`malware-triage`、`network-forensics`、`hardening`、`ioc-management`、`ctf-defense`、`reporting`、`containment`、`web-attack-triage`、`cloud-k8s-defense`、`deception-defense`、`honeypot-tarpit`、`decoy-server`。
439
463
 
440
464
  技能同步到 `$DSH_HOME/blue/skills`,由预设的 `skill-filesystem` 发现;用户自己的 `$DSH_HOME/skills` 优先级更高,可覆盖同名技能。
441
465
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-blue-team-mode",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "CTF 网络攻防蓝队防御模式:资产盘点、告警研判、威胁狩猎、应急响应、取证分析与加固修复,内置 SQLite 事实库、独立右侧栏控制台与自主任务派发队列。",
5
5
  "license": "MIT",
6
6
  "author": "FGCGDroid",
@@ -41,10 +41,14 @@
41
41
  "validate": "node scripts/validate.mjs",
42
42
  "check": "node scripts/check-compliance.mjs --selftest",
43
43
  "hooks": "node scripts/install-hooks.mjs",
44
+ "test:decoy": "node scripts/test-decoy-server.mjs",
44
45
  "test:e2e": "node scripts/test-ui-e2e.mjs",
45
- "test": "node scripts/test-tools.mjs && node scripts/test-ui.mjs",
46
+ "test": "node scripts/test-tools.mjs && node scripts/test-ui.mjs && node scripts/test-decoy-server.mjs",
46
47
  "prepack": "node scripts/build.mjs"
47
48
  },
49
+ "bin": {
50
+ "dsh-blue-decoy": "scripts/decoy-server.mjs"
51
+ },
48
52
  "publishConfig": {
49
53
  "access": "public"
50
54
  },
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dsh-blue-team-mode 的可选蜜罐/诱饵 HTTP 服务。
4
+ *
5
+ * 默认只监听 127.0.0.1;公开监听必须显式加 --allow-public。
6
+ * 只返回静态假页面和有界合成数据,不执行 shell、不抓指纹、不做无限响应。
7
+ * 事件只写本地 JSONL,不主动外传。
8
+ */
9
+ import { createServer } from 'node:http'
10
+ import { appendFileSync, mkdirSync } from 'node:fs'
11
+ import { homedir } from 'node:os'
12
+ import { dirname, join } from 'node:path'
13
+ import { randomUUID } from 'node:crypto'
14
+
15
+ const VERSION = '1.0.0'
16
+ const MAX_BODY = 64 * 1024
17
+ const RATE_WINDOW_MS = 60_000
18
+ const RATE_LIMIT = 60
19
+
20
+ function parseArgs(argv) {
21
+ const options = {
22
+ host: '127.0.0.1',
23
+ port: 8080,
24
+ log: join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'blue', 'decoy-events.jsonl'),
25
+ allowPublic: false,
26
+ name: 'decoy-http',
27
+ help: false,
28
+ }
29
+ for (let i = 0; i < argv.length; i += 1) {
30
+ const arg = argv[i]
31
+ if (arg === '--help' || arg === '-h') options.help = true
32
+ else if (arg === '--allow-public') options.allowPublic = true
33
+ else if (arg === '--host') options.host = String(argv[++i] || options.host)
34
+ else if (arg === '--port') options.port = Number(argv[++i] || options.port)
35
+ else if (arg === '--log') options.log = String(argv[++i] || options.log)
36
+ else if (arg === '--name') options.name = String(argv[++i] || options.name)
37
+ else if (arg === '--version' || arg === '-v') {
38
+ console.log(VERSION)
39
+ process.exit(0)
40
+ } else {
41
+ throw new Error('未知参数:' + arg)
42
+ }
43
+ }
44
+ return options
45
+ }
46
+
47
+ function isLoopback(host) {
48
+ return host === '127.0.0.1' || host === '::1' || host === 'localhost'
49
+ }
50
+
51
+ function text(res, status, body, type = 'text/plain; charset=utf-8') {
52
+ const data = Buffer.from(body, 'utf8')
53
+ res.writeHead(status, {
54
+ 'content-type': type,
55
+ 'content-length': data.length,
56
+ 'server': 'nginx',
57
+ 'x-content-type-options': 'nosniff',
58
+ })
59
+ res.end(data)
60
+ }
61
+
62
+ function fakeAdmin() {
63
+ return '<!doctype html><html><head><title>Admin Console</title></head><body>'
64
+ + '<h1>Internal Admin</h1><form method="post" action="/admin/login">'
65
+ + '<input name="username" placeholder="username"><input name="password" type="password" placeholder="password">'
66
+ + '<button>Sign in</button></form><p>Build 2026.11</p></body></html>'
67
+ }
68
+
69
+ function fakeGitConfig() {
70
+ return '[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = false\n'
71
+ + '[remote "origin"]\n\turl = git@internal.example.invalid:ops/backup.git\n'
72
+ + '[branch "main"]\n\tremote = origin\n\tmerge = refs/heads/main\n'
73
+ }
74
+
75
+ function fakePhpMyAdmin() {
76
+ return '<!doctype html><html><head><title>phpMyAdmin</title></head><body>'
77
+ + '<h1>phpMyAdmin</h1><form method="post"><input name="pma_username"><input name="pma_password" type="password">'
78
+ + '<button>Log in</button></form></body></html>'
79
+ }
80
+
81
+ function syntheticSql() {
82
+ const header = '-- synthetic decoy data; not a real backup\n'
83
+ let body = header
84
+ for (let i = 0; body.length < 48 * 1024; i += 1) {
85
+ body += `INSERT INTO audit_log_${i % 7} VALUES (${i}, '${randomUUID()}', 'synthetic');\n`
86
+ }
87
+ return body
88
+ }
89
+
90
+ function notFound() {
91
+ return '<html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1><hr>nginx</body></html>'
92
+ }
93
+
94
+ /** 诱饵日志只保留攻击载荷;不把口令、token、Cookie 等凭据原样写盘。 */
95
+ function redactBody(value) {
96
+ return String(value || '').slice(0, 2000)
97
+ .replace(/((?:password|passwd|pwd|token|secret|authorization|cookie|session)[^=:&\s]*\s*[=:]\s*)([^&\s"']+)/gi, '$1[REDACTED]')
98
+ }
99
+
100
+ const server = createServer((req, res) => {
101
+ const started = Date.now()
102
+ const remote = req.socket.remoteAddress || ''
103
+ const now = Date.now()
104
+ const bucket = rate.get(remote)
105
+ if (bucket === undefined || now - bucket.start > RATE_WINDOW_MS) {
106
+ rate.set(remote, { start: now, count: 1 })
107
+ } else {
108
+ bucket.count += 1
109
+ if (bucket.count > RATE_LIMIT) {
110
+ text(res, 429, 'Too Many Requests')
111
+ record(req, remote, 429, '', started)
112
+ return
113
+ }
114
+ }
115
+
116
+ const url = new URL(req.url || '/', 'http://decoy.invalid')
117
+ let body = ''
118
+ let tooLarge = false
119
+ req.on('data', (chunk) => {
120
+ if (tooLarge) return
121
+ body += chunk.toString('utf8')
122
+ if (Buffer.byteLength(body) > MAX_BODY) {
123
+ tooLarge = true
124
+ body = body.slice(0, MAX_BODY)
125
+ }
126
+ })
127
+ req.on('end', () => {
128
+ if (tooLarge) {
129
+ text(res, 413, 'Payload Too Large')
130
+ record(req, remote, 413, body, started)
131
+ return
132
+ }
133
+ const path = url.pathname
134
+ if (req.method === 'GET' && (path === '/admin' || path === '/admin/' || path === '/wp-login.php')) {
135
+ text(res, 200, fakeAdmin(), 'text/html; charset=utf-8')
136
+ } else if (req.method === 'GET' && path === '/.git/config') {
137
+ text(res, 200, fakeGitConfig())
138
+ } else if (req.method === 'GET' && (path === '/phpmyadmin' || path === '/phpmyadmin/')) {
139
+ text(res, 200, fakePhpMyAdmin(), 'text/html; charset=utf-8')
140
+ } else if (req.method === 'GET' && path === '/backup.sql') {
141
+ text(res, 200, syntheticSql(), 'application/sql; charset=utf-8')
142
+ } else if (req.method === 'GET' && path === '/shell.php') {
143
+ // 静态假页面:绝不执行、不解析、不回连。
144
+ text(res, 200, '<?php echo "synthetic decoy"; ?>', 'text/plain; charset=utf-8')
145
+ } else if (req.method === 'GET' && path === '/server-status') {
146
+ text(res, 200, 'Server Status: synthetic decoy')
147
+ } else {
148
+ text(res, 404, notFound(), 'text/html; charset=utf-8')
149
+ }
150
+ record(req, remote, res.statusCode, body, started, url)
151
+ })
152
+ })
153
+
154
+ const rate = new Map()
155
+
156
+ function record(req, remote, status, body, started, url = new URL(req.url || '/', 'http://decoy.invalid')) {
157
+ const event = {
158
+ at: new Date().toISOString(),
159
+ decoy: options.name,
160
+ remote,
161
+ method: req.method,
162
+ path: url.pathname,
163
+ query: url.search,
164
+ user_agent: String(req.headers['user-agent'] || '').slice(0, 300),
165
+ referer: String(req.headers.referer || '').slice(0, 300),
166
+ body: redactBody(body),
167
+ status,
168
+ elapsed_ms: Date.now() - started,
169
+ }
170
+ try {
171
+ mkdirSync(dirname(options.log), { recursive: true })
172
+ appendFileSync(options.log, JSON.stringify(event) + '\n')
173
+ } catch (error) {
174
+ console.error('日志写入失败:' + error.message)
175
+ }
176
+ }
177
+
178
+ let options
179
+ try {
180
+ options = parseArgs(process.argv.slice(2))
181
+ } catch (error) {
182
+ console.error(error.message)
183
+ process.exit(2)
184
+ }
185
+
186
+ if (options.help) {
187
+ console.log(`dsh-blue-decoy ${VERSION}
188
+ 用法:node scripts/decoy-server.mjs [选项]
189
+ --host <addr> 监听地址,默认 127.0.0.1
190
+ --port <port> 监听端口,默认 8080
191
+ --log <path> JSONL 日志路径,默认 $DSH_HOME/blue/decoy-events.jsonl
192
+ --name <name> 诱饵名称
193
+ --allow-public 允许非 loopback 监听(公开暴露前先评估)
194
+ --help 显示帮助`)
195
+ process.exit(0)
196
+ }
197
+
198
+ if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65535) {
199
+ console.error('端口无效')
200
+ process.exit(2)
201
+ }
202
+ if (!isLoopback(options.host) && !options.allowPublic) {
203
+ console.error('拒绝公开监听:请先确认授权和防火墙,再加 --allow-public')
204
+ process.exit(2)
205
+ }
206
+
207
+ server.listen(options.port, options.host, () => {
208
+ const address = server.address()
209
+ const host = options.host.includes(':') ? `[${options.host}]` : options.host
210
+ console.log(`listening http://${host}:${address.port}`)
211
+ console.log(`log ${options.log}`)
212
+ })
213
+
214
+ process.on('SIGINT', () => {
215
+ server.close(() => process.exit(0))
216
+ })
217
+ process.on('SIGTERM', () => {
218
+ server.close(() => process.exit(0))
219
+ })
@@ -0,0 +1,87 @@
1
+ import { spawn } from 'node:child_process'
2
+ import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { setTimeout as sleep } from 'node:timers/promises'
7
+
8
+ const root = mkdtempSync(join(tmpdir(), 'blue-decoy-'))
9
+ const log = join(root, 'events.jsonl')
10
+ const serverPath = fileURLToPath(new URL('./decoy-server.mjs', import.meta.url))
11
+
12
+ function start(args) {
13
+ return spawn(process.execPath, [serverPath, ...args], {
14
+ stdio: ['ignore', 'pipe', 'pipe'],
15
+ })
16
+ }
17
+
18
+ function waitForUrl(child) {
19
+ return new Promise((resolve, reject) => {
20
+ let output = ''
21
+ const timer = setTimeout(() => reject(new Error('启动超时:' + output)), 5000)
22
+ child.stdout.on('data', (chunk) => {
23
+ output += chunk.toString('utf8')
24
+ const match = output.match(/listening (http:\/\/[^\s]+)/)
25
+ if (match) {
26
+ clearTimeout(timer)
27
+ resolve(match[1])
28
+ }
29
+ })
30
+ child.stderr.on('data', (chunk) => { output += chunk.toString('utf8') })
31
+ child.on('exit', (code) => {
32
+ clearTimeout(timer)
33
+ reject(new Error('服务提前退出:' + code + ' ' + output))
34
+ })
35
+ })
36
+ }
37
+
38
+ let child
39
+ try {
40
+ child = start(['--port', '0', '--log', log, '--name', 'test-decoy'])
41
+ const base = await waitForUrl(child)
42
+ const admin = await fetch(base + '/admin')
43
+ const adminText = await admin.text()
44
+ if (admin.status !== 200 || !adminText.includes('Internal Admin')) throw new Error('假管理页失败')
45
+
46
+ const git = await fetch(base + '/.git/config')
47
+ const gitText = await git.text()
48
+ if (git.status !== 200 || !gitText.includes('repositoryformatversion')) throw new Error('假 .git 失败')
49
+
50
+ const backup = await fetch(base + '/backup.sql')
51
+ const backupText = await backup.text()
52
+ if (backup.status !== 200 || backupText.length < 1024 || backupText.length > 128 * 1024) throw new Error('合成备份大小异常')
53
+
54
+ const shell = await fetch(base + '/shell.php')
55
+ const shellText = await shell.text()
56
+ if (shell.status !== 200 || !shellText.includes('synthetic decoy') || shellText.includes('exec')) throw new Error('假 shell 不应执行')
57
+
58
+ await fetch(base + '/admin', {
59
+ method: 'POST',
60
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
61
+ body: 'username=admin&password=SuperSecret123&token=abc123',
62
+ })
63
+
64
+ const missing = await fetch(base + '/random-path')
65
+ if (missing.status !== 404) throw new Error('未知路径应 404')
66
+
67
+ await sleep(100)
68
+ const logText = readFileSync(log, 'utf8')
69
+ if (logText.includes('SuperSecret123') || logText.includes('abc123')) throw new Error('日志泄露口令/token')
70
+ if (!logText.includes('[REDACTED]')) throw new Error('日志未标记脱敏')
71
+ const lines = logText.trim().split(/\r?\n/).filter(Boolean)
72
+ if (lines.length < 4) throw new Error('事件日志不足:' + lines.length)
73
+ const event = JSON.parse(lines[0])
74
+ if (event.decoy !== 'test-decoy' || !event.remote || !event.path) throw new Error('事件字段不完整')
75
+
76
+ child.kill('SIGTERM')
77
+ child = null
78
+
79
+ const blocked = start(['--host', '0.0.0.0', '--port', '0', '--log', join(root, 'blocked.jsonl')])
80
+ const exitCode = await new Promise((resolve) => blocked.on('exit', resolve))
81
+ if (exitCode !== 2) throw new Error('公开监听未要求 --allow-public')
82
+
83
+ console.log('✓ 诱饵服务测试通过:假路径/有界数据/本地日志/公开监听保护')
84
+ } finally {
85
+ if (child) child.kill('SIGTERM')
86
+ rmSync(root, { recursive: true, force: true })
87
+ }
@@ -87,7 +87,7 @@ check(workerText.includes('__ROLE_TITLE__') && workerText.includes('__ROLE_PROFI
87
87
  }
88
88
 
89
89
  const skills = readdirSync(join(root, 'skills')).filter((file) => file.endsWith('.md'))
90
- check(skills.length === 18, '技能数量 = 18(实际 ' + skills.length + ')')
90
+ check(skills.length === 19, '技能数量 = 19(实际 ' + skills.length + ')')
91
91
  for (const file of skills) {
92
92
  const text = readFileSync(join(root, 'skills', file), 'utf8')
93
93
  check(/^---\r?\n/.test(text) && /^name:/m.test(text) && /^description:/m.test(text), file + ' 有 frontmatter')
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: decoy-server
3
+ description: 可选的本地/授权资产 HTTP 诱饵程序:静态假管理页、假 .git、假 phpMyAdmin、合成 SQL、假 shell 文本;只写本地 JSONL,不执行命令、不抓指纹。
4
+ ---
5
+
6
+ # 可选诱饵程序
7
+
8
+ ## 启动
9
+
10
+ 在插件目录:
11
+
12
+ ```bash
13
+ node scripts/decoy-server.mjs --host 127.0.0.1 --port 8080
14
+ ```
15
+
16
+ 安装为 npm 包后:
17
+
18
+ ```bash
19
+ npx --yes --package dsh-blue-team-mode dsh-blue-decoy --host 127.0.0.1 --port 8080
20
+ ```
21
+
22
+ 默认只监听 `127.0.0.1`。对公网/内网资产监听必须显式:
23
+
24
+ ```bash
25
+ node scripts/decoy-server.mjs --host 0.0.0.0 --port 8080 --allow-public
26
+ ```
27
+
28
+ 启动前确认:
29
+
30
+ - 目标在授权防守范围内
31
+ - 防火墙只放行需要暴露的端口
32
+ - 不要覆盖真实业务端口
33
+ - 公开前先看 `--help`
34
+
35
+ ## 提供的假路径
36
+
37
+ - `/admin`、`/wp-login.php`:假管理页
38
+ - `/.git/config`:假 git 配置
39
+ - `/phpmyadmin`:假 phpMyAdmin
40
+ - `/backup.sql`:有界合成 SQL(约 48KB)
41
+ - `/shell.php`:静态假文本,不执行、不回连
42
+ - `/server-status`:假状态页
43
+ - 其他路径:404
44
+
45
+ ## 日志
46
+
47
+ 默认写入:
48
+
49
+ ```text
50
+ $DSH_HOME/blue/decoy-events.jsonl
51
+ ```
52
+
53
+ 每条 JSON 包含时间、来源、方法、路径、UA、脱敏 body、状态码、耗时。不会记录 Cookie/Authorization;body 中的 password/token/secret/cookie 等字段会替换为 `[REDACTED]`,不抓 WebRTC/Canvas/硬件指纹。
54
+
55
+ 把事件交给 Agent:
56
+
57
+ ```text
58
+ 读取 decoy-events.jsonl,把命中事件用 blue_honeypot_ingest 落库
59
+ ```
60
+
61
+ `blue_honeypot_ingest` 会生成告警和 high 风险待审批封禁任务,不会自动改防火墙。
62
+
63
+ ## 不做
64
+
65
+ - 不执行 PHP/Shell/命令
66
+ - 不返回无限/10GB 响应
67
+ - 不做真实反弹 Shell
68
+ - 不收集浏览器指纹或真实身份信息
69
+ - 不自动封禁
70
+ - 不主动外传日志