Kernel Module Removal

Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. This rule identifies attempts to remove a kernel module.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/04/24"
  3integration = ["endpoint", "crowdstrike", "sentinel_one_cloud_funnel"]
  4maturity = "production"
  5updated_date = "2025/03/20"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the
 11functionality of the kernel without the need to reboot the system. This rule identifies attempts to remove a kernel
 12module.
 13"""
 14false_positives = [
 15    """
 16    There is usually no reason to remove modules, but some buggy modules require it. These can be exempted by username.
 17    Note that some Linux distributions are not built to support the removal of modules at all.
 18    """,
 19]
 20from = "now-9m"
 21index = [
 22    "endgame-*",
 23    "logs-crowdstrike.fdr*",
 24    "logs-endpoint.events.process*",
 25    "logs-sentinel_one_cloud_funnel.*",
 26]
 27language = "eql"
 28license = "Elastic License v2"
 29name = "Kernel Module Removal"
 30note = """## Triage and analysis
 31
 32> **Disclaimer**:
 33> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
 34
 35### Investigating Kernel Module Removal
 36
 37Kernel modules dynamically extend a Linux kernel's capabilities without rebooting. Adversaries may exploit this by removing modules to disable security features or hide malicious activities. The detection rule identifies suspicious module removal attempts by monitoring processes like `rmmod` or `modprobe` with removal arguments, especially when initiated by common shell environments, indicating potential defense evasion tactics.
 38
 39### Possible investigation steps
 40
 41- Review the process details to confirm the execution of `rmmod` or `modprobe` with removal arguments. Check the command line arguments to ensure they match the suspicious activity criteria.
 42- Identify the parent process of the suspicious activity, focusing on shell environments like `sudo`, `bash`, `dash`, `ash`, `sh`, `tcsh`, `csh`, `zsh`, `ksh`, or `fish`, to understand the context in which the module removal was initiated.
 43- Investigate the user account associated with the process to determine if the activity aligns with expected behavior or if it indicates potential unauthorized access.
 44- Check system logs and audit logs for any preceding or subsequent suspicious activities that might correlate with the module removal attempt, such as privilege escalation or other defense evasion tactics.
 45- Assess the impact of the module removal on system security features and functionality, and determine if any critical security modules were targeted.
 46- Review recent changes or updates to the system that might explain the module removal, such as legitimate maintenance or updates, to rule out false positives.
 47
 48### False positive analysis
 49
 50- Routine administrative tasks may trigger the rule when system administrators use `rmmod` or `modprobe` for legitimate maintenance. To handle this, create exceptions for specific user accounts or scripts known to perform these tasks regularly.
 51- Automated scripts or configuration management tools that manage kernel modules might cause false positives. Identify these tools and exclude their processes from the rule to prevent unnecessary alerts.
 52- Some Linux distributions or custom setups might use shell scripts that invoke `rmmod` or `modprobe` during system updates or package installations. Monitor these activities and whitelist the associated parent processes if they are verified as non-threatening.
 53- Development environments where kernel module testing is frequent can generate alerts. Exclude specific development machines or user accounts involved in module testing to reduce noise.
 54- Security tools that perform regular checks or updates on kernel modules might inadvertently trigger the rule. Verify these tools and add them to the exception list to avoid false positives.
 55
 56### Response and remediation
 57
 58- Immediately isolate the affected system from the network to prevent further unauthorized access or potential lateral movement by the adversary.
 59- Terminate any suspicious processes identified as attempting to remove kernel modules, such as those initiated by `rmmod` or `modprobe` with removal arguments.
 60- Conduct a thorough review of user accounts and privileges on the affected system to ensure no unauthorized access or privilege escalation has occurred.
 61- Restore any disabled security features or kernel modules to their original state to ensure the system's defenses are intact.
 62- Analyze system logs and audit trails to identify any additional indicators of compromise or related malicious activities.
 63- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if the threat is part of a larger attack campaign.
 64- Implement enhanced monitoring and alerting for similar activities across the network to detect and respond to future attempts promptly."""
 65references = ["http://man7.org/linux/man-pages/man8/modprobe.8.html"]
 66risk_score = 47
 67rule_id = "cd66a5af-e34b-4bb0-8931-57d0a043f2ef"
 68setup = """## Setup
 69
 70This rule requires data coming in from Elastic Defend.
 71
 72### Elastic Defend Integration Setup
 73Elastic 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.
 74
 75#### Prerequisite Requirements:
 76- Fleet is required for Elastic Defend.
 77- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 78
 79#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 80- Go to the Kibana home page and click "Add integrations".
 81- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 82- Click "Add Elastic Defend".
 83- Configure the integration name and optionally add a description.
 84- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 85- 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).
 86- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 87- 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.
 88For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 89- Click "Save and Continue".
 90- 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.
 91For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 92"""
 93severity = "medium"
 94tags = [
 95    "Domain: Endpoint",
 96    "OS: Linux",
 97    "Use Case: Threat Detection",
 98    "Tactic: Defense Evasion",
 99    "Data Source: Elastic Endgame",
100    "Data Source: Elastic Defend",
101    "Data Source: Crowdstrike",
102    "Data Source: SentinelOne",
103    "Resources: Investigation Guide",
104]
105timestamp_override = "event.ingested"
106type = "eql"
107
108query = '''
109process where host.os.type == "linux" and event.type == "start" and
110  event.action in ("exec", "exec_event", "start", "ProcessRollup2") and
111  (
112    process.name == "rmmod" or
113    (process.name == "modprobe" and process.args in ("--remove", "-r"))
114  ) and
115  process.parent.name in ("sudo", "bash", "dash", "ash", "sh", "tcsh", "csh", "zsh", "ksh", "fish")
116'''
117
118
119[[rule.threat]]
120framework = "MITRE ATT&CK"
121[[rule.threat.technique]]
122id = "T1562"
123name = "Impair Defenses"
124reference = "https://attack.mitre.org/techniques/T1562/"
125[[rule.threat.technique.subtechnique]]
126id = "T1562.001"
127name = "Disable or Modify Tools"
128reference = "https://attack.mitre.org/techniques/T1562/001/"
129
130
131
132[rule.threat.tactic]
133id = "TA0005"
134name = "Defense Evasion"
135reference = "https://attack.mitre.org/tactics/TA0005/"
136[[rule.threat]]
137framework = "MITRE ATT&CK"
138[[rule.threat.technique]]
139id = "T1547"
140name = "Boot or Logon Autostart Execution"
141reference = "https://attack.mitre.org/techniques/T1547/"
142[[rule.threat.technique.subtechnique]]
143id = "T1547.006"
144name = "Kernel Modules and Extensions"
145reference = "https://attack.mitre.org/techniques/T1547/006/"
146
147
148
149[rule.threat.tactic]
150id = "TA0003"
151name = "Persistence"
152reference = "https://attack.mitre.org/tactics/TA0003/"
...
toml

Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

Kernel modules dynamically extend a Linux kernel's capabilities without rebooting. Adversaries may exploit this by removing modules to disable security features or hide malicious activities. The detection rule identifies suspicious module removal attempts by monitoring processes like rmmod or modprobe with removal arguments, especially when initiated by common shell environments, indicating potential defense evasion tactics.

  • Review the process details to confirm the execution of rmmod or modprobe with removal arguments. Check the command line arguments to ensure they match the suspicious activity criteria.
  • Identify the parent process of the suspicious activity, focusing on shell environments like sudo, bash, dash, ash, sh, tcsh, csh, zsh, ksh, or fish, to understand the context in which the module removal was initiated.
  • Investigate the user account associated with the process to determine if the activity aligns with expected behavior or if it indicates potential unauthorized access.
  • Check system logs and audit logs for any preceding or subsequent suspicious activities that might correlate with the module removal attempt, such as privilege escalation or other defense evasion tactics.
  • Assess the impact of the module removal on system security features and functionality, and determine if any critical security modules were targeted.
  • Review recent changes or updates to the system that might explain the module removal, such as legitimate maintenance or updates, to rule out false positives.
  • Routine administrative tasks may trigger the rule when system administrators use rmmod or modprobe for legitimate maintenance. To handle this, create exceptions for specific user accounts or scripts known to perform these tasks regularly.
  • Automated scripts or configuration management tools that manage kernel modules might cause false positives. Identify these tools and exclude their processes from the rule to prevent unnecessary alerts.
  • Some Linux distributions or custom setups might use shell scripts that invoke rmmod or modprobe during system updates or package installations. Monitor these activities and whitelist the associated parent processes if they are verified as non-threatening.
  • Development environments where kernel module testing is frequent can generate alerts. Exclude specific development machines or user accounts involved in module testing to reduce noise.
  • Security tools that perform regular checks or updates on kernel modules might inadvertently trigger the rule. Verify these tools and add them to the exception list to avoid false positives.
  • Immediately isolate the affected system from the network to prevent further unauthorized access or potential lateral movement by the adversary.
  • Terminate any suspicious processes identified as attempting to remove kernel modules, such as those initiated by rmmod or modprobe with removal arguments.
  • Conduct a thorough review of user accounts and privileges on the affected system to ensure no unauthorized access or privilege escalation has occurred.
  • Restore any disabled security features or kernel modules to their original state to ensure the system's defenses are intact.
  • Analyze system logs and audit trails to identify any additional indicators of compromise or related malicious activities.
  • Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if the threat is part of a larger attack campaign.
  • Implement enhanced monitoring and alerting for similar activities across the network to detect and respond to future attempts promptly.

References

Related rules

to-top