豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
[metadata]
creation_date = "2026/04/09"
integration = ["endpoint", "sentinel_one_cloud_funnel"]
maturity = "production"
updated_date = "2026/04/09"

[rule]
author = ["Elastic"]
description = """
This rule detects the creation of files in world-writable directories by an unusual process. Attackers may
attempt to hide their activities by creating files in world-writable directories, which are commonly used
for temporary file storage. This behavior is often associated with lateral movement and can be an indicator
of an attacker attempting to move laterally within a network.
"""
from = "now-9m"
index = [
"endgame-*",
"logs-endpoint.events.file*",
"logs-sentinel_one_cloud_funnel.*",
]
language = "kuery"
license = "Elastic License v2"
name = "File Creation in World-Writable Directory by Unusual Process"
note = """
## Triage and analysis

> **Disclaimer**:
> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

### Investigating File Creation in World-Writable Directory by Unusual Process

This alert flags a Linux process that normally should not stage content in shared writable locations such as /tmp, /var/tmp, /run, or /dev/shm. Attackers abuse these directories because many users and services can write there, which makes payloads and helper scripts easier to hide; for example, a compromised shell may use curl or python to drop an ELF backdoor into /dev/shm and execute it from that transient path.

### Possible investigation steps

- Reconstruct the full process lineage and execution context around the file creation to determine whether it originated from an interactive session, scheduled task, container, service account, or a parent process already running from an unusual location.
- Inspect the dropped file’s type, permissions, ownership, hash, and contents to assess whether it is a script, ELF, archive, or disguised payload, and determine if it was later executed, renamed, or moved to a more persistent path.
- Correlate the alert with nearby authentication, privilege escalation, and network activity on the same host to identify signs of compromise such as recent SSH access, sudo use, remote command execution, or outbound connections to untrusted infrastructure.
- Validate whether the activity aligns with known administrative or software deployment behavior by checking package ownership, change records, automation tooling, and host or user prevalence, since one-off staging in shared writable paths is more suspicious than common fleetwide behavior.

### False positive analysis

- Legitimate package installation, OS update, or local maintenance script activity can use interpreters or utilities such as cp, mv, chmod, curl, or python to stage temporary files in /tmp or /var/tmp before moving them into place, so verify whether the process tree, user, and event time align with expected system change or package management activity on the host.
- Normal service startup or deployment automation may create transient files in /run or /dev/shm for configuration generation, caching, or runtime state, so confirm the file owner, contents, and parent process match a known application or boot-time workflow and that the same behavior is regularly seen on comparable systems.

### Response and remediation
- Isolate the affected Linux host from the network while preserving forensic access, stop the malicious process and any spawned tools, and collect copies of the dropped file before cleanup.
- Remove attacker footholds by deleting the dropped file.
- Restore the system to a known-good state by rebuilding from a trusted image or validated backup and verifying core packages, shell configuration files, scheduled tasks, and remote access settings match the approved baseline before reconnecting it.
- Escalate to incident response immediately if the file creation was followed by privilege escalation, credential access, outbound tool downloads, lateral movement over SSH, or the same behavior is identified on multiple hosts, and expand scoping to related accounts and systems.
"""
references = ["https://www.rapid7.com/blog/post/tr-new-whitepaper-stealthy-bpfdoor-variants/"]
risk_score = 47
rule_id = "1f56f548-94ec-4678-b1ed-b1a14cca4e3a"
setup = """## Setup

This rule requires data coming in from Elastic Defend.

### Elastic Defend Integration Setup
Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.

#### Prerequisite Requirements:
- Fleet is required for Elastic Defend.
- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).

#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
- Go to the Kibana home page and click "Add integrations".
- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
- Click "Add Elastic Defend".
- Configure the integration name and optionally add a description.
- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
- Click "Save and Continue".
- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
"""
severity = "medium"
tags = [
"Domain: Endpoint",
"OS: Linux",
"Use Case: Threat Detection",
"Tactic: Defense Evasion",
"Data Source: Elastic Defend",
"Data Source: Elastic Endgame",
"Data Source: SentinelOne",
"Resources: Investigation Guide",
]
timestamp_override = "event.ingested"
type = "new_terms"
query = '''
host.os.type:linux and event.category:file and event.type:creation and (
process.name:(
"cp" or "mv" or "chmod" or "chown" or "chattr" or "chgrp" or "curl" or "wget" or "timeout" or
"env" or "node" or "deno" or "nodejs" or .* or python* or perl* or ruby* or php* or lua*
) or
process.executable:(
./* or /tmp/* or /var/tmp/* or /dev/shm/* or /run/* or /var/run/* or /boot/* or /sys/* or
/lost+found/* or /proc/* or /var/mail/* or /var/www/*
)
) and
file.path:(/run/* or /var/run/* or /dev/shm/* or /tmp/* or /var/tmp/*) and
Comment thread
Aegrah marked this conversation as resolved.
not (
file.path:(
/var/tmp/dracut.* or /var/tmp/mkinitramfs_* or /tmp/.*-00000000.so or /run/udev/rules.d/* or
/tmp/new_root/* or /tmp/newroot/* or /run/user/*/.bubblewrap/newroot/* or /tmp/tmp.*/docker-scout_* or
/var/tmp/portage/* or /tmp/yarn--* or /run/k3s/containerd/* or /var/tmp/pamac-build-* or
/tmp/mkinitcpio* or /run/user/*/netns/netns-*
) or
file.extension:("json" or "txt")
Comment thread
Aegrah marked this conversation as resolved.
)
'''

