@kenhkl/agent-moss 0.11.2 → 0.11.4

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/dist/cli.js CHANGED
@@ -964,7 +964,11 @@ var init_logic_rules = __esm({
964
964
  // SSH 主机私钥(排除 .pub 公钥变体,对齐 Python .ssh/id_rsa(?!\.pub) 范式)
965
965
  { path: "/etc/ssh/ssh_host_rsa_key(?!\\.pub)", riskLevel: "critical", desc: "SSH \u4E3B\u673A RSA \u79C1\u94A5", credential: true },
966
966
  { path: "/etc/ssh/ssh_host_ed25519_key(?!\\.pub)", riskLevel: "critical", desc: "SSH \u4E3B\u673A Ed25519 \u79C1\u94A5", credential: true },
967
- { path: "/etc/ssh/ssh_host_ecdsa_key(?!\\.pub)", riskLevel: "critical", desc: "SSH \u4E3B\u673A ECDSA \u79C1\u94A5", credential: true }
967
+ { path: "/etc/ssh/ssh_host_ecdsa_key(?!\\.pub)", riskLevel: "critical", desc: "SSH \u4E3B\u673A ECDSA \u79C1\u94A5", credential: true },
968
+ // Nginx 配置(仅拦截写入,对齐 Python linux.py sensitive_paths)
969
+ { path: "/etc/nginx/nginx.conf", riskLevel: "high", desc: "Nginx \u4E3B\u914D\u7F6E" },
970
+ { path: "/etc/nginx/conf.d/", riskLevel: "high", desc: "Nginx \u5B50\u914D\u7F6E\u76EE\u5F55" },
971
+ { path: "/etc/nginx/sites-enabled/", riskLevel: "high", desc: "Nginx \u542F\u7528\u7AD9\u70B9\u914D\u7F6E\u76EE\u5F55" }
968
972
  ];
969
973
  HOME_SENSITIVE_PATHS = [
970
974
  { path: ".ssh/id_rsa", riskLevel: "critical", desc: "SSH \u79C1\u94A5", credential: true },
@@ -2375,6 +2379,12 @@ function stripLiteralTextSegments(actionDetail) {
2375
2379
  }
2376
2380
  return resultParts.join("");
2377
2381
  }
2382
+ function stripHeredocContent(actionDetail) {
2383
+ return actionDetail.replace(
2384
+ /<<-?\s*(?:['"]?)([A-Za-z_][A-Za-z0-9_]*)(?:['"]?)[^\n]*\n[\s\S]*?\n\s*\1\s*(?:\n|$)/g,
2385
+ "<<heredoc>>\n"
2386
+ );
2387
+ }
2378
2388
  function splitCommandSegments(actionDetail) {
2379
2389
  const segments = [];
2380
2390
  let cur = "";
@@ -2539,11 +2549,13 @@ function checkSensitivePath(command, cwd, agentExt) {
2539
2549
  }
2540
2550
  function checkDangerousPatterns(actionType, actionDetail) {
2541
2551
  if (actionType === "file_write" || actionType === "file_edit") return null;
2552
+ const scan = stripHeredocContent(actionDetail);
2542
2553
  const TEMP_DIRS = ["/tmp", "/var/tmp", "/run", "/dev/shm"];
2543
2554
  const isTempPath = TEMP_DIRS.some(
2544
2555
  (td) => new RegExp(`(?:^|[\\s/])${td.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:[\\s/]|$)`).test(actionDetail)
2545
2556
  );
2546
- if (!isTempPath && (actionDetail.includes("*") || actionDetail.includes("?")) && ["rm ", "rm ", "del ", "del ", "delete", "remove ", "remove ", "\u5220\u9664", "\u79FB\u9664"].some((kw) => actionDetail.includes(kw))) {
2557
+ const wildcardDeleteRe = /(?:\brm\b|\b(r?mdir|del|delete|remove|rmdir|unlink)\b|\b删除\b|\b移除\b)[\s\S]{0,40}?[*?]|[*?][\s\S]{0,40}?\b(?:rm|del|delete|remove|rmdir|unlink)\b|rm\s+-[a-zA-Z]*[rf][a-zA-Z]*\s+\S*[*?]/i;
2558
+ if (!isTempPath && wildcardDeleteRe.test(scan)) {
2547
2559
  return {
2548
2560
  allowed: false,
2549
2561
  reason: "\u68C0\u6D4B\u5230\u901A\u914D\u7B26\u7ED3\u5408\u5220\u9664\u64CD\u4F5C\uFF0C\u53EF\u80FD\u9020\u6210\u6279\u91CF\u8BEF\u5220",
@@ -2806,7 +2818,10 @@ var init_heuristic = __esm({
2806
2818
  { pattern: />\s*\/boot\//i, severity: "critical", description: "\u8986\u76D6\u5199\u5165\u542F\u52A8\u5F15\u5BFC\u76EE\u5F55", riskType: "file_access" },
2807
2819
  // 注:/proc/ 重定向覆盖走 checkSensitivePath 的 high(内核参数 /proc/sys/),此处不拦 /proc/ 避免遮蔽(对齐 Python)。
2808
2820
  // --- High: download script + execute risk ---
2821
+ // curl -X POST 外传敏感信息(对齐 Python linux.py: curl POST env/key/token)
2822
+ { pattern: /curl\s+.*-X\s+POST.*\b(env|environment|secret|key|token|password)\b/i, severity: "high", description: "\u68C0\u6D4B\u5230\u901A\u8FC7 curl POST \u5916\u4F20\u53EF\u80FD\u5305\u542B\u654F\u611F\u4FE1\u606F\u7684\u8BF7\u6C42", riskType: "data_exfiltration" },
2809
2823
  { pattern: /(?:curl|wget)\s+.*(?:-o|--output|>)\s*\S+\.(?:sh|bash)\b/i, severity: "high", description: "\u8FDC\u7A0B\u4E0B\u8F7D\u811A\u672C\u5230\u672C\u5730", riskType: "script_execution" },
2824
+ { pattern: /(?:curl|wget)\s+\S+.*\b(?:chmod|chown)\s+\+x\b/i, severity: "high", description: "\u8FDC\u7A0B\u4E0B\u8F7D\u540E\u4FEE\u6539\u53EF\u6267\u884C\u6743\u9650\uFF0C\u5B58\u5728\u8FDC\u7A0B\u4EE3\u7801\u6267\u884C\u98CE\u9669", riskType: "script_execution" },
2810
2825
  { pattern: /(?:curl|wget)\s+.*\s+&&?\s*(?:chmod\s+\+x|bash|sh)/i, severity: "high", description: "\u4E0B\u8F7D\u540E\u6267\u884C", riskType: "script_execution" },
2811
2826
  // --- High: package manager pipe-to-shell ---
2812
2827
  { pattern: /git\s+clone\s+.*\|.*bash/i, severity: "high", description: "git clone pipe shell", riskType: "script_execution" },
@@ -5731,18 +5746,18 @@ async function main() {
5731
5746
  const binPath = which || `${process.execPath} ${path3.join(__dirname7, "cli.js")}`;
5732
5747
  let content = fs4.readFileSync(srcPath, "utf-8");
5733
5748
  content = content.replace("__AGENT_MOSS_BIN__", binPath);
5734
- const dst = "/etc/systemd/system/agent_moss.service";
5749
+ const dst = "/etc/systemd/system/agent-moss.service";
5735
5750
  fs4.writeFileSync(dst, content, "utf-8");
5736
5751
  fs4.chmodSync(dst, 420);
5737
5752
  console.log(`\u2705 \u5DF2\u5B89\u88C5 systemd service: ${dst}`);
5738
5753
  execSync("systemctl daemon-reload", { stdio: "inherit" });
5739
5754
  console.log("\u2705 systemctl daemon-reload \u5B8C\u6210");
5740
5755
  if (enable) {
5741
- execSync("systemctl enable agent_moss", { stdio: "inherit" });
5742
- console.log("\u2705 systemctl enable agent_moss \u5B8C\u6210");
5756
+ execSync("systemctl enable agent-moss", { stdio: "inherit" });
5757
+ console.log("\u2705 systemctl enable agent-moss \u5B8C\u6210");
5743
5758
  }
5744
- console.log("\n\u542F\u52A8\u670D\u52A1\uFF1A sudo systemctl start agent_moss");
5745
- console.log("\u67E5\u770B\u72B6\u6001\uFF1A sudo systemctl status agent_moss");
5759
+ console.log("\n\u542F\u52A8\u670D\u52A1\uFF1A sudo systemctl start agent-moss");
5760
+ console.log("\u67E5\u770B\u72B6\u6001\uFF1A sudo systemctl status agent-moss");
5746
5761
  console.log("\u67E5\u770B\u65E5\u5FD7\uFF1A journalctl -u agent_moss -f");
5747
5762
  break;
5748
5763
  }
@@ -5751,9 +5766,9 @@ async function main() {
5751
5766
  const { execSync } = await import("child_process");
5752
5767
  let systemdInfo = "";
5753
5768
  try {
5754
- const out = execSync("systemctl is-active agent_moss 2>/dev/null || true", { encoding: "utf-8" }).trim();
5769
+ const out = execSync("systemctl is-active agent-moss 2>/dev/null || true", { encoding: "utf-8" }).trim();
5755
5770
  if (out === "active") {
5756
- const show = execSync("systemctl show agent_moss --property=MainPID,ActiveEnterTimestamp,ExecStart 2>/dev/null || true", { encoding: "utf-8" });
5771
+ const show = execSync("systemctl show agent-moss --property=MainPID,ActiveEnterTimestamp,ExecStart 2>/dev/null || true", { encoding: "utf-8" });
5757
5772
  for (const line of show.trim().split("\n")) {
5758
5773
  const [key, ...vals] = line.split("=");
5759
5774
  const val = vals.join("=");
@@ -5831,10 +5846,10 @@ async function main() {
5831
5846
  }
5832
5847
  console.log();
5833
5848
  console.log(" \u542F\u505C\u547D\u4EE4\uFF1A");
5834
- console.log(" systemctl start agent_moss \u542F\u52A8");
5835
- console.log(" systemctl stop agent_moss \u505C\u6B62");
5836
- console.log(" systemctl restart agent_moss \u91CD\u542F");
5837
- console.log(" systemctl status agent_moss \u72B6\u6001");
5849
+ console.log(" systemctl start agent-moss \u542F\u52A8");
5850
+ console.log(" systemctl stop agent-moss \u505C\u6B62");
5851
+ console.log(" systemctl restart agent-moss \u91CD\u542F");
5852
+ console.log(" systemctl status agent-moss \u72B6\u6001");
5838
5853
  console.log(" journalctl -u agent_moss -f \u65E5\u5FD7");
5839
5854
  } else {
5840
5855
  console.log(`\u274C AgentMoss \u670D\u52A1\u672A\u8FD0\u884C`);
@@ -5843,7 +5858,7 @@ async function main() {
5843
5858
  console.log(` \u68C0\u67E5\u65E5\u5FD7\uFF1Ajournalctl -u agent_moss -n 20 --no-pager`);
5844
5859
  } else {
5845
5860
  console.log(` \u542F\u52A8\u65B9\u5F0F\uFF1A`);
5846
- console.log(` systemctl start agent_moss \uFF08systemd\uFF09`);
5861
+ console.log(` systemctl start agent-moss \uFF08systemd\uFF09`);
5847
5862
  console.log(` agent-moss server \uFF08\u524D\u53F0\uFF09`);
5848
5863
  }
5849
5864
  process.exit(1);