Skip to content

[New Rule] Newly Observed Systemd or Cron Child Command Line - #7248

Open
Aegrah wants to merge 6 commits into
mainfrom
esql-new-terms-systemd-cron
Open

Aegrah wants to merge 6 commits into
mainfrom
esql-new-terms-systemd-cron

Conversation

@Aegrah

@Aegrah Aegrah commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Issue link(s): N/A

Summary - What I changed

  • Adds an ES|QL rule that detects an exact command line executed as a direct child of systemd, cron, or crond when it has not been observed on the same agent.id during the previous seven days.
  • Uses a seven-day history with a ten-minute scheduling guard and alerts only when the earliest observation is recent, preventing normally recurring weekly jobs from alerting.
  • Preserves host, user, process, parent, working-directory, and first/last-seen context for investigation.
  • Documents that a systemd parent can represent an ordinary service or transient unit and does not necessarily prove timer execution.

How To Test

  • python -m detection_rules toml-lint -f rules/linux/persistence_newly_observed_systemd_cron_command_line.toml
  • python -m detection_rules validate-rule rules/linux/persistence_newly_observed_systemd_cron_command_line.toml
  • Import the rule into a stack with at least seven days of Elastic Defend process telemetry.
  • Confirm an established daily or weekly scheduled command does not alert, while a new direct-child command line for the same agent does.

Checklist

  • Added applicable PR labels.
  • Secret and sensitive material has been managed correctly.
  • Automated testing was updated or added to match the most common scenarios.
  • Documentation and comments were added where required.

Contributor checklist

  • Signed the contributor license agreement.
  • Followed the contributor guidelines.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Aegrah Aegrah added OS: Linux Rule: New Proposal for new rule labels Nov 26, 2026
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown

Starting the rule tests ...

@Aegrah Aegrah self-assigned this Nov 26, 2026
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown

Starting the rule tests ...

Co-authored-by: Cursor <cursoragent@cursor.com>
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown

Starting the rule tests ...

Removed references to outdated URLs for unusual execution rules.
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown

Starting the rule tests ...

@Aegrah
Aegrah marked this pull request as ready for review November 26, 2026 14:26
Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:26
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown

Starting the rule tests ...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active findings identify a recency-window boundary that can cause false alerts, rejection of delayed-ingestion events, and aggregation that can combine fields from different executions into a misleading process context.

3 open issues
What changed in this PR

Adds a Linux ES|QL detection rule for newly observed command lines launched directly by systemd, cron, or crond, complementing existing signature-based persistence detections.

Changes:

  • Groups activity by agent and exact command line using seven days of history plus a ten-minute scheduling guard.
  • Preserves investigation context and suppresses repeated alerts for one hour.
  • Documents telemetry requirements, triage steps, and the distinction between systemd service and timer execution.
File Description
rules/​linux/​persistence_newly_observed_systemd_cron_command_line.toml Adds the detection query, scheduling, suppression, threat mappings, and investigation guide.

Review effort: Balanced

Comment on lines +115 to +127
Esql.first_time_seen = MIN(@timestamp),
Esql.last_time_seen = MAX(@timestamp),
Esql.host_id_values = VALUES(host.id),
Esql.host_name_values = VALUES(host.name),
Esql.user_name_values = VALUES(user.name),
Esql.process_entity_id_values = VALUES(process.entity_id),
Esql.process_executable_values = VALUES(process.executable),
Esql.process_working_directory_values = VALUES(process.working_directory),
Esql.process_parent_name_values = VALUES(process.parent.name),
Esql.process_parent_executable_values = VALUES(process.parent.executable),
Esql.process_parent_command_line_values = VALUES(process.parent.command_line)
BY agent.id, process.command_line
| EVAL Esql.first_seen_minutes_ago = DATE_DIFF("minute", Esql.first_time_seen, NOW())
Esql.process_parent_command_line_values = VALUES(process.parent.command_line)
BY agent.id, process.command_line
| EVAL Esql.first_seen_minutes_ago = DATE_DIFF("minute", Esql.first_time_seen, NOW())
| WHERE Esql.first_seen_minutes_ago >= 0 AND Esql.first_seen_minutes_ago <= 10
Comment on lines +132 to +136
user.name = MV_FIRST(Esql.user_name_values),
process.entity_id = MV_FIRST(Esql.process_entity_id_values),
process.executable = MV_FIRST(Esql.process_executable_values),
process.parent.name = MV_FIRST(Esql.process_parent_name_values),
process.parent.executable = MV_FIRST(Esql.process_parent_executable_values)
Co-authored-by: Cursor <cursoragent@cursor.com>
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown

Starting the rule tests ...

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants