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