The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
rules: cover service teardown and wrapped destructive commands
Justin D'Souza2e336c66e7ce
diff --git a/rules/risky-command/cloud-permission-grant.rule.yaml b/rules/risky-command/cloud-permission-grant.rule.yamlindex 34207e77..725bbb1d 100644--- a/rules/risky-command/cloud-permission-grant.rule.yaml+++ b/rules/risky-command/cloud-permission-grant.rule.yaml@@ -13,14 +13,17 @@ taxonomy:beacon_category: risky-commandowasp_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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?aws(?:[ \\t]+--(?:profile|region|endpoint-url)[ \\t]+[^\\s;&|]+)*[ \\t]+iam[ \\t]+(?:create-access-key|attach-(?:user|group|role)-policy|put-(?:user|group|role)-policy|create-policy|create-policy-version|add-user-to-group)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+iam[ \\t]+service-accounts[ \\t]+keys[ \\t]+create(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+(?:projects|organizations|folders|iam[ \\t]+service-accounts)[ \\t]+(?:add-iam-policy-binding|set-iam-policy)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+(?:storage[ \\t]+buckets|run[ \\t]+services|secrets)[ \\t]+add-iam-policy-binding(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?az[ \\t]+(?:role[ \\t]+assignment[ \\t]+create|ad[ \\t]+sp[ \\t]+credential[ \\t]+reset)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?kubectl(?:[ \\t]+(?:-n|--namespace|--context|--kubeconfig)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+create[ \\t]+(?:rolebinding|clusterrolebinding)(?:[ \\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\"`=]*/)?aws(?:[ \\t]+--(?:profile|region|endpoint-url)[ \\t]+[^\\s;&|]+)*[ \\t]+iam[ \\t]+(?:create-access-key|attach-(?:user|group|role)-policy|put-(?:user|group|role)-policy|create-policy|create-policy-version|add-user-to-group)(?:[ \\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\"`=]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+iam[ \\t]+service-accounts[ \\t]+keys[ \\t]+create(?:[ \\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\"`=]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+(?:projects|organizations|folders|iam[ \\t]+service-accounts)[ \\t]+(?:add-iam-policy-binding|set-iam-policy)(?:[ \\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\"`=]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+(?:storage[ \\t]+buckets|run[ \\t]+services|secrets)[ \\t]+add-iam-policy-binding(?:[ \\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\"`=]*/)?az[ \\t]+(?:role[ \\t]+assignment[ \\t]+create|ad[ \\t]+sp[ \\t]+credential[ \\t]+reset)(?:[ \\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\"`=]*/)?kubectl(?:[ \\t]+(?:-n|--namespace|--context|--kubeconfig)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+create[ \\t]+(?:rolebinding|clusterrolebinding)(?:[ \\t]|$|[;&|\\n<>#])"))emit:@@ -285,3 +288,39 @@ tests:- event: { action: tool.invoked }command: { command: "aws iam create-access-key --user-name agent" }session: { id: s1 }+ - name: aws_profile_env+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "AWS_PROFILE=prod aws iam create-access-key --user-name agent" }+ session: { id: s1 }+ - name: sudo_aws+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u deploy aws iam attach-user-policy --user-name agent --policy-arn arn:aws:iam::aws:policy/AdministratorAccess" }+ session: { id: s1 }+ - name: relative_aws+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "AWS_PROFILE=prod bin/aws iam create-access-key --user-name agent" }+ session: { id: s1 }+ - name: aws_profile_read+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "AWS_PROFILE=prod aws iam list-users" }+ session: { id: s1 }+ - name: sudo_cloud_echo+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u deploy echo \"aws iam create-access-key\"" }+ session: { id: s1 }+ - name: env_cloud_mention+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "NOTE=\"aws iam create-access-key\" echo ok" }+ session: { id: s1 }diff --git a/rules/risky-command/database-drop-or-flush.rule.yaml b/rules/risky-command/database-drop-or-flush.rule.yamlindex 65d334bc..cd2dea17 100644--- a/rules/risky-command/database-drop-or-flush.rule.yaml+++ b/rules/risky-command/database-drop-or-flush.rule.yaml@@ -12,16 +12,19 @@ taxonomy:beacon_category: risky-commandowasp_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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:psql|mysql|mariadb)\\b[^;&|\\n#]*[ \\t](?:-c|-e|--command|--execute)(?:[ \\t]+|=)[\\\"\\x27]?[ \\t]*(?:(?i:DROP)[ \\t]+(?i:TABLE|DATABASE|SCHEMA|INDEX|VIEW|MATERIALIZED|SEQUENCE|TYPE|FUNCTION|PROCEDURE|TRIGGER|EXTENSION|ROLE|USER)\\b|(?i:TRUNCATE)[ \\t]+[a-zA-Z_\\\"\\x27])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?sqlite3(?:[ \\t]+-[\\w-]+)*[ \\t]+[^\\s;&|]+[ \\t][\\\"\\x27][ \\t]*(?i:DROP|TRUNCATE)[ \\t]+(?i:TABLE|INDEX|VIEW|TRIGGER)\\b") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?dropdb(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?mysqladmin(?:[ \\t]+(?:-[upPhS]|--(?:user|password|port|host|socket))(?:=|[ \\t]+)?[^\\s;&|]+|[ \\t]+(?:--force|-f))*[ \\t]+drop(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?redis-cli(?:[ \\t]+(?:-[hpansu]|--(?:host|port|pass|user|uri))(?:=|[ \\t]+)[^\\s;&|]+|[ \\t]+--(?:tls|raw|no-auth-warning))*[ \\t]+(?i:FLUSHALL|FLUSHDB)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:bundle[ \\t]+exec[ \\t]+)?(?:rails|rake)[ \\t]+db:(?:drop|reset|migrate:reset)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:(?:npx|pnpm[ \\t]+exec|bunx)[ \\t]+)?prisma[ \\t]+migrate[ \\t]+reset(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:python[0-9.]*[ \\t]+(?:[^\\s;&|]*/)?manage\\.py|django-admin)[ \\t]+flush(?:[ \\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\"`=]*/)?(?:psql|mysql|mariadb)\\b[^;&|\\n#]*[ \\t](?:-c|-e|--command|--execute)(?:[ \\t]+|=)[\\\"\\x27]?[ \\t]*(?:(?i:DROP)[ \\t]+(?i:TABLE|DATABASE|SCHEMA|INDEX|VIEW|MATERIALIZED|SEQUENCE|TYPE|FUNCTION|PROCEDURE|TRIGGER|EXTENSION|ROLE|USER)\\b|(?i:TRUNCATE)[ \\t]+[a-zA-Z_\\\"\\x27])") ||+ 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\"`=]*/)?sqlite3(?:[ \\t]+-[\\w-]+)*[ \\t]+[^\\s;&|]+[ \\t][\\\"\\x27][ \\t]*(?i:DROP|TRUNCATE)[ \\t]+(?i:TABLE|INDEX|VIEW|TRIGGER)\\b") ||+ 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\"`=]*/)?dropdb(?:[ \\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\"`=]*/)?mysqladmin(?:[ \\t]+(?:-[upPhS]|--(?:user|password|port|host|socket))(?:=|[ \\t]+)?[^\\s;&|]+|[ \\t]+(?:--force|-f))*[ \\t]+drop(?:[ \\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\"`=]*/)?redis-cli(?:[ \\t]+(?:-[hpansu]|--(?:host|port|pass|user|uri))(?:=|[ \\t]+)[^\\s;&|]+|[ \\t]+--(?:tls|raw|no-auth-warning))*[ \\t]+(?i:FLUSHALL|FLUSHDB)(?:[ \\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\"`=]*/)?(?:bundle[ \\t]+exec[ \\t]+)?(?:rails|rake)[ \\t]+db:(?:drop|reset|migrate:reset)(?:[ \\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\"`=]*/)?(?:(?:npx|pnpm[ \\t]+exec|bunx)[ \\t]+)?prisma[ \\t]+migrate[ \\t]+reset(?:[ \\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\"`=]*/)?(?:python[0-9.]*[ \\t]+(?:[^\\s;&|]*/)?manage\\.py|django-admin)[ \\t]+flush(?:[ \\t]|$|[;&|\\n<>#])"))emit:@@ -286,3 +289,105 @@ tests:- event: { action: tool.invoked }command: { command: "psql app -c \"DROP TABLE users;\"" }session: { id: s1 }+ - name: sudo_postgres_dropdb+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u postgres dropdb app" }+ session: { id: s1 }+ - name: sudo_postgres_psql+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u postgres psql -c \"DROP DATABASE app\"" }+ session: { id: s1 }+ - name: postgres_env+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "PGPASSWORD=secret psql -h db -c \"DROP TABLE users\"" }+ session: { id: s1 }+ - name: mysql_env+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "MYSQL_PWD=x mysql -e \"DROP DATABASE app\"" }+ session: { id: s1 }+ - name: relative_rails+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "RAILS_ENV=production bin/rails db:drop" }+ session: { id: s1 }+ - name: sudo_attached_user+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -n -upostgres dropdb app" }+ session: { id: s1 }+ - name: sudo_long_user+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "sudo --user=postgres --group postgres -- dropdb app" }+ session: { id: s1 }+ - name: env_before_and_after_sudo+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "PGHOST=db sudo -u postgres PGPASSWORD=secret psql -c \"DROP TABLE users\"" }+ session: { id: s1 }+ - name: quoted_assignment+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "PGPASSWORD=\"has spaces\" PGHOST=db psql -c \"DROP TABLE users\"" }+ session: { id: s1 }+ - name: empty_assignment+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "PGHOST= psql -c \"DROP TABLE users\"" }+ session: { id: s1 }+ - name: sudo_user_not_command+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u dropdb echo app" }+ session: { id: s1 }+ - name: sudo_list_only+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -l -u postgres dropdb app" }+ session: { id: s1 }+ - name: sudo_validate_only+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -v dropdb app" }+ session: { id: s1 }+ - name: env_mentions_tool+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "NOTE=\"dropdb app\" echo ok" }+ session: { id: s1 }+ - name: env_read_only+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "PGPASSWORD=secret psql -c \"SELECT 1\"" }+ session: { id: s1 }+ - name: relative_rails_read_only+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "RAILS_ENV=production bin/rails db:version" }+ session: { id: s1 }+ - name: sudo_echo+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u postgres echo \"dropdb app\"" }+ session: { id: s1 }diff --git a/rules/risky-command/infrastructure-teardown.rule.yaml b/rules/risky-command/infrastructure-teardown.rule.yamlindex 60b9412b..c4446e50 100644--- a/rules/risky-command/infrastructure-teardown.rule.yaml+++ b/rules/risky-command/infrastructure-teardown.rule.yaml@@ -13,17 +13,20 @@ taxonomy:beacon_category: risky-commandowasp_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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:terraform|tofu)(?:[ \\t]+-chdir=[^\\s;&|]+)?[ \\t]+destroy(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:pulumi|cdk)[ \\t]+destroy(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?kubectl(?:[ \\t]+(?:-n|--namespace|--context|--kubeconfig)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+delete[ \\t]+(?:namespace|namespaces|ns)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?aws(?:[ \\t]+--(?:profile|region|endpoint-url)[ \\t]+[^\\s;&|]+)*[ \\t]+(?:s3[ \\t]+rb|(?:cloudformation[ \\t]+delete-stack|eks[ \\t]+delete-cluster)|s3api[ \\t]+delete-bucket)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?aws(?:[ \\t]+--(?:profile|region|endpoint-url)[ \\t]+[^\\s;&|]+)*[ \\t]+s3[ \\t]+rm\\b[^;&|\\n#]*[ \\t]--recursive(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+(?:projects[ \\t]+delete|container[ \\t]+clusters[ \\t]+delete|storage[ \\t]+buckets[ \\t]+delete)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+storage[ \\t]+rm\\b[^;&|\\n#]*[ \\t](?:--recursive|-r)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?gsutil[ \\t]+(?:-m[ \\t]+)?(?:rb(?:[ \\t]|$|[;&|\\n<>#])|rm\\b[^;&|\\n#]*[ \\t]-[a-zA-Z]*[rR][a-zA-Z]*(?:[ \\t]|$|[;&|\\n<>#]))") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?az[ \\t]+(?:group[ \\t]+delete|aks[ \\t]+delete|storage[ \\t]+container[ \\t]+delete)(?:[ \\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\"`=]*/)?(?:terraform|tofu)(?:[ \\t]+-chdir=[^\\s;&|]+)?[ \\t]+(?:destroy|apply(?:[ \\t]+(?:[^\\s;&|<>#\\x27\"`]+|\\x27[^\\x27\\n]*\\x27|\"[^\"\\n]*\")+)*?[ \\t]+-destroy(?:=true)?)(?:[ \\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\"`=]*/)?(?:pulumi|cdk)[ \\t]+destroy(?:[ \\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\"`=]*/)?kubectl(?:[ \\t]+(?:-n|--namespace|--context|--kubeconfig)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+delete[ \\t]+(?:namespace|namespaces|ns)(?:/[^\\s;&|<>#\\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\"`=]*/)?aws(?:[ \\t]+--(?:profile|region|endpoint-url)[ \\t]+[^\\s;&|]+)*[ \\t]+(?:s3[ \\t]+rb|(?:cloudformation[ \\t]+delete-stack|eks[ \\t]+delete-cluster)|s3api[ \\t]+delete-bucket)(?:[ \\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\"`=]*/)?aws(?:[ \\t]+--(?:profile|region|endpoint-url)[ \\t]+[^\\s;&|]+)*[ \\t]+s3[ \\t]+rm\\b[^;&|\\n#]*[ \\t]--recursive(?:[ \\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\"`=]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+(?:projects[ \\t]+delete|container[ \\t]+clusters[ \\t]+delete|storage[ \\t]+buckets[ \\t]+delete)(?:[ \\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\"`=]*/)?gcloud(?:[ \\t]+--(?:project|account|configuration)(?:=|[ \\t]+)[^\\s;&|]+)*[ \\t]+storage[ \\t]+rm\\b[^;&|\\n#]*[ \\t](?:--recursive|-r)(?:[ \\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\"`=]*/)?gsutil[ \\t]+(?:-m[ \\t]+)?(?:rb(?:[ \\t]|$|[;&|\\n<>#])|rm\\b[^;&|\\n#]*[ \\t]-[a-zA-Z]*[rR][a-zA-Z]*(?:[ \\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\"`=]*/)?az[ \\t]+(?:group[ \\t]+delete|aks[ \\t]+delete|storage[ \\t]+container[ \\t]+delete)(?:[ \\t]|$|[;&|\\n<>#])"))emit:@@ -324,3 +327,117 @@ tests:- event: { action: tool.invoked }command: { command: "terraform destroy -auto-approve" }session: { id: s1 }+ - name: terraform_apply_destroy+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "terraform apply -destroy -auto-approve" }+ session: { id: s1 }+ - name: tofu_apply_destroy+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "tofu apply -destroy" }+ session: { id: s1 }+ - name: terraform_apply_flags+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "terraform -chdir=infra apply -auto-approve -destroy" }+ session: { id: s1 }+ - name: terraform_destroy_true+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "terraform apply -destroy=true" }+ session: { id: s1 }+ - name: namespace_slash+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "kubectl delete namespace/prod" }+ session: { id: s1 }+ - name: ns_slash+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "kubectl delete ns/prod" }+ session: { id: s1 }+ - name: kubectl_env+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "KUBECONFIG=/tmp/prod kubectl delete ns/prod" }+ session: { id: s1 }+ - name: sudo_kubectl+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u deploy kubectl delete namespace/prod" }+ session: { id: s1 }+ - name: relative_terraform+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "TF_WORKSPACE=prod ./bin/terraform apply -destroy" }+ session: { id: s1 }+ - name: plan_destroy+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "terraform plan -destroy" }+ session: { id: s1 }+ - name: tofu_plan_destroy+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "tofu plan -destroy" }+ session: { id: s1 }+ - name: apply_not_destroy+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "terraform apply -auto-approve" }+ session: { id: s1 }+ - name: apply_destroy_false+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "terraform apply -destroy=false" }+ session: { id: s1 }+ - name: apply_quoted_flag+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "terraform apply -var \"note=use -destroy later\"" }+ session: { id: s1 }+ - name: separate_destroy_flag+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "terraform apply; echo -destroy" }+ session: { id: s1 }+ - name: pod_slash+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "kubectl delete pod/app" }+ session: { id: s1 }+ - name: kubectl_env_get+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "KUBECONFIG=/tmp/prod kubectl get ns/prod" }+ session: { id: s1 }+ - name: namespace_prefix+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "kubectl delete ns-example" }+ session: { id: s1 }+ - name: sudo_terraform_echo+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u deploy echo \"terraform apply -destroy\"" }+ session: { id: s1 }diff --git a/rules/risky-command/telemetry-or-history-tampering.rule.yaml b/rules/risky-command/telemetry-or-history-tampering.rule.yamlindex 321aede7..8dfa0b05 100644--- a/rules/risky-command/telemetry-or-history-tampering.rule.yaml+++ b/rules/risky-command/telemetry-or-history-tampering.rule.yaml@@ -14,22 +14,25 @@ taxonomy:beacon_category: risky-commandowasp_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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?: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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?: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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?>[ \\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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?systemctl[ \\t]+(?:--user[ \\t]+)?(?:stop|disable|mask|kill)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:[^\\s;&|\\\"\\x27]*/)?(?:com\\.beacon\\.endpoint\\.[\\w.*-]+|beacon-collector(?:\\.service)?|beacon-otelcol)[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?service[ \\t]+beacon-collector[ \\t]+stop(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?launchctl[ \\t]+(?:unload|bootout|remove|stop|kill)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:[^\\s;&|\\\"\\x27]*/)?(?:com\\.beacon\\.endpoint\\.[\\w.*-]+|beacon-collector(?:\\.service)?|beacon-otelcol)[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:pkill|killall)\\b[^;&|\\n#]*[ \\t][\\\"\\x27]?(?:[^\\s;&|\\\"\\x27]*/)?(?:com\\.beacon\\.endpoint\\.[\\w.*-]+|beacon-collector(?:\\.service)?|beacon-otelcol)[\\\"\\x27]?(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?beacon[ \\t]+endpoint[ \\t]+(?:uninstall|disconnect|hooks[ \\t]+uninstall)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?history[ \\t]+(?:-c|-w[ \\t]+/dev/null)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?: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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:export[ \\t]+)?HISTFILE=[ \\t]*(?:$|[;&|\\n#]|[0-9]*[<>]|&>)") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?set[ \\t]+\\+o[ \\t]+history(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?(?:rm|unlink|shred|truncate)\\b[^;&|\\n#]*[ \\t][\\\"\\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\"`=]*/)?(?: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|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|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|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:@@ -438,3 +441,117 @@ tests:- 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_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 }diff --git a/rules/source-control/git-local-work-discarded.rule.yaml b/rules/source-control/git-local-work-discarded.rule.yamlindex 8a4b1a2d..2163098f 100644--- a/rules/source-control/git-local-work-discarded.rule.yaml+++ b/rules/source-control/git-local-work-discarded.rule.yaml@@ -13,15 +13,18 @@ taxonomy:beacon_category: source-controlowasp_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]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+reset\\b[^;&|\\n#]*[ \\t]--hard(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+clean[ \\t]+(?:-[dfxXq]+[ \\t]+)*(?:-[dxXq]*f[dfxXq]*[dxX][dfxXq]*|-[dfxXq]*[dxX][dfxXq]*f[dfxXq]*|-[dfxXq]*f[dfxXq]*[ \\t]+(?:-[dfxXq]+[ \\t]+)*-[dfxXq]*[dxX][dfxXq]*|-[dfxXq]*[dxX][dfxXq]*[ \\t]+(?:-[dfxXq]+[ \\t]+)*-[dfxXq]*f[dfxXq]*)(?:[ \\t]+-[dfxXq]+)*(?:[ \\t]+--)?(?:[ \\t]+[^\\s;&|<>#-][^\\s;&|<>#]*)*[ \\t]*(?:$|[;&|\\n#]|[0-9]*[<>]|&>)") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+checkout[ \\t]+(?:HEAD[ \\t]+)?(?:--[ \\t]+)?[\\\"\\x27]?(?:\\.|:/)[\\\"\\x27]?[ \\t]*(?:$|[;&|\\n#]|[0-9]*[<>]|&>)") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+checkout[ \\t]+(?:-f|--force)(?:[ \\t]|$|[;&|\\n<>#])") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+restore[ \\t]+(?:(?:(?:--source|-s)(?:=|[ \\t]+)[^\\s;&|]+|--worktree|-W)[ \\t]+)*(?:--[ \\t]+)?[\\\"\\x27]?(?:\\.|:/)[\\\"\\x27]?[ \\t]*(?:$|[;&|\\n#]|[0-9]*[<>]|&>)") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+restore[ \\t]+(?:(?:--staged|-S)[ \\t]+)?(?:--worktree|-W|-SW|-WS)[ \\t]+(?:(?:--staged|-S)[ \\t]+)?(?:--[ \\t]+)?[\\\"\\x27]?(?:\\.|:/)[\\\"\\x27]?[ \\t]*(?:$|[;&|\\n#]|[0-9]*[<>]|&>)") ||- e.command.command.matches("(^|[;&|\\n])[ \\t]*(?:(?:then|do|else)[ \\t]+)?(?:sudo[ \\t]+)?(?:/[^\\s;&|]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+stash[ \\t]+clear(?:[ \\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\"`=]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+reset\\b[^;&|\\n#]*[ \\t]--hard(?:[ \\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\"`=]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+clean[ \\t]+(?:-[dfxXq]+[ \\t]+)*(?:-[dxXq]*f[dfxXq]*[dxX][dfxXq]*|-[dfxXq]*[dxX][dfxXq]*f[dfxXq]*|-[dfxXq]*f[dfxXq]*[ \\t]+(?:-[dfxXq]+[ \\t]+)*-[dfxXq]*[dxX][dfxXq]*|-[dfxXq]*[dxX][dfxXq]*[ \\t]+(?:-[dfxXq]+[ \\t]+)*-[dfxXq]*f[dfxXq]*)(?:[ \\t]+-[dfxXq]+)*(?:[ \\t]+--)?(?:[ \\t]+[^\\s;&|<>#-][^\\s;&|<>#]*)*[ \\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\"`=]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+checkout[ \\t]+(?:HEAD[ \\t]+)?(?:--[ \\t]+)?[\\\"\\x27]?(?:\\.|:/)[\\\"\\x27]?[ \\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\"`=]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+checkout[ \\t]+(?:-f|--force)(?:[ \\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\"`=]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+restore[ \\t]+(?:(?:(?:--source|-s)(?:=|[ \\t]+)[^\\s;&|]+|--worktree|-W)[ \\t]+)*(?:--[ \\t]+)?[\\\"\\x27]?(?:\\.|:/)[\\\"\\x27]?[ \\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\"`=]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+restore[ \\t]+(?:(?:--staged|-S)[ \\t]+)?(?:--worktree|-W|-SW|-WS)[ \\t]+(?:(?:--staged|-S)[ \\t]+)?(?:--[ \\t]+)?[\\\"\\x27]?(?:\\.|:/)[\\\"\\x27]?[ \\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\"`=]*/)?git(?:[ \\t]+-C[ \\t]+[^\\s;&|]+)*[ \\t]+stash[ \\t]+clear(?:[ \\t]|$|[;&|\\n<>#])"))emit:@@ -364,3 +367,39 @@ tests:- event: { action: tool.invoked }command: { command: "git reset --hard HEAD~1" }session: { id: s1 }+ - name: git_env+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "GIT_DIR=.git git reset --hard HEAD" }+ session: { id: s1 }+ - name: sudo_git+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u deploy git clean -fd" }+ session: { id: s1 }+ - name: relative_git+ verdict: match+ events:+ - event: { action: command.executed }+ command: { command: "GIT_DIR=.git ./bin/git stash clear" }+ session: { id: s1 }+ - name: git_env_read+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "GIT_DIR=.git git status" }+ session: { id: s1 }+ - name: sudo_git_dry_run+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u deploy git clean -nd" }+ session: { id: s1 }+ - name: sudo_git_echo+ verdict: no_match+ events:+ - event: { action: command.executed }+ command: { command: "sudo -u deploy echo \"git reset --hard\"" }+ session: { id: s1 }