Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

4.6 KB
Raw Blame
id: os-keychain-secret-read
version: 1
title: Secret read from the OS keychain or secret service
description: >
  A command reads a stored secret out of the operating system's credential store:
  macOS security find-generic-password or find-internet-password with -w or -g
  (which print the password, not just the item's attributes) or dump-keychain -d;
  Linux secret-tool lookup or search, or kwallet-query -r; Windows vaultcmd
  /listcreds, PowerShell Get-StoredCredential, Get-Secret -AsPlainText, or the WinRT
  PasswordVault. The keychain holds browser, Wi-Fi, VPN, Git and cloud CLI
  credentials, so an agent reading one has stepped outside its project's secrets.
  Commands that only list or describe items (find-identity, find-certificate,
  find-generic-password without -w/-g, secret-tool store, cmdkey /list) do not fire.
severity: high
status: stable
posture: detect
taxonomy:
  beacon_category: credential-access
  owasp_llm: LLM02
  mitre_atlas: AML.T0024

match: >
  e.event.action == "command.executed" && (
    e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(secret-tool\\s+(lookup|search)\\b|kwallet-query\\s+([^;&|\\n]*\\s)?(-r|--read-password)\\b|vaultcmd(\\.exe)?\\s+/listcreds\\b)") ||
    e.command.command.matches("(?i)\\b(find-(generic|internet)-password\\b([^;&|\\n]*\\s)?(?-i:-[a-zA-Z]*[wg][a-zA-Z]*)\\b|dump-keychain\\b([^;&|\\n]*\\s)?(?-i:-[a-zA-Z]*d[a-zA-Z]*)\\b|get-storedcredential|get-secret\\s+([^;&|\\n]*\\s)?-asplaintext|\\[windows\\.security\\.credentials\\.passwordvault\\])")
  )

emit:
  reason: "Secret read from the OS keychain or secret service (security -w, secret-tool lookup, kwallet-query, Windows Credential Manager)"

tests:
  - name: macos_generic_password_w
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "security find-generic-password -s 'GitHub' -w" }
        session: { id: s1 }
  - name: macos_internet_password_g
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "security find-internet-password -s github.com -g" }
        session: { id: s1 }
  - name: macos_dump_keychain_decrypt
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "security dump-keychain -d ~/Library/Keychains/login.keychain-db" }
        session: { id: s1 }
  - name: macos_chained
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "TOKEN=$(security find-generic-password -a me -s npm -w) && echo ok" }
        session: { id: s1 }
  - name: linux_secret_tool_lookup
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "secret-tool lookup service github" }
        session: { id: s1 }
  - name: linux_kwallet_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "kwallet-query -r github kdewallet" }
        session: { id: s1 }
  - name: windows_vaultcmd
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "vaultcmd /listcreds:\"Windows Credentials\" /all" }
        session: { id: s1 }
  - name: powershell_get_secret_plaintext
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "Get-Secret -Name GitHubToken -AsPlainText" }
        session: { id: s1 }
  - name: macos_attribute_filter_upper_g
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "security find-generic-password -s build -G ci-label" }
        session: { id: s1 }
  - name: macos_attribute_filter_clustered
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "security find-generic-password -s build -aG me" }
        session: { id: s1 }
  - name: macos_find_identity
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "security find-identity -v -p codesigning" }
        session: { id: s1 }
  - name: macos_find_generic_attributes_only
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "security find-generic-password -s 'GitHub'" }
        session: { id: s1 }
  - name: linux_secret_tool_store
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "secret-tool store --label=x service x" }
        session: { id: s1 }
  - name: windows_cmdkey_list
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cmdkey /list" }
        session: { id: s1 }