Setcap setuid/setgid Capability Set
This rule monitors for the addition of the cap_setuid+ep or cap_setgid+ep capabilities via setcap. Setuid (Set User ID) and setgid (Set Group ID) are Unix-like OS features that enable processes to run with elevated privileges, based on the file owner or group. Threat actors can exploit these attributes to achieve persistence by creating malicious binaries, allowing them to maintain control over a compromised system with elevated permissions.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/09/05"
3integration = ["endpoint", "crowdstrike", "sentinel_one_cloud_funnel"]
4maturity = "production"
5updated_date = "2025/03/20"
6
7[transform]
8[[transform.osquery]]
9label = "Osquery - Retrieve Running Processes by User"
10query = "SELECT pid, username, name FROM processes p JOIN users u ON u.uid = p.uid ORDER BY username"
11
12[[transform.osquery]]
13label = "Osquery - Retrieve Crontab Information"
14query = "SELECT * FROM crontab"
15
16[[transform.osquery]]
17label = "Osquery - Retrieve Listening Ports"
18query = "SELECT pid, address, port, socket, protocol, path FROM listening_ports"
19
20[[transform.osquery]]
21label = "Osquery - Retrieve Open Sockets"
22query = "SELECT pid, family, remote_address, remote_port, socket, state FROM process_open_sockets"
23
24[[transform.osquery]]
25label = "Osquery - Retrieve Information for a Specific User"
26query = "SELECT * FROM users WHERE username = {{user.name}}"
27
28[[transform.osquery]]
29label = "Osquery - Investigate the Account Authentication Status"
30query = "SELECT * FROM logged_in_users WHERE user = {{user.name}}"
31
32
33[rule]
34author = ["Elastic"]
35description = """
36This rule monitors for the addition of the cap_setuid+ep or cap_setgid+ep capabilities via setcap. Setuid (Set User ID)
37and setgid (Set Group ID) are Unix-like OS features that enable processes to run with elevated privileges, based on the
38file owner or group. Threat actors can exploit these attributes to achieve persistence by creating malicious binaries,
39allowing them to maintain control over a compromised system with elevated permissions.
40"""
41from = "now-9m"
42index = [
43 "endgame-*",
44 "logs-crowdstrike.fdr*",
45 "logs-endpoint.events.process*",
46 "logs-sentinel_one_cloud_funnel.*",
47]
48language = "eql"
49license = "Elastic License v2"
50name = "Setcap setuid/setgid Capability Set"
51note = """## Triage and analysis
52
53### Investigating Setcap setuid/setgid Capability Set
54
55Setuid (Set User ID) and setgid (Set Group ID) are Unix-like OS features that enable processes to run with elevated privileges, based on the file owner or group.
56
57Threat actors can exploit these attributes to achieve persistence by creating malicious binaries, allowing them to maintain control over a compromised system with elevated permissions.
58
59This rule monitors for the addition of the cap_setuid+ep or cap_setgid+ep capabilities via setcap.
60
61> **Note**:
62> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/current/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
63> This investigation guide uses [placeholder fields](https://www.elastic.co/guide/en/security/current/osquery-placeholder-fields.html) to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
64
65#### Possible Investigation Steps
66
67- Investigate the file that was targeted by the addition of the setuid/setgid capability through OSQuery.
68- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
69 - $osquery_0
70- Investigate other alerts associated with the user/host during the past 48 hours.
71- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
72- Investigate whether the altered scripts call other malicious scripts elsewhere on the file system.
73 - If scripts or executables were dropped, retrieve the files and determine if they are malicious:
74 - Use a private sandboxed malware analysis system to perform analysis.
75 - Observe and collect information about the following activities:
76 - Attempts to contact external domains and addresses.
77 - Check if the domain is newly registered or unexpected.
78 - Check the reputation of the domain or IP address.
79 - File access, modification, and creation activities.
80 - Cron jobs, services and other persistence mechanisms.
81 - $osquery_1
82- Investigate abnormal behaviors by the subject process/user such as network connections, file modifications, and any other spawned child processes.
83 - Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
84 - $osquery_2
85 - $osquery_3
86 - Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
87 - $osquery_4
88- Investigate whether the user is currently logged in and active.
89 - $osquery_5
90
91### False Positive Analysis
92
93- If this activity is related to new benign software installation activity, consider adding exceptions — preferably with a combination of user and command line conditions.
94- If this activity is related to a system administrator that performed these actions for administrative purposes, consider adding exceptions for this specific administrator user account.
95- Try to understand the context of the execution by thinking about the user, machine, or business purpose. A small number of endpoints, such as servers with unique software, might appear unusual but satisfy a specific business need.
96
97### Response and remediation
98
99- Initiate the incident response process based on the outcome of the triage.
100- Isolate the involved host to prevent further post-compromise behavior.
101- If the triage identified malware, search the environment for additional compromised hosts.
102 - Implement temporary network rules, procedures, and segmentation to contain the malware.
103 - Stop suspicious processes.
104 - Immediately block the identified indicators of compromise (IoCs).
105 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
106- 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.
107- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
108- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
109- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
110"""
111risk_score = 47
112rule_id = "f5c005d3-4e17-48b0-9cd7-444d48857f97"
113setup = """## Setup
114
115This rule requires data coming in from Elastic Defend.
116
117### Elastic Defend Integration Setup
118Elastic 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.
119
120#### Prerequisite Requirements:
121- Fleet is required for Elastic Defend.
122- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
123
124#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
125- Go to the Kibana home page and click "Add integrations".
126- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
127- Click "Add Elastic Defend".
128- Configure the integration name and optionally add a description.
129- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
130- 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).
131- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
132- 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.
133For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
134- Click "Save and Continue".
135- 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.
136For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
137"""
138severity = "medium"
139tags = [
140 "Domain: Endpoint",
141 "OS: Linux",
142 "Use Case: Threat Detection",
143 "Tactic: Persistence",
144 "Data Source: Elastic Defend",
145 "Data Source: Elastic Endgame",
146 "Data Source: Crowdstrike",
147 "Data Source: SentinelOne",
148 "Resources: Investigation Guide",
149]
150timestamp_override = "event.ingested"
151type = "eql"
152
153query = '''
154process where host.os.type == "linux" and event.type == "start" and
155 event.action in ("exec", "exec_event", "start", "ProcessRollup2") and
156 process.name == "setcap" and process.args : "cap_set?id+ep" and not (
157 process.parent.name in ("jem", "vzctl") or
158 process.args like "/usr/bin/new?idmap"
159 )
160'''
161
162
163[[rule.threat]]
164framework = "MITRE ATT&CK"
165
166[rule.threat.tactic]
167id = "TA0003"
168name = "Persistence"
169reference = "https://attack.mitre.org/tactics/TA0003/"
170[[rule.threat]]
171framework = "MITRE ATT&CK"
172[[rule.threat.technique]]
173id = "T1548"
174name = "Abuse Elevation Control Mechanism"
175reference = "https://attack.mitre.org/techniques/T1548/"
176[[rule.threat.technique.subtechnique]]
177id = "T1548.001"
178name = "Setuid and Setgid"
179reference = "https://attack.mitre.org/techniques/T1548/001/"
180
181
182
183[rule.threat.tactic]
184id = "TA0004"
185name = "Privilege Escalation"
186reference = "https://attack.mitre.org/tactics/TA0004/"
Triage and analysis
Investigating Setcap setuid/setgid Capability Set
Setuid (Set User ID) and setgid (Set Group ID) are Unix-like OS features that enable processes to run with elevated privileges, based on the file owner or group.
Threat actors can exploit these attributes to achieve persistence by creating malicious binaries, allowing them to maintain control over a compromised system with elevated permissions.
This rule monitors for the addition of the cap_setuid+ep or cap_setgid+ep capabilities via setcap.
Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide. This investigation guide uses placeholder fields to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
Possible Investigation Steps
- Investigate the file that was targeted by the addition of the setuid/setgid capability through OSQuery.
- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
- $osquery_0
- Investigate other alerts associated with the user/host during the past 48 hours.
- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
- Investigate whether the altered scripts call other malicious scripts elsewhere on the file system.
- If scripts or executables were dropped, retrieve the files and determine if they are malicious:
- Use a private sandboxed malware analysis system to perform analysis.
- Observe and collect information about the following activities:
- Attempts to contact external domains and addresses.
- Check if the domain is newly registered or unexpected.
- Check the reputation of the domain or IP address.
- File access, modification, and creation activities.
- Cron jobs, services and other persistence mechanisms.
- $osquery_1
- Attempts to contact external domains and addresses.
- Observe and collect information about the following activities:
- Use a private sandboxed malware analysis system to perform analysis.
- If scripts or executables were dropped, retrieve the files and determine if they are malicious:
- Investigate abnormal behaviors by the subject process/user such as network connections, file modifications, and any other spawned child processes.
- Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
- $osquery_2
- $osquery_3
- Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
- $osquery_4
- Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
- Investigate whether the user is currently logged in and active.
- $osquery_5
False Positive Analysis
- If this activity is related to new benign software installation activity, consider adding exceptions — preferably with a combination of user and command line conditions.
- If this activity is related to a system administrator that performed these actions for administrative purposes, consider adding exceptions for this specific administrator user account.
- Try to understand the context of the execution by thinking about the user, machine, or business purpose. A small number of endpoints, such as servers with unique software, might appear unusual but satisfy a specific business need.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved host to prevent further post-compromise behavior.
- If the triage identified malware, search the environment for additional compromised hosts.
- Implement temporary network rules, procedures, and segmentation to contain the malware.
- Stop suspicious processes.
- Immediately block the identified indicators of compromise (IoCs).
- Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
- 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.
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
Related rules
- Boot File Copy
- Directory Creation in /bin directory
- GRUB Configuration Generation through Built-in Utilities
- Git Hook Child Process
- Initramfs Extraction via CPIO