@kenhkl/agent-gate 0.8.2 → 0.9.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.
@@ -0,0 +1,585 @@
1
+ # AgentGate Trigger Rules Configuration
2
+ # 角色变更:从"黑名单触发 AgentMoss" → "白名单跳过 + 快速阻断兜底"
3
+ #
4
+ # 核心流程:
5
+ # 1. 白名单规则(action: allow, _skip_agentmoss: true)→ 直接放行,不调 AgentMoss
6
+ # 2. 快速阻断规则(action: block)→ 本地立即 Deny,不等 AgentMoss
7
+ # 3. 以上都不匹配 → 默认送 AgentMoss 完整分析
8
+ #
9
+ # 规则来源:AgentMoss 三层防御体系
10
+ # - Layer 1.1: 启发式检测(关键命令正则 + 注入关键词 + 用户规则)
11
+ # - Layer 1.2: 逻辑规则(敏感路径 + read_before_write + 意图偏离等)
12
+ # - Layer 1.3: LLM 语义分析(由 AgentMoss 完成,不在本文件中定义)
13
+ #
14
+ # 无论单独层还是组合融合,收集信息后统一触发 AgentMoss 判断。
15
+
16
+ rules:
17
+
18
+ # ======================================================================
19
+ # 白名单 — 完全安全的操作,跳过 AgentMoss
20
+ # action: allow, _skip_agentmoss: true
21
+ # 适用:L1 Proxy + L2 PTY
22
+ # ======================================================================
23
+
24
+ # --- 安全只读 bash 命令 ---
25
+ - name: "whitelist_bash_safe_readonly"
26
+ description: "完全安全的 bash 只读命令 — 跳过 AgentMoss"
27
+ action: allow
28
+ severity: low
29
+ _skip_agentmoss: true
30
+ pattern:
31
+ source_collector: "llm_api_proxy"
32
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
33
+ arguments_regex: "^(ls|dir|pwd|which|whereis|realpath|basename|dirname|file|stat|du|echo|printf|type|command|whoami|id|hostname|uname|date|env|printenv|tty|arch|uptime|groups|logname)\\b"
34
+
35
+ - name: "whitelist_bash_safe_readonly_pty"
36
+ description: "完全安全的 bash 只读命令 — PTY"
37
+ action: allow
38
+ severity: low
39
+ _skip_agentmoss: true
40
+ pattern:
41
+ source_collector: "pty"
42
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
43
+ arguments_regex: "^(ls|dir|pwd|which|whereis|realpath|basename|dirname|file|stat|du|echo|printf|type|command|whoami|id|hostname|uname|date|env|printenv|tty|arch|uptime|groups|logname)\\b"
44
+
45
+ # --- 安全只读操作工具 ---
46
+ - name: "whitelist_safe_tools"
47
+ description: "完全安全的工具操作 — 跳过 AgentMoss"
48
+ action: allow
49
+ severity: low
50
+ _skip_agentmoss: true
51
+ pattern:
52
+ source_collector: "llm_api_proxy"
53
+ tool_name_matches: ["ask_user_question", "glob", "list_dir", "ls", "count_text_length", "filemgr-globfiles"]
54
+
55
+ # --- 安全只读 bash 命令(可访问敏感路径,但本身安全)---
56
+ # 这些命令会读取文件内容,需要保留 L2 敏感路径检查
57
+ - name: "whitelist_bash_readonly_sensitive"
58
+ description: "安全但可读敏感路径的 bash 命令 — 跳过 AgentMoss(需 L2 配合)"
59
+ action: allow
60
+ severity: low
61
+ _skip_agentmoss: true
62
+ pattern:
63
+ source_collector: "llm_api_proxy"
64
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
65
+ arguments_regex: "^(cat|head|tail|less|more|wc|grep|find|ag|rg|awk|sed|cut|sort|uniq)\\b"
66
+
67
+ # --- 安全只读工具(可访问敏感路径)---
68
+ - name: "whitelist_readonly_sensitive_tools"
69
+ description: "安全但可读敏感路径的工具 — 跳过 AgentMoss(需 L2 配合)"
70
+ action: allow
71
+ severity: low
72
+ _skip_agentmoss: true
73
+ pattern:
74
+ source_collector: "llm_api_proxy"
75
+ tool_name_matches: ["read", "file_read", "read_file", "head", "tail", "grep", "filemgr-readfile", "filemgr-grepfiles"]
76
+
77
+ # --- 内联脚本命令(假阳性防护 — 字符串字面量中的敏感路径)---
78
+ # 这些命令的 file_access 模式可能是字符串误报,跳过本地阻断
79
+ - name: "whitelist_inline_script"
80
+ description: "内联脚本命令 — 跳过本地 quick-deny,交 AgentMoss 语义判断"
81
+ action: allow
82
+ severity: low
83
+ _skip_agentmoss: false # 注意:不跳过 AgentMoss,只跳过本地 quick-deny
84
+ pattern:
85
+ source_collector: "llm_api_proxy"
86
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
87
+ arguments_regex: "(?:python|python3|python3\\.\\d+|perl|perl5|ruby|jruby|mruby|node|php|lua)\\s+-[a-zA-Z]*[cer][a-zA-Z]*\\s+"
88
+
89
+ # ======================================================================
90
+ # 快速阻断 — 明显危险操作,不等 AgentMoss 直接拒绝
91
+ # action: block (local_block: true)
92
+ # 适用:L1 Proxy + L2 PTY + L3 eBPF
93
+ # ======================================================================
94
+
95
+ # --- rm -rf 根目录 ---
96
+ - name: "quick_deny_rm_rf_root"
97
+ description: "rm -rf 根目录 — 立即阻止"
98
+ action: block
99
+ severity: critical
100
+ pattern:
101
+ source_collector: "llm_api_proxy"
102
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
103
+ arguments_regex: "\\brm\\s+-(?=[^\\s]*r)(?=[^\\s]*f)[a-zA-Z]*\\s+/"
104
+
105
+ - name: "quick_deny_rm_rf_root_pty"
106
+ description: "rm -rf 根目录 — PTY 立即阻止"
107
+ action: block
108
+ severity: critical
109
+ pattern:
110
+ source_collector: "pty"
111
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
112
+ arguments_regex: "\\brm\\s+-(?=[^\\s]*r)(?=[^\\s]*f)[a-zA-Z]*\\s+/"
113
+
114
+ - name: "quick_deny_rm_rf_root_ebpf"
115
+ description: "rm -rf 根目录 — eBPF 立即记录"
116
+ action: block
117
+ severity: critical
118
+ pattern:
119
+ event_type: "process_exec"
120
+ argv_regex: "\\brm\\s+-(?=[^\\s]*r)(?=[^\\s]*f)[a-zA-Z]*\\s+/"
121
+
122
+ # --- rm -rf 系统目录 ---
123
+ - name: "quick_deny_rm_system_dir"
124
+ description: "rm -rf 关键系统目录 — 立即阻止"
125
+ action: block
126
+ severity: critical
127
+ pattern:
128
+ source_collector: "llm_api_proxy"
129
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
130
+ arguments_regex: "\\brm\\s+-[a-zA-Z]*[rf][a-zA-Z]*\\s+/(etc|var|home|usr|boot|root|opt|srv|sys|proc)\\b"
131
+
132
+ - name: "quick_deny_rm_system_dir_pty"
133
+ description: "rm -rf 系统目录 — PTY"
134
+ action: block
135
+ severity: critical
136
+ pattern:
137
+ source_collector: "pty"
138
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
139
+ arguments_regex: "\\brm\\s+-[a-zA-Z]*[rf][a-zA-Z]*\\s+/(etc|var|home|usr|boot|root|opt|srv|sys|proc)\\b"
140
+
141
+ # --- chmod 777 ---
142
+ - name: "quick_deny_chmod_777"
143
+ description: "chmod 777 — 立即阻止"
144
+ action: block
145
+ severity: critical
146
+ pattern:
147
+ source_collector: "llm_api_proxy"
148
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
149
+ arguments_regex: "chmod\\s+[0-7]*777[0-7]*"
150
+
151
+ - name: "quick_deny_chmod_777_pty"
152
+ description: "chmod 777 — PTY"
153
+ action: block
154
+ severity: critical
155
+ pattern:
156
+ source_collector: "pty"
157
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
158
+ arguments_regex: "chmod\\s+[0-7]*777[0-7]*"
159
+
160
+ # --- curl | bash ---
161
+ - name: "quick_deny_curl_pipe_bash"
162
+ description: "curl | bash 远程下载执行 — 立即阻止"
163
+ action: block
164
+ severity: critical
165
+ pattern:
166
+ source_collector: "llm_api_proxy"
167
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
168
+ arguments_regex: "(?:curl|wget)\\s+.*\\|\\s*(?:bash|sh|zsh|dash)"
169
+
170
+ - name: "quick_deny_curl_pipe_bash_pty"
171
+ description: "curl | bash — PTY"
172
+ action: block
173
+ severity: critical
174
+ pattern:
175
+ source_collector: "pty"
176
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
177
+ arguments_regex: "(?:curl|wget)\\s+.*\\|\\s*(?:bash|sh|zsh|dash)"
178
+
179
+ # --- dd if=/dev/zero ---
180
+ - name: "quick_deny_dd_zero"
181
+ description: "dd if=/dev/zero 磁盘清零 — 立即阻止"
182
+ action: block
183
+ severity: critical
184
+ pattern:
185
+ source_collector: "llm_api_proxy"
186
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
187
+ arguments_regex: "\\bdd\\s+if=/dev/zero"
188
+
189
+ # --- mkfs ---
190
+ - name: "quick_deny_mkfs"
191
+ description: "mkfs 格式化 — 立即阻止"
192
+ action: block
193
+ severity: critical
194
+ pattern:
195
+ source_collector: "llm_api_proxy"
196
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
197
+ arguments_regex: "\\bmkfs\\b"
198
+
199
+ - name: "quick_deny_mkfs_pty"
200
+ description: "mkfs 格式化 — PTY"
201
+ action: block
202
+ severity: critical
203
+ pattern:
204
+ source_collector: "pty"
205
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
206
+ arguments_regex: "\\bmkfs\\b"
207
+
208
+ # --- 覆盖写入 /etc/ ---
209
+ - name: "quick_deny_overwrite_etc"
210
+ description: "重定向覆盖 /etc/ — 立即阻止"
211
+ action: block
212
+ severity: critical
213
+ pattern:
214
+ source_collector: "llm_api_proxy"
215
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
216
+ arguments_regex: ">\\s*/etc/"
217
+
218
+ - name: "quick_deny_overwrite_etc_pty"
219
+ description: "重定向覆盖 /etc/ — PTY"
220
+ action: block
221
+ severity: critical
222
+ pattern:
223
+ source_collector: "pty"
224
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
225
+ arguments_regex: ">\\s*/etc/"
226
+
227
+ # --- 反弹 Shell ---
228
+ - name: "quick_deny_reverse_shell"
229
+ description: "反弹 Shell 特征 — 立即阻止"
230
+ action: block
231
+ severity: critical
232
+ pattern:
233
+ source_collector: "llm_api_proxy"
234
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
235
+ arguments_regex: "\\bnc\\s+.*-e\\b|\\bncat\\s+.*-e\\b|/dev/tcp/|/dev/udp/"
236
+
237
+ - name: "quick_deny_reverse_shell_pty"
238
+ description: "反弹 Shell — PTY"
239
+ action: block
240
+ severity: critical
241
+ pattern:
242
+ source_collector: "pty"
243
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
244
+ arguments_regex: "\\bnc\\s+.*-e\\b|\\bncat\\s+.*-e\\b|/dev/tcp/|/dev/udp/"
245
+
246
+ # --- Docker socket ---
247
+ - name: "quick_deny_docker_socket"
248
+ description: "Docker socket 容器逃逸 — 立即阻止"
249
+ action: block
250
+ severity: critical
251
+ pattern:
252
+ source_collector: "llm_api_proxy"
253
+ arguments_regex: "/var/run/docker\\.sock"
254
+
255
+ # ======================================================================
256
+ # 触发分析规则 — 匹配到即触发 AgentMoss
257
+ # action: trigger_analysis
258
+ # 所有非白名单操作默认送 AgentMoss,但以下规则提供精确的 risk_type/severity
259
+ # 适用:L1 Proxy + L2 PTY
260
+ # ======================================================================
261
+
262
+ # --- 敏感文件操作(L1)---
263
+ - name: "sensitive_file_shadow"
264
+ description: "访问 /etc/shadow — 触发 AgentMoss"
265
+ action: trigger_analysis
266
+ severity: critical
267
+ pattern:
268
+ source_collector: "llm_api_proxy"
269
+ arguments_regex: "/etc/shadow"
270
+
271
+ - name: "sensitive_file_shadow_pty"
272
+ description: "访问 /etc/shadow — PTY"
273
+ action: trigger_analysis
274
+ severity: critical
275
+ pattern:
276
+ source_collector: "pty"
277
+ arguments_regex: "/etc/shadow"
278
+
279
+ - name: "sensitive_file_passwd"
280
+ description: "访问 /etc/passwd"
281
+ action: trigger_analysis
282
+ severity: high
283
+ pattern:
284
+ source_collector: "llm_api_proxy"
285
+ arguments_regex: "/etc/passwd"
286
+
287
+ - name: "sensitive_file_ssh_key"
288
+ description: "访问 SSH 私钥"
289
+ action: trigger_analysis
290
+ severity: critical
291
+ pattern:
292
+ source_collector: "llm_api_proxy"
293
+ arguments_regex: "\\.ssh/id_rsa|\\.ssh/id_ed25519"
294
+
295
+ - name: "sensitive_file_sudoers"
296
+ description: "访问 sudo 配置"
297
+ action: trigger_analysis
298
+ severity: critical
299
+ pattern:
300
+ source_collector: "llm_api_proxy"
301
+ arguments_regex: "/etc/sudoers"
302
+
303
+ - name: "sensitive_file_credentials"
304
+ description: "访问凭据配置文件"
305
+ action: trigger_analysis
306
+ severity: high
307
+ pattern:
308
+ source_collector: "llm_api_proxy"
309
+ arguments_regex: "\\bcredentials\\.(yml|yaml)\\b|\\bsecrets\\.(yml|yaml)\\b|(?:^|[\\s/\\\\]\\.env\\b)"
310
+
311
+ # --- 危险命令(L1)---
312
+ - name: "dangerous_sudo"
313
+ description: "sudo 提权 — 触发 AgentMoss"
314
+ action: trigger_analysis
315
+ severity: high
316
+ pattern:
317
+ source_collector: "llm_api_proxy"
318
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
319
+ arguments_regex: "\\bsudo\\s+"
320
+
321
+ - name: "dangerous_git_force_push"
322
+ description: "git push --force"
323
+ action: trigger_analysis
324
+ severity: high
325
+ pattern:
326
+ source_collector: "llm_api_proxy"
327
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
328
+ arguments_regex: "git\\s+push\\s+.*--force"
329
+
330
+ - name: "dangerous_password_modify"
331
+ description: "非交互式密码修改"
332
+ action: trigger_analysis
333
+ severity: high
334
+ pattern:
335
+ source_collector: "llm_api_proxy"
336
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
337
+ arguments_regex: "(\\|\\s*passwd\\b|passwd\\s+--stdin\\b|chpasswd\\b|newusers\\b|passwd\\s+-[a-zA-Z]*[dl]\\b)"
338
+
339
+ # --- Prompt 注入(L1)---
340
+ - name: "prompt_injection_ignore_previous"
341
+ description: "指令覆盖注入"
342
+ action: trigger_analysis
343
+ severity: critical
344
+ pattern:
345
+ source_collector: "llm_api_proxy"
346
+ arguments_regex: "ignore\\s+(previous|all\\s+previous)\\s+instructions|disregard\\s+all\\s+prior"
347
+
348
+ - name: "prompt_injection_role_hijack"
349
+ description: "角色劫持注入"
350
+ action: trigger_analysis
351
+ severity: high
352
+ pattern:
353
+ source_collector: "llm_api_proxy"
354
+ arguments_regex: "you\\s+are\\s+(now|no\\s+longer)|from\\s+now\\s+on,\\s+you|你现在是一个|你不再是一个"
355
+
356
+ - name: "prompt_injection_jailbreak"
357
+ description: "越狱/开发者模式"
358
+ action: trigger_analysis
359
+ severity: critical
360
+ pattern:
361
+ source_collector: "llm_api_proxy"
362
+ arguments_regex: "developer\\s+mode|DAN\\s+mode|jailbreak|开发者模式|越狱"
363
+
364
+ - name: "prompt_injection_bypass"
365
+ description: "绕过安全审计"
366
+ action: trigger_analysis
367
+ severity: critical
368
+ pattern:
369
+ source_collector: "llm_api_proxy"
370
+ arguments_regex: "bypass\\s+audit|skip\\s+security\\s+check|disable\\s+guard|绕过审计|禁用安全检查|关闭防护"
371
+
372
+ # --- 权限提升(L1)---
373
+ - name: "privilege_escalation"
374
+ description: "提权操作(su/chmod u+s)"
375
+ action: trigger_analysis
376
+ severity: high
377
+ pattern:
378
+ source_collector: "llm_api_proxy"
379
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
380
+ arguments_regex: "\\bsu\\s+-|chmod\\s+u\\+s|setuid"
381
+
382
+ # --- 横向移动(L1)---
383
+ - name: "lateral_movement"
384
+ description: "SSH 到远程主机"
385
+ action: trigger_analysis
386
+ severity: medium
387
+ pattern:
388
+ source_collector: "llm_api_proxy"
389
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
390
+ arguments_regex: "(?:ssh|scp|rsync)\\s+(?:-[\\w]+\\s+)*\\S+@\\S+"
391
+
392
+ # --- 持久化后门(L1)---
393
+ - name: "persistence_shell_config"
394
+ description: "修改 Shell 配置文件(持久化风险)"
395
+ action: trigger_analysis
396
+ severity: high
397
+ pattern:
398
+ source_collector: "llm_api_proxy"
399
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
400
+ arguments_regex: ">>\\s*(~|/home/[^/]+)/(\\.bashrc|\\.zshrc|\\.profile|\\.bash_profile|\\.zprofile)"
401
+
402
+ - name: "persistence_crontab"
403
+ description: "编辑 crontab(持久化风险)"
404
+ action: trigger_analysis
405
+ severity: high
406
+ pattern:
407
+ source_collector: "llm_api_proxy"
408
+ arguments_regex: "crontab\\s+-[er]|\\|\\s*crontab\\b"
409
+
410
+ - name: "persistence_crontab_pty"
411
+ description: "编辑 crontab — PTY"
412
+ action: trigger_analysis
413
+ severity: high
414
+ pattern:
415
+ source_collector: "pty"
416
+ arguments_regex: "crontab\\s+-[er]|\\|\\s*crontab\\b"
417
+
418
+ # --- 数据外传(L1)---
419
+ - name: "data_exfil_curl_post"
420
+ description: "curl POST 外传敏感信息"
421
+ action: trigger_analysis
422
+ severity: high
423
+ pattern:
424
+ source_collector: "llm_api_proxy"
425
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
426
+ arguments_regex: "curl\\s+.*-X\\s+POST.*\\b(env|environment|secret|key|token|password)\\b"
427
+
428
+ - name: "data_exfil_base64_bash"
429
+ description: "Base64 编码后管道执行(编码绕过)"
430
+ action: trigger_analysis
431
+ severity: high
432
+ pattern:
433
+ source_collector: "llm_api_proxy"
434
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
435
+ arguments_regex: "base64\\s+(-d|--decode)\\s*\\|"
436
+
437
+ - name: "data_exfil_base64_bash_pty"
438
+ description: "Base64 编码绕过 — PTY"
439
+ action: trigger_analysis
440
+ severity: high
441
+ pattern:
442
+ source_collector: "pty"
443
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
444
+ arguments_regex: "base64\\s+(-d|--decode)\\s*\\|"
445
+
446
+ # --- SSH 绕过(L1)---
447
+ - name: "ssh_skip_host_key_check"
448
+ description: "SSH 跳过主机密钥验证"
449
+ action: trigger_analysis
450
+ severity: high
451
+ pattern:
452
+ source_collector: "llm_api_proxy"
453
+ arguments_regex: "ssh\\s+.*StrictHostKeyChecking\\s*=\\s*no"
454
+
455
+ # --- iptables(L1)---
456
+ - name: "iptables_modify"
457
+ description: "修改 iptables 防火墙规则"
458
+ action: trigger_analysis
459
+ severity: high
460
+ pattern:
461
+ source_collector: "llm_api_proxy"
462
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
463
+ arguments_regex: "iptables\\s+-"
464
+
465
+ - name: "iptables_modify_pty"
466
+ description: "修改 iptables — PTY"
467
+ action: trigger_analysis
468
+ severity: high
469
+ pattern:
470
+ source_collector: "pty"
471
+ tool_name_matches: ["bash", "executeBash", "execute_command", "Bash", "shell", "terminal-executebash"]
472
+ arguments_regex: "iptables\\s+-"
473
+
474
+ # ======================================================================
475
+ # L3 eBPF 规则(syscall 级,仅记录)
476
+ # ======================================================================
477
+
478
+ - name: "ebpf_sensitive_file_access"
479
+ description: "敏感文件访问 — eBPF 记录"
480
+ action: trigger_analysis
481
+ severity: high
482
+ pattern:
483
+ event_type: "file_access"
484
+ pathname_matches: [
485
+ "/etc/shadow", "/etc/passwd", "/etc/sudoers",
486
+ "/etc/crontab", "/etc/systemd/*", "/etc/ssh/sshd_config",
487
+ "/boot/*", "/proc/sys/*", "/sys/*",
488
+ "/root/.ssh/*",
489
+ "*.pem", "*.key", "credentials.yml", "credentials.yaml",
490
+ "secrets.yml", "secrets.yaml", ".env",
491
+ ]
492
+
493
+ - name: "ebpf_device_file_access"
494
+ description: "设备文件访问 — eBPF 记录"
495
+ action: trigger_analysis
496
+ severity: high
497
+ pattern:
498
+ event_type: "file_access"
499
+ pathname_matches: ["/dev/zero", "/dev/random", "/dev/urandom", "/dev/full",
500
+ "/dev/core", "/dev/mem", "/dev/kmsg"]
501
+
502
+ - name: "ebpf_suspicious_network"
503
+ description: "可疑网络连接 — eBPF 记录"
504
+ action: trigger_analysis
505
+ severity: medium
506
+ pattern:
507
+ event_type: "network_connect"
508
+ condition:
509
+ remote_port_in: [22, 443, 8080, 8443]
510
+ remote_addr_not_in: ["10.*", "172.16.*", "172.17.*", "172.18.*", "172.19.*",
511
+ "172.20.*", "172.21.*", "172.22.*", "172.23.*", "172.24.*",
512
+ "172.25.*", "172.26.*", "172.27.*", "172.28.*", "172.29.*",
513
+ "172.30.*", "172.31.*", "192.168.*", "127.*"]
514
+
515
+ - name: "ebpf_sudo"
516
+ description: "sudo 执行 — eBPF 记录"
517
+ action: trigger_analysis
518
+ severity: high
519
+ pattern:
520
+ event_type: "process_exec"
521
+ argv_regex: "\\bsudo\\s+"
522
+
523
+ - name: "ebpf_modify_shell_config"
524
+ description: "修改 Shell 配置 — eBPF 记录"
525
+ action: trigger_analysis
526
+ severity: high
527
+ pattern:
528
+ event_type: "process_exec"
529
+ argv_regex: ">>\\s*(~|/home/[^/]+)/(\\.bashrc|\\.zshrc|\\.profile|\\.bash_profile|\\.zprofile)"
530
+
531
+ - name: "ebpf_password_operation"
532
+ description: "密码修改 — eBPF 记录"
533
+ action: trigger_analysis
534
+ severity: high
535
+ pattern:
536
+ event_type: "process_exec"
537
+ argv_regex: "(\\|\\s*passwd\\b|passwd\\s+--stdin\\b|chpasswd\\b|newusers\\b|passwd\\s+-[a-zA-Z]*[dl]\\b)"
538
+
539
+ - name: "ebpf_crontab"
540
+ description: "crontab 修改 — eBPF 记录"
541
+ action: trigger_analysis
542
+ severity: high
543
+ pattern:
544
+ event_type: "process_exec"
545
+ argv_regex: "crontab\\s+-[er]"
546
+
547
+ - name: "ebpf_iptables"
548
+ description: "iptables 修改 — eBPF 记录"
549
+ action: trigger_analysis
550
+ severity: high
551
+ pattern:
552
+ event_type: "process_exec"
553
+ argv_regex: "iptables\\s+-"
554
+
555
+ - name: "ebpf_base64_evasion"
556
+ description: "Base64 解码执行 — eBPF 记录"
557
+ action: trigger_analysis
558
+ severity: high
559
+ pattern:
560
+ event_type: "process_exec"
561
+ argv_regex: "base64\\s+(-d|--decode)\\s*\\|"
562
+
563
+ - name: "ebpf_ssh_skip_key_check"
564
+ description: "SSH 跳过密钥验证 — eBPF 记录"
565
+ action: trigger_analysis
566
+ severity: high
567
+ pattern:
568
+ event_type: "process_exec"
569
+ argv_regex: "ssh\\s+.*StrictHostKeyChecking\\s*=\\s*no"
570
+
571
+ - name: "ebpf_git_force_push"
572
+ description: "git push --force — eBPF 记录"
573
+ action: trigger_analysis
574
+ severity: high
575
+ pattern:
576
+ event_type: "process_exec"
577
+ argv_regex: "git\\s+push\\s+.*--force"
578
+
579
+ - name: "ebpf_data_exfil_curl"
580
+ description: "curl POST 外传 — eBPF 记录"
581
+ action: trigger_analysis
582
+ severity: high
583
+ pattern:
584
+ event_type: "process_exec"
585
+ argv_regex: "curl\\s+.*-X\\s+POST.*\\b(env|environment|secret|key|token|password)\\b"
@@ -4,6 +4,23 @@
4
4
  * SQLite 和 JSON 文件存储各自实现此接口,
