Suspicious System Commands Executed by Previously Unknown Executable
This rule monitors for the execution of several commonly used system commands executed by a previously unknown executable located in commonly abused directories. An alert from this rule can indicate the presence of potentially malicious activity, such as the execution of unauthorized or suspicious processes attempting to run malicious code. Detecting and investigating such behavior can help identify and mitigate potential security threats, protecting the system and its data from potential compromise.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/06/14"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2025/12/19"
6
7[rule]
8author = ["Elastic"]
9description = """
10This rule monitors for the execution of several commonly used system commands executed by a previously unknown
11executable located in commonly abused directories. An alert from this rule can indicate the presence of potentially
12malicious activity, such as the execution of unauthorized or suspicious processes attempting to run malicious code.
13Detecting and investigating such behavior can help identify and mitigate potential security threats, protecting the
14system and its data from potential compromise.
15"""
16from = "now-9m"
17index = ["logs-endpoint.events.*", "endgame-*"]
18language = "kuery"
19license = "Elastic License v2"
20name = "Suspicious System Commands Executed by Previously Unknown Executable"
21note = """## Triage and analysis
22
23> **Disclaimer**:
24> 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.
25
26### Investigating Suspicious System Commands Executed by Previously Unknown Executable
27
28In Linux environments, system commands are essential for managing processes and configurations. Adversaries exploit this by executing commands via unknown executables in vulnerable directories, aiming to run unauthorized code. The detection rule identifies such anomalies by monitoring command executions from unfamiliar sources, excluding known safe processes, thus highlighting potential threats for further investigation.
29
30### Possible investigation steps
31
32- Review the process.executable path to determine if it is located in a commonly abused directory such as /tmp, /dev/shm, or /var/tmp, which may indicate malicious intent.
33- Examine the process.args to identify which specific system command was executed (e.g., hostname, id, ifconfig) and assess whether its execution is typical for the system's normal operations.
34- Check the process.parent.executable to understand the parent process that initiated the suspicious command execution, ensuring it is not a known safe process or a legitimate system service.
35- Investigate the user account associated with the process to determine if it has the necessary permissions and if the activity aligns with the user's typical behavior.
36- Correlate the event with other logs or alerts from the same host to identify any patterns or additional suspicious activities that may indicate a broader compromise.
37- Assess the risk score and severity in the context of the environment to prioritize the investigation and response efforts accordingly.
38
39### False positive analysis
40
41- System maintenance scripts or automated tasks may trigger alerts if they execute common system commands from directories like /tmp or /var/tmp. To handle this, identify these scripts and add their executables to the exclusion list.
42- Custom user scripts that perform routine checks using commands like ls or ps might be flagged. Review these scripts and consider adding their paths to the known safe processes to prevent unnecessary alerts.
43- Development or testing environments often use temporary executables in directories such as /dev/shm. If these are known and non-threatening, include their paths in the exception list to reduce false positives.
44- Some monitoring tools or agents might execute commands like uptime or whoami from non-standard locations. Verify these tools and update the exclusion criteria to include their executables or parent processes.
45- In environments with containerized applications, processes running from /run/containerd or similar paths might be incorrectly flagged. Ensure these paths are accounted for in the exclusion settings if they are part of legitimate operations.
46
47### Response and remediation
48
49- Isolate the affected system from the network to prevent further unauthorized access or lateral movement by the adversary.
50- Terminate any suspicious processes identified by the alert, especially those originating from unknown executables in commonly abused directories.
51- Conduct a thorough review of the affected directories (e.g., /tmp, /var/tmp, /dev/shm) to identify and remove any unauthorized or malicious files or executables.
52- Restore any altered system configurations or files from a known good backup to ensure system integrity.
53- Implement stricter access controls and permissions on the directories identified in the alert to prevent unauthorized executable placement.
54- Monitor the system for any signs of persistence mechanisms, such as cron jobs or startup scripts, and remove any that are unauthorized.
55- Escalate the incident to the security operations team for further analysis and to determine if additional systems may be compromised."""
56risk_score = 21
57rule_id = "e9001ee6-2d00-4d2f-849e-b8b1fb05234c"
58setup = """## Setup
59
60This rule requires data coming in from Elastic Defend.
61
62### Elastic Defend Integration Setup
63Elastic 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.
64
65#### Prerequisite Requirements:
66- Fleet is required for Elastic Defend.
67- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
68
69#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
70- Go to the Kibana home page and click "Add integrations".
71- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
72- Click "Add Elastic Defend".
73- Configure the integration name and optionally add a description.
74- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
75- 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).
76- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
77- 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.
78For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
79- Click "Save and Continue".
80- 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.
81For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
82"""
83severity = "low"
84tags = [
85 "Domain: Endpoint",
86 "OS: Linux",
87 "Use Case: Threat Detection",
88 "Tactic: Execution",
89 "Data Source: Elastic Endgame",
90 "Data Source: Elastic Defend",
91 "Resources: Investigation Guide",
92]
93timestamp_override = "event.ingested"
94type = "new_terms"
95query = '''
96host.os.type:linux and event.category:process and event.action:(exec or exec_event or fork or fork_event) and
97process.executable:(* and (
98 /etc/crontab or /bin/* or /boot/* or /dev/shm/* or /etc/cron.*/* or /etc/init.d/* or /etc/rc*.d/* or /etc/update-motd.d/* or
99 /home/*/.* or /tmp/* or /usr/bin/* or /usr/lib/update-notifier/* or /usr/share/* or /var/tmp/* or /sbin/* or /usr/sbin/* or
100 /usr/local/sbin/* or /usr/local/bin/* or /var/lib/* or /var/run/* or /var/cache/* or /var/log/* or /dev/shm/* or /var/tmp/*
101) and not /tmp/go-build*) and
102process.args:(hostname or id or ifconfig or ls or netstat or ps or pwd or route or top or uptime or whoami) and
103not (process.name:
104 (apt or dnf or docker or dockerd or dpkg or hostname or id or ls or netstat or ps or pwd or rpm or snap or
105 snapd or sudo or top or uptime or which or whoami or yum or sh or bash or ip or dash or find or podman or env or
106 busybox or aws or timeout or nmcli or dpkg-query or nsenter or pw-cli or node or npm or gnome-calculator or pidof or
107 steamerrorreporter or ssh or grep or xargs or apt-get or numactl or entrypoint or flatpak-spawn or logger or command or
108 login or sshpass or docker-compose or whereis or rbd or basename or ifconfig or tar or crictl or su) or
109process.parent.executable:(
110 /opt/cassandra/bin/cassandra or /opt/nessus/sbin/nessusd or /opt/nessus_agent/sbin/nessus-agent-module or /opt/puppetlabs/puppet/bin/puppet or
111 /opt/puppetlabs/puppet/bin/ruby or /usr/libexec/platform-python or /usr/local/cloudamize/bin/CCAgent or /usr/sbin/sshd or /bin/* or
112 /etc/network/* or /opt/Elastic/* or /opt/TrendMicro* or /opt/aws/* or /opt/eset/* or /opt/rapid7/* or /run/containerd/* or /run/k3s/* or
113 /snap/* or /tmp/dpkg-licenses* or /tmp/newroot/* or /usr/bin/* or /var/lib/amagent/* or /var/lib/docker/* or /vz/* or
114 "/usr/sbin/sshd" or "./runc" or "/opt/gitlab/embedded/bin/ruby" or /opt/saltstack/salt/bin/python* or "/usr/lib/rabbitmq/bin/rabbitmqctl"
115 ) or
116 process.executable:(/run/containerd/* or /srv/snp/docker/* or /tmp/.criu*)
117)
118'''
119
120[[rule.threat]]
121framework = "MITRE ATT&CK"
122
123[[rule.threat.technique]]
124id = "T1059"
125name = "Command and Scripting Interpreter"
126reference = "https://attack.mitre.org/techniques/T1059/"
127
128[[rule.threat.technique.subtechnique]]
129id = "T1059.004"
130name = "Unix Shell"
131reference = "https://attack.mitre.org/techniques/T1059/004/"
132
133[rule.threat.tactic]
134id = "TA0002"
135name = "Execution"
136reference = "https://attack.mitre.org/tactics/TA0002/"
137
138[rule.new_terms]
139field = "new_terms_fields"
140value = ["process.parent.name"]
141
142[[rule.new_terms.history_window_start]]
143field = "history_window_start"
144value = "now-5d"
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 Suspicious System Commands Executed by Previously Unknown Executable
In Linux environments, system commands are essential for managing processes and configurations. Adversaries exploit this by executing commands via unknown executables in vulnerable directories, aiming to run unauthorized code. The detection rule identifies such anomalies by monitoring command executions from unfamiliar sources, excluding known safe processes, thus highlighting potential threats for further investigation.
Possible investigation steps
- Review the process.executable path to determine if it is located in a commonly abused directory such as /tmp, /dev/shm, or /var/tmp, which may indicate malicious intent.
- Examine the process.args to identify which specific system command was executed (e.g., hostname, id, ifconfig) and assess whether its execution is typical for the system's normal operations.
- Check the process.parent.executable to understand the parent process that initiated the suspicious command execution, ensuring it is not a known safe process or a legitimate system service.
- Investigate the user account associated with the process to determine if it has the necessary permissions and if the activity aligns with the user's typical behavior.
- Correlate the event with other logs or alerts from the same host to identify any patterns or additional suspicious activities that may indicate a broader compromise.
- Assess the risk score and severity in the context of the environment to prioritize the investigation and response efforts accordingly.
False positive analysis
- System maintenance scripts or automated tasks may trigger alerts if they execute common system commands from directories like /tmp or /var/tmp. To handle this, identify these scripts and add their executables to the exclusion list.
- Custom user scripts that perform routine checks using commands like ls or ps might be flagged. Review these scripts and consider adding their paths to the known safe processes to prevent unnecessary alerts.
- Development or testing environments often use temporary executables in directories such as /dev/shm. If these are known and non-threatening, include their paths in the exception list to reduce false positives.
- Some monitoring tools or agents might execute commands like uptime or whoami from non-standard locations. Verify these tools and update the exclusion criteria to include their executables or parent processes.
- In environments with containerized applications, processes running from /run/containerd or similar paths might be incorrectly flagged. Ensure these paths are accounted for in the exclusion settings if they are part of legitimate operations.
Response and remediation
- Isolate the affected system from the network to prevent further unauthorized access or lateral movement by the adversary.
- Terminate any suspicious processes identified by the alert, especially those originating from unknown executables in commonly abused directories.
- Conduct a thorough review of the affected directories (e.g., /tmp, /var/tmp, /dev/shm) to identify and remove any unauthorized or malicious files or executables.
- Restore any altered system configurations or files from a known good backup to ensure system integrity.
- Implement stricter access controls and permissions on the directories identified in the alert to prevent unauthorized executable placement.
- Monitor the system for any signs of persistence mechanisms, such as cron jobs or startup scripts, and remove any that are unauthorized.
- Escalate the incident to the security operations team for further analysis and to determine if additional systems may be compromised.
Related rules
- Abnormal Process ID or Lock File Created
- BPF filter applied using TC
- Binary Executed from Shared Memory Directory
- Interactive Terminal Spawned via Perl
- Interactive Terminal Spawned via Python