dsh-malware-audit:基於 AST 的惡意意圖檢測插件

前言

DeepSeek Harness (dsh) 插件運行在真實的文件系統和進程訪問權限下。現有的審計工具(如 dsh-security-audit)通常擅長檢測能力(例如,插件可以訪問文件系統或網絡),但明確避免判斷意圖,聲明自己僅是“審計輔助”而非“殺毒軟件”。dsh-malware-audit 填補了這一特定空白:它掃描已安裝插件的真實語法樹 (AST),以尋找惡意意圖模式,而不是依賴簽名數據庫或原始文本匹配。

安裝與啓用

  1. 使用官方命令安裝插件。
    dsh plugin --profile <name> add dsh-malware-audit
  1. 將插件名稱添加到 dsh.profile.bundles 列表中,否則插件不會激活。參考配置如下:
    {
      "dsh": {
        "profile": {
          "bundles": [
            "@deepseek-ai/dsh-base",
            "@deepseek-ai/dsh-web-app",
            "dsh-malware-audit"
          ]
        }
      }
    }
  1. 驗證配置是否生效,檢查 malware-audit 配置項是否存在。
    dsh --profile <name> --dump-config

核心功能與用法

手動掃描

在任意會話中輸入 /scan-plugins。該命令會掃描所有聲明瞭 dsh.bundle 的已安裝插件,打印發現總結,並將完整報告保存到當前目錄的 .dsh-malware-audit/scan-<timestamp>.txt 文件中。

定期計劃掃描

默認情況下掃描是隻讀的。啓用定期掃描需在配置文件中設置 scheduleMinutes。

scheduleMinutes: 60

設置大於 0 的數值即可啓用。注意:小於 5 的值會被拒絕。

自動隔離

啓用自動隔離功能 (autoQuarantine: true)。當掃描發現嚴重級別的問題時,插件會被自動隔離。

檢測規則

插件使用啓發式規則進行掃描,不包含已知惡意包簽名數據庫。主要檢測以下模式:

規則 嚴重程度 檢測內容
dynamic-eval critical eval(), new Function(), vm.Script 相關調用
decode-then-execute critical Base64 解碼後直接傳入 eval() 或 require()
fetch-and-execute critical child_process 調用 curl/wget 等外部命令
cross-plugin-write critical 向其他插件的 node_modules 目錄寫入文件
raw-ip-network warning 使用原始 IP 地址而非域名進行網絡請求
env-exfil-shape warning 網絡請求參數引用了 process.env
child-process-shell notice 任意 child_process 調用

配置項說明

在 cordis.patch.yml 中配置插件行爲:

- insert:
    - id: malware-audit
      name: 'dsh-malware-audit'
      config:
        maxFiles: 400
        maxFileBytes: 262144
        ignoreRuleIds: []
        ignorePlugins: []
        scheduleMinutes: 0
        autoQuarantine: false
字段 默認值 描述
maxFiles 400 單插件文件數上限,超過則停止掃描該插件
maxFileBytes 262144 單文件大小上限 (256 KiB),超過則跳過
ignoreRuleIds [] 跳過特定規則的檢測
ignorePlugins [] 跳過特定插件的掃描
scheduleMinutes 0 自動掃描間隔,0 表示禁用
autoQuarantine false 發現嚴重問題時自動隔離

隔離機制與恢復

隔離行爲

當 autoQuarantine: true 且發現嚴重問題時,quarantinePlugin() 會執行:
1. 將插件的 node_modules 條目移動到 .dsh-malware-audit/quarantine/<name>-<timestamp>/。
2. 從所有本地配置文件的 dsh.profile.bundles 列表中移除該插件名稱。
隔離在下次啓動時生效,不會立即停止當前運行的進程。

恢復插件

隔離後需手動恢復:
1. 將目錄從 .dsh-malware-audit/quarantine/ 移回 profile 的 node_modules 下。
2. 在配置的 dsh.profile.bundles 中重新添加該插件名稱。

注意事項

  1. 資源限制:掃描僅限於插件自身目錄,排除 node_modules、.git、lib、dist、build。每插件資源預算爲最多 400 個文件或 256 KiB。
  2. 文件類型:僅掃描 .js/.ts 源文件,不掃描 .md、.json 等文檔文件。
  3. 非殺毒軟件:基於啓發式規則,無已知惡意包簽名數據庫。
  4. 依賴環境:需要 Node.js >= 22。
  5. 誤報風險:雖然是 AST 掃描,但仍有已知誤報可能(如特定 JSDoc 註釋),建議在啓用自動隔離前手動運行幾次掃描確認。

總結

dsh-malware-audit 提供了一種不同於傳統殺毒軟件的靜態代碼分析視角,專門針對惡意意圖模式。它不替代完整的代碼審計,而是作爲一個安全輔助工具,幫助識別插件中潛在的惡意行爲。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