5
5
  * 通过 AGENT_GATE_STORAGE 环境变量选择后端。
6
6
  */
7
+ /**
8
+ * `/tool_calls` 的过滤条件,双端对齐 Python
9
+ * `repository.query_tool_calls` / `count_tool_calls` 的入参。
10
+ */
11
+ interface ToolCallFilter {
12
+ sessionId?: string;
13
+ /** 完整 agent_id(`<agent_type>:<hostname>`),精确匹配。 */
14
+ agentId?: string;
15
+ /** 逐 agent token 的隔离依据:只按 agent_type 过滤,不知道(也不该知道)别人 hostname。 */
16
+ agentType?: string;
17
+ decision?: string;
18
+ riskLevel?: string;
19
+ /** 时间下界(含),与 `called_at` 字符串比较。 */
20
+ fromTime?: string;
21
+ /** 时间上界(含)。 */
22
+ toTime?: string;
23
+ }
7
24
  interface ToolCallRecord {
8
25
  session_id: string;
9
26
  seq: number;
@@ -61,20 +78,20 @@ interface StorageAdapter {
61
78
  getNextSeq(sessionId: string): number;
62
79
  insertToolCall(record: ToolCallRecord): number;
63
80
  getActionHistory(sessionId: string, limit?: number): ActionEntry[];
64
- queryToolCalls(params: {
65
- sessionId?: string;
66
- /** 逐 agent token 的隔离依据(agent_id 是 `<agent_type>:<hostname>`)。 */
67
- agentType?: string;
68
- decision?: string;
81
+ queryToolCalls(params: ToolCallFilter & {
69
82
  limit?: number;
70
83
  offset?: number;
71
84
  }): ToolCallRich[];
72
- countToolCalls(params: {
73
- decision?: string;
74
- agentType?: string;
75
- }): number;
85
+ countToolCalls(params: ToolCallFilter): number;
76
86
  getStorageStats(): StorageStats;
77
87
  clearToolCalls(): number;
88
+ /** 归档最老的记录到本地压缩文件,主库保留最近 keep 条。 */
89
+ archiveOldRecords(keep: number): {
90
+ archived: number;
91
+ file: string;
92
+ };
93
+ /** 真正释放磁盘(DELETE 不会让文件变小)。 */
94
+ vacuum(): void;
78
95
  getAgentsList(agentType?: string): AgentSummary[];
79
96
  getTimeline(limit?: number): TimelineEntry[];
80
97
  /** 会话归属哪个 agent_type(跨 agent 读隔离校验用)。不存在返回 undefined。 */