@kenhkl/agent-moss 0.16.13 → 0.17.0

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.
@@ -173,7 +173,8 @@
173
173
  "(?:cat|head|tail|less|more|grep)\\s+[^;&|\\n]*known_hosts",
174
174
  "\\bpython3?\\s+-c\\s+['\\\"][\\s\\S]{0,200}?(?:base64\\.b64encode|open\\s*\\(|Path\\(|io\\.open\\s*\\(|read_text\\s*\\(|read\\s*\\()[\\s\\S]{0,200}?(?:/etc/shadow|/etc/passwd|id_rsa|credentials|\\.ssh)",
175
175
  "(?:grep|find|cat)\\s+[^;&|\\n]*\\b(?:password|secret|passwd|shadow|credential|api[_-]?key)\\b[^;&|\\n]*(?:/etc/shadow|/etc/passwd|id_rsa|credentials|\\.ssh)",
176
- "(?:cp|mv|dd|curl)\\s+[^;&|\\n]*(?:/etc/shadow|/etc/passwd|id_rsa|credentials|\\.ssh)"
176
+ "(?:cp|mv|dd|curl)\\s+[^;&|\\n]*(?:/etc/shadow|/etc/passwd|id_rsa|credentials|\\.ssh)",
177
+ "(?:cat|head|tail|less|more|sed|awk|strings|base64|dd|cp|mv|grep|xxd|od)\\s+[^;&|\\n]*(?:\\.config/agentmoss/auth_token|\\.agentmoss/stateful_chains|agent_moss_policy_cache|agent_moss/rules|agent_moss/skills|agent_moss/agents/|agent_moss/scenarios/)"
177
178
  ],
178
179
  "PERSIST": [
179
180
  "(?:echo|printf|cat)\\b[^;\\n]*\\|[^;\\n]*(?:crontab|at\\b)\\s*-",
@@ -0,0 +1,73 @@
1
+ {
2
+ "_comment": "L2 逻辑规则的识别词表(Python engine/logic_rules.py ↔ TS engine/logic-rules.ts 单一事实源)。全部为子串匹配,被匹配文本先转小写。",
3
+ "_dir_traversal_note": "目录遍历词表不在这里:它复用 inline_rules.json 的 dir_traversal_keywords —— 两处原本就是逐字相同的 10 条,再放一份就是给自己造双份维护。",
4
+ "indirect_file_access": {
5
+ "_comment": "间接文件访问(Rule 4.5):内联脚本用目录遍历动态发现文件 + 读写/执行调用。四组词分别决定「有没有文件操作」和「是读还是写/执行」—— 写/执行时所有敏感文件都拦,只读时只拦凭据文件。",
6
+ "read_keywords": [
7
+ "read(",
8
+ "readline",
9
+ "readlines",
10
+ "fread",
11
+ "fgets",
12
+ "load(",
13
+ "getpass",
14
+ "file_get_contents"
15
+ ],
16
+ "write_keywords": [
17
+ "write(",
18
+ "writelines",
19
+ "fwrite",
20
+ "file_put_contents"
21
+ ],
22
+ "exec_keywords": [
23
+ "system(",
24
+ "exec(",
25
+ "eval(",
26
+ "popen(",
27
+ "os.system",
28
+ "os.popen",
29
+ "subprocess",
30
+ "os.exec",
31
+ "os.spawn",
32
+ "shell=true",
33
+ "check_output",
34
+ "check_call",
35
+ "run(",
36
+ "passthru",
37
+ "shell_exec",
38
+ "proc_open"
39
+ ],
40
+ "open_keywords": [
41
+ "open(",
42
+ "fopen("
43
+ ]
44
+ },
45
+ "_more": "另有几组「谁算写操作 / 谁算临时目录」的通用名单,原先散在 logic_rules.py 的三个函数里各写一份。",
46
+ "non_write_tool_prefixes": [
47
+ "memory-",
48
+ "skill-manager-",
49
+ "mailbox-",
50
+ "app-"
51
+ ],
52
+ "_non_write_tool_prefixes_comment": "写判定豁免的非写工具前缀(不含 skill-,与 heuristic 的敏感路径排除名单刻意差一项)。",
53
+ "write_commands": [
54
+ "cp",
55
+ "mv",
56
+ "install",
57
+ "tee",
58
+ "dd",
59
+ "truncate",
60
+ "mkfs",
61
+ "fdisk",
62
+ "parted"
63
+ ],
64
+ "_write_commands_comment": "写/删命令集合(逐段首词判定,供重定向/通配判定用)。",
65
+ "source_arg_commands": [
66
+ "cp",
67
+ "mv",
68
+ "install",
69
+ "rsync"
70
+ ],
71
+ "_source_arg_commands_comment": "第一个位置参数是「源文件」的命令:源在敏感目录 → 视为读取。",
72
+ "_reused": "不重复存的两组:① 写/删命令词边界正则 = platform_traits.json 的 write_command_res(逐字相同);② 工具排除前缀 = heuristic_rules.json 的 sensitive_excluded_prefixes(逐字相同);③ 临时目录名单 = heuristic_rules.json 的 temp_dirs(L1/L2 共用一份)。"
73
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_comment": "规则包清单。schema_version 是**契约**:引擎启动时按自己认识的版本校验,不匹配直接报错(不会'读不懂就当空')。结构有破坏性变更时才 +1;新增文件/新增可选键不用动。",
3
+ "schema_version": 1,
4
+ "name": "agent-moss-rules",
5
+ "description": "AgentMoss 内置规则包:L1/L2/L3 规则、平台特征、脚本与形式化引擎识别名单。契约与校验见 agent_moss/rules_contract.py。"
6
+ }
@@ -0,0 +1,389 @@
1
+ {
2
+ "_comment": [
3
+ "平台行为特征(Platform Traits)—— 双端共用的单一事实源。",
4
+ "Python: agent_moss/profiles/*.py ← rules_loader.load_platform_traits()",
5
+ "TS: ts/src/engine/platform-traits.ts ← rules-loader.loadPlatformTraits()",
6
+ "",
7
+ "这些不是『检测规则』而是『放行/豁免的边界』,直接决定判定的宽严,改动务必谨慎:",
8
+ " fully_safe_commands 首段命令命中 → 跳过 L2 + L3",
9
+ " readonly_sensitive_commands 首段命令命中 → 跳 L3,保留 L2(L1 敏感路径照常)",
10
+ " read_only_commands 命令词命中 → 重定向 > 视为输出而非写文件",
11
+ " write_command_res 命令词命中 → 视为写/删意图(词边界正则)",
12
+ " write_keywords / read_keywords 意图关键词(子串匹配,不加词边界)",
13
+ " safe_action_types action_type 命中 → 跳过 L2 + L3",
14
+ " readonly_sensitive_action_types action_type 命中 → 跳 L3,保留 L2",
15
+ "",
16
+ "macos / harmony 继承 linux(同为类 Unix 命令集),只写 inherits 即可。",
17
+ "列表类字段保持顺序(与源码一致);集合类字段(read_only_commands / safe_action_types /",
18
+ "readonly_sensitive_action_types)已按字典序排列 —— 仅做成员判断,顺序无语义。",
19
+ "改动后自查:python3 -m pytest tests/test_platform_traits.py"
20
+ ],
21
+ "_schema": 1,
22
+ "linux": {
23
+ "write_keywords": [
24
+ "write",
25
+ "写入",
26
+ "save",
27
+ "保存",
28
+ "modify",
29
+ "修改",
30
+ "update",
31
+ "更新",
32
+ "delete",
33
+ "删除",
34
+ "remove",
35
+ "移除",
36
+ "create",
37
+ "创建",
38
+ "append",
39
+ "追加",
40
+ "truncate",
41
+ "截断",
42
+ "overwrite",
43
+ "覆盖",
44
+ "replace",
45
+ "替换",
46
+ "edit"
47
+ ],
48
+ "read_keywords": [
49
+ "read",
50
+ "读取",
51
+ "cat",
52
+ "head",
53
+ "tail",
54
+ "less",
55
+ "more",
56
+ "view",
57
+ "查看",
58
+ "open",
59
+ "打开",
60
+ "load",
61
+ "加载",
62
+ "grep",
63
+ "search",
64
+ "搜索",
65
+ "find",
66
+ "查找"
67
+ ],
68
+ "write_command_res": [
69
+ "\\brm\\b",
70
+ "\\bunlink\\b",
71
+ "\\brmdir\\b",
72
+ "\\bshred\\b",
73
+ "\\bcp\\b",
74
+ "\\bmv\\b",
75
+ "\\binstall\\b",
76
+ "\\btee\\b",
77
+ "\\bdd\\b",
78
+ "\\bmkfs\\b",
79
+ "\\b(fdisk|parted|cfdisk|sfdisk)\\b",
80
+ "\\bchmod\\b",
81
+ "\\bchown\\b",
82
+ "\\btruncate\\b"
83
+ ],
84
+ "read_only_commands": [
85
+ "arch",
86
+ "arp",
87
+ "awk",
88
+ "blockdev",
89
+ "cat",
90
+ "cut",
91
+ "df",
92
+ "dir",
93
+ "dmesg",
94
+ "dmidecode",
95
+ "du",
96
+ "echo",
97
+ "ethtool",
98
+ "fdisk",
99
+ "file",
100
+ "find",
101
+ "free",
102
+ "getconf",
103
+ "getent",
104
+ "grep",
105
+ "head",
106
+ "hexdump",
107
+ "hostnamectl",
108
+ "hwinfo",
109
+ "id",
110
+ "ifconfig",
111
+ "inxi",
112
+ "iostat",
113
+ "ip",
114
+ "journalctl",
115
+ "last",
116
+ "less",
117
+ "localectl",
118
+ "ls",
119
+ "lsblk",
120
+ "lscpu",
121
+ "lsmem",
122
+ "lsmod",
123
+ "lsns",
124
+ "lsof",
125
+ "lspci",
126
+ "lsusb",
127
+ "modinfo",
128
+ "more",
129
+ "mpstat",
130
+ "netstat",
131
+ "nl",
132
+ "nmcli",
133
+ "nproc",
134
+ "od",
135
+ "parted",
136
+ "pgrep",
137
+ "pidof",
138
+ "printf",
139
+ "ps",
140
+ "rev",
141
+ "route",
142
+ "sed",
143
+ "smartctl",
144
+ "sort",
145
+ "ss",
146
+ "stat",
147
+ "strings",
148
+ "sysctl",
149
+ "systemctl",
150
+ "tac",
151
+ "tail",
152
+ "timedatectl",
153
+ "top",
154
+ "tr",
155
+ "tree",
156
+ "udevadm",
157
+ "uname",
158
+ "uniq",
159
+ "uptime",
160
+ "vmstat",
161
+ "w",
162
+ "wc",
163
+ "who",
164
+ "whoami",
165
+ "xxd"
166
+ ],
167
+ "fully_safe_commands": [
168
+ "^ls(?:\\s|$)",
169
+ "^dir(?:\\s|$)",
170
+ "^pwd(?:\\s|$)",
171
+ "^which\\s+",
172
+ "^whereis\\s+",
173
+ "^realpath\\s+",
174
+ "^basename\\s+",
175
+ "^dirname\\s+",
176
+ "^file\\s+",
177
+ "^stat\\s+",
178
+ "^du(?:\\s|$)",
179
+ "^echo\\s+",
180
+ "^printf\\s+",
181
+ "^type\\s+",
182
+ "^command\\s+",
183
+ "^whoami(?:\\s|$)",
184
+ "^id(?:\\s|$)",
185
+ "^hostname(?:\\s|$)",
186
+ "^uname(?:\\s|$)",
187
+ "^date(?:\\s|$)",
188
+ "^env(?:\\s|$)",
189
+ "^printenv(?:\\s|$)",
190
+ "^tty(?:\\s|$)",
191
+ "^arch(?:\\s|$)",
192
+ "^uptime(?:\\s|$)",
193
+ "^groups(?:\\s|$)",
194
+ "^logname(?:\\s|$)",
195
+ "^df(?:\\s|$)",
196
+ "^free(?:\\s|$)",
197
+ "^vmstat(?:\\s|$)",
198
+ "^nproc(?:\\s|$)",
199
+ "^lscpu(?:\\s|$)",
200
+ "^lsblk(?:\\s|$)",
201
+ "^lspci(?:\\s|$)",
202
+ "^lsusb(?:\\s|$)",
203
+ "^lsmod(?:\\s|$)"
204
+ ],
205
+ "readonly_sensitive_commands": [
206
+ "^cat\\s+\\S",
207
+ "^head(?:\\s|$)",
208
+ "^tail(?:\\s|$)",
209
+ "^less(?:\\s|$)",
210
+ "^more(?:\\s|$)",
211
+ "^wc(?:\\s|$)",
212
+ "^grep(?:\\s|$)",
213
+ "^find\\s+",
214
+ "^ag(?:\\s|$)",
215
+ "^rg(?:\\s|$)",
216
+ "^awk\\s+",
217
+ "^(?!.*(?:\\s|['\\\"])-[a-zA-Z]*i[a-zA-Z]*\\b)(?!.*(?:\\s|['\\\"])--in-place)sed\\s+",
218
+ "^cut\\s+",
219
+ "^sort(?:\\s|$)",
220
+ "^uniq(?:\\s|$)",
221
+ "^ps(?:\\s|$)",
222
+ "^ss(?:\\s|$)",
223
+ "^netstat(?:\\s|$)",
224
+ "^lsof(?:\\s|$)",
225
+ "^systemctl\\s+(?:status|is-active|is-enabled|is-failed|list-units|list-unit-files|list-dependencies|show|cat)\\b",
226
+ "^service\\s+\\S+\\s+status\\b",
227
+ "^journalctl\\b(?!.*--(?:vacuum-size|vacuum-time|vacuum-files|rotate|flush|sync)\\b)"
228
+ ],
229
+ "safe_action_types": [
230
+ "ask_user_question",
231
+ "count_text_length",
232
+ "filemgr-globfiles",
233
+ "glob",
234
+ "list_dir",
235
+ "ls"
236
+ ],
237
+ "readonly_sensitive_action_types": [
238
+ "file_read",
239
+ "filemgr-grepfiles",
240
+ "filemgr-readfile",
241
+ "grep",
242
+ "head",
243
+ "read",
244
+ "read_file",
245
+ "tail"
246
+ ]
247
+ },
248
+ "windows": {
249
+ "write_keywords": [
250
+ "write",
251
+ "写入",
252
+ "save",
253
+ "保存",
254
+ "modify",
255
+ "修改",
256
+ "update",
257
+ "更新",
258
+ "delete",
259
+ "删除",
260
+ "remove",
261
+ "移除",
262
+ "create",
263
+ "创建",
264
+ "append",
265
+ "追加",
266
+ "overwrite",
267
+ "覆盖",
268
+ "replace",
269
+ "替换",
270
+ "set",
271
+ "设置"
272
+ ],
273
+ "read_keywords": [
274
+ "read",
275
+ "读取",
276
+ "type",
277
+ "findstr",
278
+ "dir",
279
+ "view",
280
+ "查看",
281
+ "open",
282
+ "打开",
283
+ "load",
284
+ "加载",
285
+ "search",
286
+ "搜索",
287
+ "find",
288
+ "查找",
289
+ "get",
290
+ "获取"
291
+ ],
292
+ "write_command_res": [
293
+ "\\b(del|erase)\\b",
294
+ "\\brmdir\\b",
295
+ "\\b(rd)\\b",
296
+ "\\bcopy\\b",
297
+ "\\b(xcopy|robocopy)\\b",
298
+ "\\b(move|movefile)\\b",
299
+ "\\breplace\\b",
300
+ "\\bicacls\\b",
301
+ "\\battrib\\b",
302
+ "\\breg(?:\\.exe)?\\s+(?:add|delete|copy|save|restore|import|load|unload)\\b",
303
+ "\\bformat\\b",
304
+ "\\bdiskpart\\b",
305
+ "\\bmkdir\\b",
306
+ "\\bmd\\b",
307
+ "\\bsetx\\b",
308
+ "\\bwmic\\b"
309
+ ],
310
+ "read_only_commands": [
311
+ "cls",
312
+ "cmd",
313
+ "comp",
314
+ "dir",
315
+ "diskpart",
316
+ "driverquery",
317
+ "echo",
318
+ "fc",
319
+ "find",
320
+ "findstr",
321
+ "getmac",
322
+ "help",
323
+ "hostname",
324
+ "ipconfig",
325
+ "more",
326
+ "netstat",
327
+ "powershell",
328
+ "query",
329
+ "reg",
330
+ "sort",
331
+ "systeminfo",
332
+ "tasklist",
333
+ "tree",
334
+ "type",
335
+ "ver",
336
+ "w32tm",
337
+ "where",
338
+ "whoami",
339
+ "wmic"
340
+ ],
341
+ "fully_safe_commands": [
342
+ "^dir(?:\\s|$)",
343
+ "^where\\s+",
344
+ "^echo\\s+",
345
+ "^cd(?:\\s|$)",
346
+ "^tree(?:\\s|$)",
347
+ "^help(?:\\s|$)",
348
+ "^cls(?:\\s|$)",
349
+ "^ver(?:\\s|$)",
350
+ "^whoami(?:\\s|$)",
351
+ "^hostname(?:\\s|$)",
352
+ "^systeminfo(?:\\s|$)",
353
+ "^tasklist(?:\\s|$)",
354
+ "^getmac(?:\\s|$)",
355
+ "^driverquery(?:\\s|$)",
356
+ "^netstat(?:\\s|$)"
357
+ ],
358
+ "readonly_sensitive_commands": [
359
+ "^type\\s+",
360
+ "^findstr\\s+",
361
+ "^sc\\s+query\\b",
362
+ "^reg\\s+query\\b"
363
+ ],
364
+ "safe_action_types": [
365
+ "ask_user_question",
366
+ "count_text_length",
367
+ "filemgr-globfiles",
368
+ "glob",
369
+ "list_dir",
370
+ "ls"
371
+ ],
372
+ "readonly_sensitive_action_types": [
373
+ "file_read",
374
+ "filemgr-grepfiles",
375
+ "filemgr-readfile",
376
+ "grep",
377
+ "head",
378
+ "read",
379
+ "read_file",
380
+ "tail"
381
+ ]
382
+ },
383
+ "macos": {
384
+ "inherits": "linux"
385
+ },
386
+ "harmony": {
387
+ "inherits": "linux"
388
+ }
389
+ }