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

to-top