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