[[rule.threat]]
framework = "MITRE ATT&CK"

[[rule.threat.technique]]
id = "T1222"
name = "File and Directory Permissions Modification"
reference = "https://attack.mitre.org/techniques/T1222/"

[[rule.threat.technique.subtechnique]]
id = "T1222.002"
name = "Linux and Mac File and Directory Permissions Modification"
reference = "https://attack.mitre.org/techniques/T1222/002/"

[rule.threat.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"
Comment thread
Aegrah marked this conversation as resolved.

[rule.new_terms]
field = "new_terms_fields"
value = ["host.id", "process.executable", "file.path"]

[[rule.new_terms.history_window_start]]
field = "history_window_start"
value = "now-5d"
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
[metadata]
creation_date = "2026/04/09"
integration = ["endpoint"]
maturity = "production"
updated_date = "2026/04/09"

[rule]
author = ["Elastic"]
description = """
This rule detects the clearing of the shell history via environment variables. Attackers may clear the shell history
to hide their activities from being tracked. By leveraging environment variables such as HISTSIZE, HISTFILESIZE,
HISTCONTROL, and HISTFILE, attackers can clear the shell history by setting them to 0, ignoring spaces, or redirecting
the history to /dev/null, effectively erasing the command history.
"""
from = "now-9m"
index = ["logs-endpoint.events.process*"]
language = "eql"
license = "Elastic License v2"
name = "Shell History Clearing via Environment Variables"
note = """
## Triage and analysis

> **Disclaimer**:
> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

### Investigating Shell History Clearing via Environment Variables

This rule detects Linux processes that start with shell history controls set to disable or discard command logging, a common defense-evasion tactic that removes evidence of hands-on-keyboard activity. An attacker who gains a shell may launch bash with HISTFILE=/dev/null and HISTSIZE=0, then run discovery, credential access, or privilege-escalation commands knowing their interactive history will not be written to disk.

### Possible investigation steps

- Reconstruct the full process ancestry and login context to determine whether the shell was launched from a legitimate admin session, a remote access channel such as SSH or a web shell, or an unexpected parent process.
- Review all commands and child processes executed by the same user and terminal session immediately before and after the history suppression event for signs of discovery, credential access, lateral movement, privilege escalation, or log tampering.
- Correlate with authentication, sudo, PAM, and SSH logs on the host to verify who initiated the session, from where, and whether the activity aligns with approved maintenance or change windows.
- Examine concurrent file, network, and process telemetry for follow-on actions such as downloading tools, touching sensitive files, modifying startup scripts, or making outbound connections that would indicate the shell was used for malicious objectives.
- If the activity is not clearly benign, capture volatile evidence and inspect shell startup files and account profiles for persistent history-disabling settings or aliases that could mask repeated interactive activity.

### False positive analysis

- Administrators may intentionally launch a temporary shell with HISTFILE=/dev/null or HISTSIZE=0 during sensitive maintenance to avoid saving secrets entered at the prompt; verify the user, change timing, parent process, and nearby commands align with approved administrative work on the host.
- A user's shell startup files may legitimately set HISTCONTROL=ignorespace or redirect HISTFILE for noninteractive, ephemeral, or test sessions as part of local shell customization; confirm the same settings exist in the account or system shell profiles and appear consistently across the user's normal sessions without other suspicious behavior.

### Response and remediation

- Isolate the affected Linux host from the network while preserving forensic access, stop the malicious shell and any spawned tools, and collect copies of the user’s shell startup files, current crontabs, and recently modified scripts before cleanup.
- Remove attacker footholds by deleting unauthorized changes in ~/.bashrc, ~/.profile, /etc/profile, /etc/bash.bashrc, ~/.ssh/authorized_keys, systemd service or timer units, cron jobs, and any backdoor binaries or web shells dropped during the session.
- Reset credentials and secrets exposed on or from the host, including the compromised local account, any sudo-capable accounts, SSH keys, and application tokens, and review sudoers files and group membership for malicious privilege changes.
- Restore the system to a known-good state by rebuilding from a trusted image or validated backup and verifying core packages, shell configuration files, scheduled tasks, and remote access settings match the approved baseline before reconnecting it.
- Escalate to incident response immediately if the history-suppression shell was followed by privilege escalation, credential access, outbound tool downloads, lateral movement over SSH, or the same behavior is identified on multiple hosts, and expand scoping to related accounts and systems.
- Harden against recurrence by enforcing centralized command and session logging, restricting interactive shell access to managed administration paths, monitoring for shell profiles that set HISTFILE=/dev/null or HISTSIZE=0, and tightening change control for user and system startup files.
"""
references = ["https://www.rapid7.com/blog/post/tr-new-whitepaper-stealthy-bpfdoor-variants/"]
risk_score = 73
rule_id = "a68da7d6-7eab-45bd-97c5-93b469c0706e"
setup = """## Setup

This rule requires data coming in from Elastic Defend.

### Elastic Defend Integration Setup
Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.

#### Prerequisite Requirements:
- Fleet is required for Elastic Defend.
- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).

#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
- Go to the Kibana home page and click "Add integrations".
- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
- Click "Add Elastic Defend".
- Configure the integration name and optionally add a description.
- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
- Click "Save and Continue".
- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).

Elastic Defend integration does not collect environment variable logging by default.
In order to capture this behavior, this rule requires a specific configuration option set within the advanced settings of the Elastic Defend integration.
#### To set up environment variable capture for an Elastic Agent policy:
- Go to “Security → Manage → Policies”.
- Select an “Elastic Agent policy”.
- Click “Show advanced settings”.
- Scroll down or search for “linux.advanced.capture_env_vars”.
- Enter the names of environment variables you want to capture, separated by commas.
- For this rule the linux.advanced.capture_env_vars variable should be set to "HISTSIZE, HISTFILESIZE, HISTCONTROL, HISTFILE".
- Click “Save”.
After saving the integration change, the Elastic Agents running this policy will be updated and the rule will function properly.
For more information on capturing environment variables refer to the [helper guide](https://www.elastic.co/guide/en/security/current/environment-variable-capture.html).
"""
severity = "high"
tags = [
"Domain: Endpoint",
"OS: Linux",
"Use Case: Threat Detection",
"Tactic: Defense Evasion",
"Data Source: Elastic Defend",
"Resources: Investigation Guide",
]
timestamp_override = "event.ingested"
type = "eql"
query = '''
process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
process.env_vars like~ (
"HISTSIZE=0", "HISTFILESIZE=0", "HISTCONTROL=ignorespace", "HISTFILE=/dev/null"
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.

Suggested change
"HISTSIZE=0", "HISTFILESIZE=0", "HISTCONTROL=ignorespace", "HISTFILE=/dev/null"
"HISTSIZE=0", "HISTFILESIZE=0", "HISTCONTROL=ignorespace", "HISTCONTROL=ignoreboth", "HISTFILE=/dev/null"

I think we should add ignoreboth as well.

Ref: https://www.geeksforgeeks.org/linux-unix/histcontrol-command-in-linux-with-examples/

Copy link
Copy Markdown
Contributor Author

@Aegrah Aegrah Apr 20, 2026

Choose a reason for hiding this comment

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

ignoreboth is commonly used, so it might be okay for DR, but for ER its too restrictive (based on telemetry)

)
'''

[[rule.threat]]
framework = "MITRE ATT&CK"

[rule.threat.tactic]
name = "Defense Evasion"
id = "TA0005"
reference = "https://attack.mitre.org/tactics/TA0005/"

[[rule.threat.technique]]
name = "Indicator Removal"
id = "T1070"
reference = "https://attack.mitre.org/techniques/T1070/"

[[rule.threat.technique.subtechnique]]
name = "Clear Command History"
id = "T1070.003"
reference = "https://attack.mitre.org/techniques/T1070/003/"
Loading