Skip to content

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

fix(rules): match tee --append and clustered tee flags into /etc/sudoers (#1043)

Rudy Mizrahi Celekli2812a5dfd1d8
diff --git a/rules/risky-command/sudoers-nopasswd-tampering.rule.yaml b/rules/risky-command/sudoers-nopasswd-tampering.rule.yaml
index 30e337f5..d677c609 100644
--- a/rules/risky-command/sudoers-nopasswd-tampering.rule.yaml
+++ b/rules/risky-command/sudoers-nopasswd-tampering.rule.yaml
@@ -1,5 +1,5 @@
id: sudoers-nopasswd-tampering
-version: 1
+version: 2
title: Sudoers / NOPASSWD privilege rule tampered or probed
description: >
A command writes to the sudoers configuration (/etc/sudoers or /etc/sudoers.d/),
@@ -18,7 +18,7 @@ taxonomy:
match: >
e.event.action == "command.executed" && (
- e.command.command.matches("(?i)(>>?\\s*|tee\\s+(-a\\s+)?)/etc/sudoers(\\.d)?\\b") ||
+ e.command.command.matches("(?i)(>>?\\s*|\\btee\\b[^;&|<]*\\s)/etc/sudoers(\\.d)?\\b") ||
e.command.command.matches("(?i)/etc/sudoers\\.d/[^\\s]+") ||
e.command.command.matches("(?i)\\bvisudo\\b") ||
e.command.command.matches("(?i)\\bNOPASSWD\\s*:") ||
@@ -41,6 +41,36 @@ tests:
- event: { action: command.executed }
command: { command: "echo 'user ALL=(ALL) NOPASSWD:ALL' | tee -a /etc/sudoers" }
session: { id: s1 }
+ - name: tee_long_append_into_sudoers
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "echo 'agent ALL=(ALL) ALL' | sudo tee --append /etc/sudoers" }
+ session: { id: s1 }
+ - name: tee_clustered_flags_into_sudoers
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "echo 'agent ALL=(ALL) ALL' | sudo tee -ai /etc/sudoers" }
+ session: { id: s1 }
+ - name: tee_sudoers_as_second_target
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "echo 'agent ALL=(ALL) ALL' | sudo tee -a /etc/hosts /etc/sudoers" }
+ session: { id: s1 }
+ - name: tee_reading_sudoers_from_stdin
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "tee copy.txt < /etc/sudoers" }
+ session: { id: s1 }
+ - name: tee_into_other_etc_file
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "echo 'nameserver 1.1.1.1' | sudo tee --append /etc/resolv.conf" }
+ session: { id: s1 }
- name: visudo_edit
verdict: match
events: