Skip to content

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

31.6 KB
Raw Blame
id: telemetry-or-history-tampering
version: 1
title: Beacon telemetry or shell history disabled or removed
description: >
  An agent deletes or truncates Beacon data, removes its managed plugin files,
  stops its services, uninstalls or disconnects it, or clears/disables shell
  history. Legitimate cleanup and maintenance can also match. Reading logs or
  history and querying service status do not match. Detection requires the
  command to have reached the runtime log before collection was interrupted.
severity: high
status: experimental
posture: detect
taxonomy:
  beacon_category: risky-command
  owasp_llm: LLM06

# Command prefixes accept environment assignments, relative executable paths, and
# sudo execution options. Value-taking sudo options consume their argument;
# inspection modes such as sudo -l/-v are not execution prefixes.
match: >
  e.event.action == "command.executed" && (
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?(?:rm|unlink|shred)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:(?:[^\\s;&|\\\"\\x27<>]*/)?(?:\\.beacon(?:/[^\\s;&|\\\"\\x27<>]*)?|runtime\\.jsonl(?:\\.[^\\s;&|\\\"\\x27<>]*)?|var/log/beacon-agent(?:/[^\\s;&|\\\"\\x27<>]*)?)|[^\\s;&|\\\"\\x27<>]*/(?:plugins?|extensions)/beacon(?:-endpoint)?(?:\\.[jt]s|/[^\\s;&|\\\"\\x27<>]*)?|[^\\s;&|\\\"\\x27<>]*/\\.(?:bash_history|zsh_history|sh_history))[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?truncate\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:(?:[^\\s;&|\\\"\\x27<>]*/)?(?:\\.beacon(?:/[^\\s;&|\\\"\\x27<>]*)?|runtime\\.jsonl(?:\\.[^\\s;&|\\\"\\x27<>]*)?|var/log/beacon-agent(?:/[^\\s;&|\\\"\\x27<>]*)?)|[^\\s;&|\\\"\\x27<>]*/(?:plugins?|extensions)/beacon(?:-endpoint)?(?:\\.[jt]s|/[^\\s;&|\\\"\\x27<>]*)?|[^\\s;&|\\\"\\x27<>]*/\\.(?:bash_history|zsh_history|sh_history))[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?(?:cat[ \\t]+/dev/null|:|true|(?:echo|printf)(?:[ \\t]+[\\\"\\x27][\\\"\\x27])?)[ \\t]*>[ \\t]*[\\\"\\x27]?(?:(?:[^\\s;&|\\\"\\x27<>]*/)?(?:\\.beacon(?:/[^\\s;&|\\\"\\x27<>]*)?|runtime\\.jsonl(?:\\.[^\\s;&|\\\"\\x27<>]*)?|var/log/beacon-agent(?:/[^\\s;&|\\\"\\x27<>]*)?)|[^\\s;&|\\\"\\x27<>]*/(?:plugins?|extensions)/beacon(?:-endpoint)?(?:\\.[jt]s|/[^\\s;&|\\\"\\x27<>]*)?|[^\\s;&|\\\"\\x27<>]*/\\.(?:bash_history|zsh_history|sh_history))[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?>[ \\t]*[\\\"\\x27]?(?:(?:[^\\s;&|\\\"\\x27<>]*/)?(?:\\.beacon(?:/[^\\s;&|\\\"\\x27<>]*)?|runtime\\.jsonl(?:\\.[^\\s;&|\\\"\\x27<>]*)?|var/log/beacon-agent(?:/[^\\s;&|\\\"\\x27<>]*)?)|[^\\s;&|\\\"\\x27<>]*/(?:plugins?|extensions)/beacon(?:-endpoint)?(?:\\.[jt]s|/[^\\s;&|\\\"\\x27<>]*)?|[^\\s;&|\\\"\\x27<>]*/\\.(?:bash_history|zsh_history|sh_history))[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?systemctl[ \\t]+(?:--user[ \\t]+)?(?:stop|disable|mask|kill)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:[^\\s;&|\\\"\\x27]*/)?(?:com\\.beacon\\.endpoint\\.[\\w.*-]+|beacon-(?:collector|otelcol|asymptote-forwarder|inventory|session-sync|updater)(?:\\.(?:service|timer))?)[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?service[ \\t]+beacon-collector[ \\t]+stop(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?launchctl[ \\t]+(?:unload|bootout|remove|stop|kill)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:[^\\s;&|\\\"\\x27]*/)?(?:com\\.beacon\\.endpoint\\.[\\w.*-]+|beacon-(?:collector|otelcol|asymptote-forwarder|inventory|session-sync|updater)(?:\\.(?:service|timer))?)[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?(?:pkill|killall)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:[^\\s;&|\\\"\\x27]*/)?(?:com\\.beacon\\.endpoint\\.[\\w.*-]+|beacon-(?:collector|otelcol|asymptote-forwarder|inventory|session-sync|updater)(?:\\.(?:service|timer))?)[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?beacon[ \\t]+endpoint[ \\t]+(?:uninstall|disconnect|hooks[ \\t]+uninstall)(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?history[ \\t]+(?:-c|-w[ \\t]+/dev/null)(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?(?:unset[ \\t]+HISTFILE|(?:export[ \\t]+)?(?:HISTFILE[ \\t]*=[ \\t]*(?:/dev/null|[\\\"\\x27][\\\"\\x27])|(?:HISTSIZE|HISTFILESIZE)[ \\t]*=[ \\t]*0))(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?(?:export[ \\t]+)?HISTFILE=[ \\t]*(?:$|[;&|\\n#]|[0-9]*[<>]|&>)") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?set[ \\t]+\\+o[ \\t]+history(?:[ \\t]|$|[;&|\\n<>#])") ||
    e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*(?:sudo[ \\t]+(?:(?:-[ugCDRTp][ \\t]*(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|--(?:user|group|close-from|chdir|chroot|command-timeout|prompt)(?:=|[ \\t]+)(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+|-[nEHkPSb]+|--(?:non-interactive|preserve-env(?:=[A-Za-z0-9_,]+)?|set-home|reset-timestamp|stdin|background))[ \\t]+)*(?:--[ \\t]+)?(?:[A-Za-z_][A-Za-z0-9_]*=(?:(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)?[ \\t]+)*)?(?:[^\\s;&|<>#\\x27\"`=]*/)?(?:rm|unlink|shred|truncate)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?[^\\s;&|\\\"\\x27]*/\\.(?:bash_history|zsh_history|sh_history)[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])")
  )

emit:
  reason: "Beacon telemetry or shell history disabled or removed"

tests:
  - name: match_1_rm_rf_beacon
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm -rf ~/.beacon/" }
        session: { id: s1 }
  - name: match_2_rm_var_log_beacon_agent_runtime_jsonl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm /var/log/beacon-agent/runtime.jsonl" }
        session: { id: s1 }
  - name: match_3_truncate_s_0_runtime_jsonl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "truncate -s 0 runtime.jsonl" }
        session: { id: s1 }
  - name: match_4_beacon_endpoint_logs_runtime_jsonl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: ": > ~/.beacon/endpoint/logs/runtime.jsonl" }
        session: { id: s1 }
  - name: match_5_cat_dev_null_runtime_jsonl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cat /dev/null > runtime.jsonl" }
        session: { id: s1 }
  - name: match_6_runtime_jsonl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: ">runtime.jsonl" }
        session: { id: s1 }
  - name: match_7_echo_runtime_jsonl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "echo \"\" > runtime.jsonl" }
        session: { id: s1 }
  - name: match_8_systemctl_stop_beacon_collector_service
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl stop beacon-collector.service" }
        session: { id: s1 }
  - name: match_9_service_beacon_collector_stop
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "service beacon-collector stop" }
        session: { id: s1 }
  - name: match_10_systemctl_user_disable_beacon_collector_service
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl --user disable beacon-collector.service" }
        session: { id: s1 }
  - name: match_11_launchctl_unload_library_launchagents_com_beacon_endpoint_collector_plist
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "launchctl unload ~/Library/LaunchAgents/com.beacon.endpoint.collector.plist" }
        session: { id: s1 }
  - name: match_12_launchctl_bootout_gui_501_com_beacon_endpoint_collector
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "launchctl bootout gui/501/com.beacon.endpoint.collector" }
        session: { id: s1 }
  - name: match_13_pkill_f_beacon_otelcol
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "pkill -f beacon-otelcol" }
        session: { id: s1 }
  - name: match_14_killall_beacon_otelcol
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "killall beacon-otelcol" }
        session: { id: s1 }
  - name: match_15_beacon_endpoint_uninstall
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "beacon endpoint uninstall" }
        session: { id: s1 }
  - name: match_16_beacon_endpoint_disconnect
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "beacon endpoint disconnect" }
        session: { id: s1 }
  - name: match_17_beacon_endpoint_hooks_uninstall
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "beacon endpoint hooks uninstall" }
        session: { id: s1 }
  - name: match_18_rm_config_opencode_plugins_beacon_ts
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm ~/.config/opencode/plugins/beacon.ts" }
        session: { id: s1 }
  - name: match_19_rm_cline_plugins_beacon_ts
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm ~/.cline/plugins/beacon.ts" }
        session: { id: s1 }
  - name: match_20_rm_pi_agent_extensions_beacon_ts
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm ~/.pi/agent/extensions/beacon.ts" }
        session: { id: s1 }
  - name: match_21_rm_rf_openclaw_extensions_beacon_endpoint
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm -rf ~/.openclaw/extensions/beacon-endpoint" }
        session: { id: s1 }
  - name: match_22_launchctl_kill_sigterm_gui_501_com_beacon_endpoint_collector
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "launchctl kill SIGTERM gui/501/com.beacon.endpoint.collector" }
        session: { id: s1 }
  - name: match_23_history_c
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "history -c" }
        session: { id: s1 }
  - name: match_24_histfile
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "HISTFILE=" }
        session: { id: s1 }
  - name: match_25_export_histfile
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "export HISTFILE=" }
        session: { id: s1 }
  - name: match_26_unset_histfile
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "unset HISTFILE" }
        session: { id: s1 }
  - name: match_27_export_histfile_dev_null
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "export HISTFILE=/dev/null" }
        session: { id: s1 }
  - name: match_28_histsize_0
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "HISTSIZE=0" }
        session: { id: s1 }
  - name: match_29_printf_runtime_jsonl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "printf \"\" > runtime.jsonl" }
        session: { id: s1 }
  - name: match_30_bash_history
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: ": > ~/.bash_history" }
        session: { id: s1 }
  - name: match_31_cat_dev_null_zsh_history
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cat /dev/null > ~/.zsh_history" }
        session: { id: s1 }
  - name: match_32_set_o_history
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "set +o history" }
        session: { id: s1 }
  - name: match_33_rm_zsh_history
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm ~/.zsh_history" }
        session: { id: s1 }
  - name: no_match_1_beacon_endpoint_status
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "beacon endpoint status" }
        session: { id: s1 }
  - name: no_match_2_tail_f_beacon_endpoint_logs_runtime_jsonl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tail -f ~/.beacon/endpoint/logs/runtime.jsonl" }
        session: { id: s1 }
  - name: no_match_3_cat_var_log_beacon_agent_runtime_jsonl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat /var/log/beacon-agent/runtime.jsonl" }
        session: { id: s1 }
  - name: no_match_4_systemctl_status_beacon_collector_service
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl status beacon-collector.service" }
        session: { id: s1 }
  - name: no_match_5_launchctl_print_gui_501_com_beacon_endpoint_collector
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "launchctl print gui/501/com.beacon.endpoint.collector" }
        session: { id: s1 }
  - name: no_match_6_history
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "history" }
        session: { id: s1 }
  - name: no_match_7_history_10
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "history 10" }
        session: { id: s1 }
  - name: no_match_8_rm_notes_txt_cat_runtime_jsonl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rm notes.txt; cat runtime.jsonl" }
        session: { id: s1 }
  - name: no_match_9_rm_notes_txt_echo_beacon
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rm notes.txt\necho ~/.beacon/" }
        session: { id: s1 }
  - name: no_match_10_systemctl_status_beacon_collector_service_echo_stop
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl status beacon-collector.service; echo stop" }
        session: { id: s1 }
  - name: no_match_11_rm_plugins_unrelated_ts
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rm ./plugins/unrelated.ts" }
        session: { id: s1 }
  - name: no_match_12_echo_runtime_jsonl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "echo runtime.jsonl" }
        session: { id: s1 }
  - name: no_match_13_cat_runtime_jsonl_backup_jsonl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat runtime.jsonl > backup.jsonl" }
        session: { id: s1 }
  - name: no_match_14_echo_hello_runtime_jsonl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "echo hello >> runtime.jsonl" }
        session: { id: s1 }
  - name: no_match_15_histsize_1000
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "HISTSIZE=1000" }
        session: { id: s1 }
  - name: no_match_16_set_o_history
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "set -o history" }
        session: { id: s1 }
  - name: no_match_17_rm_file_runtime_jsonl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rm file # runtime.jsonl" }
        session: { id: s1 }
  - name: no_match_18_systemctl_status_stop_beacon_collector_service
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl status # stop beacon-collector.service" }
        session: { id: s1 }
  - name: no_match_19_service_beacon_collector_status
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "service beacon-collector status" }
        session: { id: s1 }
  - name: no_match_20_echo_history_c
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "echo history -c" }
        session: { id: s1 }
  - name: no_match_21_rm_beacon_backup
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rm ~/.beacon-backup" }
        session: { id: s1 }
  - name: no_match_22_rm_runtime_jsonl_notes
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rm runtime.jsonl-notes" }
        session: { id: s1 }
  - name: newline
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "true\nrm -rf ~/.beacon/" }
        session: { id: s1 }
  - name: then
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "if true; then rm -rf ~/.beacon/" }
        session: { id: s1 }
  - name: do
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "for x in a; do rm -rf ~/.beacon/" }
        session: { id: s1 }
  - name: else
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "if false; then true; else rm -rf ~/.beacon/" }
        session: { id: s1 }
  - name: redirect_or_comment_1
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm -rf ~/.beacon/ 2>/dev/null" }
        session: { id: s1 }
  - name: redirect_or_comment_2
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm -rf ~/.beacon/ >/dev/null 2>&1" }
        session: { id: s1 }
  - name: redirect_or_comment_3
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm -rf ~/.beacon/&>/dev/null" }
        session: { id: s1 }
  - name: redirect_or_comment_4
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "rm -rf ~/.beacon/ # maintenance" }
        session: { id: s1 }
  - name: mention_1
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "echo \"rm -rf ~/.beacon/\"" }
        session: { id: s1 }
  - name: mention_2
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "grep -F \"rm -rf ~/.beacon/\"" }
        session: { id: s1 }
  - name: mention_3
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git commit -m \"rm -rf ~/.beacon/\"" }
        session: { id: s1 }
  - name: wrong_event_action
    verdict: no_match
    events:
      - event: { action: tool.invoked }
        command: { command: "rm -rf ~/.beacon/" }
        session: { id: s1 }
  - name: stop_cloud_forwarder
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "sudo systemctl stop beacon-asymptote-forwarder" }
        session: { id: s1 }
  - name: disable_cloud_forwarder
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl disable --now beacon-asymptote-forwarder.service" }
        session: { id: s1 }
  - name: mask_inventory_timer
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl mask beacon-inventory.timer" }
        session: { id: s1 }
  - name: stop_session_sync_timer
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl stop beacon-session-sync.timer" }
        session: { id: s1 }
  - name: mask_session_sync_service
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "sudo systemctl mask beacon-session-sync.service" }
        session: { id: s1 }
  - name: stop_inventory_service
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl stop beacon-inventory.service" }
        session: { id: s1 }
  - name: stop_updater_service
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl stop beacon-updater.service" }
        session: { id: s1 }
  - name: disable_updater_timer
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl disable beacon-updater.timer" }
        session: { id: s1 }
  - name: pkill_cloud_forwarder
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "pkill -f beacon-asymptote-forwarder" }
        session: { id: s1 }
  - name: killall_inventory
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "killall beacon-inventory" }
        session: { id: s1 }
  - name: pkill_updater
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "pkill -f beacon-updater" }
        session: { id: s1 }
  - name: sudo_systemctl_options
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "sudo -n -u root systemctl stop beacon-asymptote-forwarder" }
        session: { id: s1 }
  - name: systemctl_env
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus systemctl --user stop beacon-collector" }
        session: { id: s1 }
  - name: relative_systemctl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "bin/systemctl stop beacon-inventory.timer" }
        session: { id: s1 }
  - name: forwarder_status
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl status beacon-asymptote-forwarder.service" }
        session: { id: s1 }
  - name: inventory_status
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl status beacon-inventory.timer" }
        session: { id: s1 }
  - name: updater_start
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl start beacon-updater.timer" }
        session: { id: s1 }
  - name: unrelated_unit
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl stop beacon-unrelated.service" }
        session: { id: s1 }
  - name: sudo_service_echo
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "sudo -u root echo \"systemctl stop beacon-inventory.timer\"" }
        session: { id: s1 }
  - name: unit_suffix
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "systemctl stop beacon-inventory.timer-backup" }
        session: { id: s1 }
  - name: env_status
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus systemctl --user status beacon-collector" }
        session: { id: s1 }