Skip to content

Commit 71186c8

Browse files
authored
[Rule Tuning] Potential Persistence Through Run Control Detected (#2857)
* [Rule Tuning] changed rule type to new_terms * Updated min stack comment * Update persistence_rc_script_creation.toml * Changed description, removed file.path from new_terms field because it is not necessary * added host.id to new terms field and bumped up min stack
1 parent 7d64dc2 commit 71186c8

File tree

1 file changed

+26
-50
lines changed

1 file changed

+26
-50
lines changed

rules/linux/persistence_rc_script_creation.toml

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,25 @@
22
creation_date = "2023/02/28"
33
integration = ["endpoint"]
44
maturity = "production"
5-
min_stack_comments = "New fields added: required_fields, related_integrations, setup"
6-
min_stack_version = "8.3.0"
7-
updated_date = "2023/02/28"
5+
min_stack_comments = "Multiple field support in the New Terms rule type was added in Elastic 8.6"
6+
min_stack_version = "8.6.0"
7+
updated_date = "2023/06/22"
88

99
[rule]
1010
author = ["Elastic"]
1111
description = """
12-
The /etc/rc.local file is used to start custom applications, services, scripts or commands during start-up.
13-
The rc.local file has mostly been replaced by Systemd, however through the "systemd-rc-local-generator",
14-
rc.local files can be converted to services that run at boot. Adversaries may alter rc.local to execute
15-
malicious code at start-up, and gain persistence onto the system.
12+
This rule monitors the creation/alteration of the rc.local file by a previously unknown process executable
13+
through the use of the new terms rule type. The /etc/rc.local file is used to start custom applications,
14+
services, scripts or commands during start-up. The rc.local file has mostly been replaced by Systemd.
15+
However, through the "systemd-rc-local-generator", rc.local files can be converted to services that run at
16+
boot. Adversaries may alter rc.local to execute malicious code at start-up, and gain persistence onto the
17+
system.
1618
"""
1719
from = "now-9m"
18-
index = ["logs-endpoint.events.*", "auditbeat-*"]
19-
language = "eql"
20+
index = ["logs-endpoint.events.*", "auditbeat-*", "endgame-*"]
21+
language = "kuery"
2022
license = "Elastic License v2"
21-
name = "RC Script Creation"
22-
note = """## Triage and analysis
23-
### Investigating RC script creation
24-
Detection alerts from this rule indicate the creation of a new `/etc/rc.local` file. The rc.local file has been deprecated in favor of the use of `systemd services`, and more recent Unix distributions no longer leverage this method of on-boot script execution. There might still be users that use rc.local in a benign matter, so investigation to see whether the file is malicious is vital. The first file to check can be found here:
25-
- /etc/rc.local
26-
27-
This file may contain a path to an executable, script or a command. Additionally, the `systemd-rc-local-generator` located at `/usr/lib/systemd/system-generators/systemd-rc-local-generator` is used to convert rc.local into rc-local.service. The service and wants files can be found in the following directories:
28-
- /lib/systemd/system/rc-local.service
29-
- /run/systemd/generator/multi-user.target.wants/rc-local.service
30-
31-
In case the file is not present here, the `sudo systemctl status rc-local` can be executed to find the location of the rc-local unit file. Make sure to investigate all files mentioned above, and files that these scripts may link to establish whether the alert is malicious or benign behavior.
32-
33-
### Investigating RC script execution
34-
The detection rule queries for the creation of these files, but manual analysis is required to check for rc script execution. Systemd will generate syslogs in case of the execution of the rc-local service. The following command can be used to check for the execution of this service:
35-
36-
`sudo cat /var/log/syslog | grep "rc-local.service|/etc/rc.local Compatibility"`
37-
38-
If logging is found, analyze it, and chances are that the contents of the rc.local file have been executed. In case several syslog log files are available, use a wildcard to search through all of the available logs.
39-
40-
### Response and remediation
41-
- Initiate the incident response process based on the outcome of the triage.
42-
- Isolate the involved host to prevent further post-compromise behavior.
43-
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
44-
- Delete the service/rc.local files or restore it to the original configuration.
45-
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
46-
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
47-
- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
48-
"""
23+
name = "Potential Persistence Through Run Control Detected"
4924
references = [
5025
"https://www.intezer.com/blog/malware-analysis/hiddenwasp-malware-targeting-linux-systems/",
5126
"https://pberba.github.io/security/2022/02/06/linux-threat-hunting-for-persistence-initialization-scripts-and-shell-configuration/#8-boot-or-logon-initialization-scripts-rc-scripts",
@@ -55,36 +30,37 @@ references = [
5530
risk_score = 47
5631
rule_id = "0f4d35e4-925e-4959-ab24-911be207ee6f"
5732
severity = "medium"
58-
tags = ["Elastic", "Host", "Linux", "Threat Detection", "Persistence", "Investigation Guide"]
59-
type = "eql"
33+
tags = ["Elastic", "Host", "Linux", "Threat Detection", "Persistence", "Elastic Endgame"]
34+
type = "new_terms"
6035

6136
query = '''
62-
sequence by user.id, host.id with maxspan=15s
63-
[file where host.os.type == "linux" and
64-
event.type == "creation" and
65-
file.path == "/etc/rc.local"]
66-
[process where host.os.type == "linux" and
67-
event.type == "start" and
68-
process.name == "chmod" and
69-
process.args == "+x" and process.args == "/etc/rc.local"]
37+
host.os.type : "linux" and event.category : "file" and
38+
event.type : ("change" or "file_modify_event" or "creation" or "file_create_event") and
39+
file.path : "/etc/rc.local" and not file.extension : "swp"
7040
'''
7141

72-
7342
[[rule.threat]]
7443
framework = "MITRE ATT&CK"
44+
7545
[[rule.threat.technique]]
7646
id = "T1037"
7747
name = "Boot or Logon Initialization Scripts"
7848
reference = "https://attack.mitre.org/techniques/T1037/"
49+
7950
[[rule.threat.technique.subtechnique]]
8051
id = "T1037.004"
8152
name = "RC Scripts"
8253
reference = "https://attack.mitre.org/techniques/T1037/004/"
8354

84-
85-
8655
[rule.threat.tactic]
8756
id = "TA0003"
8857
name = "Persistence"
8958
reference = "https://attack.mitre.org/tactics/TA0003/"
9059

60+
[rule.new_terms]
61+
field = "new_terms_fields"
62+
value = ["host.id", "process.executable"]
63+
64+
[[rule.new_terms.history_window_start]]
65+
field = "history_window_start"
66+
value = "now-7d"

0 commit comments

Comments
 (0)