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