Skip to content

Commit 7d64dc2

Browse files
authored
[Rule tunings / New Rule] Kernel Unload and Enumeration (#2838)
* [Rule Tunings] Kernel Module Enumeration / Removal * [Rule Tunings] Kernel Module Enumeration and Removal * Deleted copy of wrong file * EQL Conversion and made the rule more resilient * Converted rules to EQL and made rules more resilient * Removed unwanted rule from PR * fixed unit tests * fixed unit testing, removed endgame support * Added a rule to detect kernel module enum via proc * Did some additional tuning, 0 hits in RedSector now
1 parent 082e92c commit 7d64dc2

File tree

3 files changed

+85
-13
lines changed

3 files changed

+85
-13
lines changed

rules/linux/defense_evasion_kernel_module_removal.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ integration = ["endpoint"]
44
maturity = "production"
55
min_stack_comments = "New fields added: required_fields, related_integrations, setup"
66
min_stack_version = "8.3.0"
7-
updated_date = "2023/02/22"
7+
updated_date = "2023/06/08"
88

99
[rule]
1010
author = ["Elastic"]
@@ -20,8 +20,8 @@ false_positives = [
2020
""",
2121
]
2222
from = "now-9m"
23-
index = ["auditbeat-*", "logs-endpoint.events.*", "endgame-*"]
24-
language = "kuery"
23+
index = ["logs-endpoint.events.*", "endgame-*"]
24+
language = "eql"
2525
license = "Elastic License v2"
2626
name = "Kernel Module Removal"
2727
references = ["http://man7.org/linux/man-pages/man8/modprobe.8.html"]
@@ -30,11 +30,11 @@ rule_id = "cd66a5af-e34b-4bb0-8931-57d0a043f2ef"
3030
severity = "high"
3131
tags = ["Elastic", "Host", "Linux", "Threat Detection", "Defense Evasion", "Elastic Endgame"]
3232
timestamp_override = "event.ingested"
33-
type = "query"
33+
type = "eql"
3434

3535
query = '''
36-
event.category:process and host.os.type:linux and event.type:(start or process_started) and
37-
process.args:((rmmod and sudo) or (modprobe and sudo and ("--remove" or "-r")))
36+
process where host.os.type == "linux" and event.action == "exec" and process.name == "rmmod" or
37+
(process.name == "modprobe" and process.args in ("--remove", "-r"))
3838
'''
3939

4040

rules/linux/discovery_kernel_module_enumeration.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ integration = ["endpoint"]
44
maturity = "production"
55
min_stack_comments = "New fields added: required_fields, related_integrations, setup"
66
min_stack_version = "8.3.0"
7-
updated_date = "2023/02/22"
7+
updated_date = "2023/06/08"
88

99
[rule]
1010
author = ["Elastic"]
@@ -20,20 +20,23 @@ false_positives = [
2020
""",
2121
]
2222
from = "now-9m"
23-
index = ["auditbeat-*", "logs-endpoint.events.*", "endgame-*"]
24-
language = "kuery"
23+
index = ["logs-endpoint.events.*"]
24+
language = "eql"
2525
license = "Elastic License v2"
2626
name = "Enumeration of Kernel Modules"
2727
risk_score = 47
2828
rule_id = "2d8043ed-5bda-4caf-801c-c1feb7410504"
2929
severity = "medium"
30-
tags = ["Elastic", "Host", "Linux", "Threat Detection", "Discovery", "Elastic Endgame"]
30+
tags = ["Elastic", "Host", "Linux", "Threat Detection", "Discovery"]
3131
timestamp_override = "event.ingested"
32-
type = "query"
32+
type = "eql"
3333

3434
query = '''
35-
event.category:process and host.os.type:linux and event.type:(start or process_started) and
36-
process.args:(kmod and list and sudo or sudo and (depmod or lsmod or modinfo))
35+
process where host.os.type == "linux" and event.type == "start" and
36+
((process.name == "kmod" and process.args == "list") or (process.name == "modinfo" and process.parent.user.id != "0") or
37+
(process.name == "depmod" and process.args in ("--all", "-a") and process.parent.user.id != "0")
38+
or process.name == "lsmod") and not process.parent.name : ("vboxmanage", "virtualbox", "prime-offload", "vboxdrv.sh") and not
39+
process.group_leader.name : "qualys-cloud-agent"
3740
'''
3841

3942

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[metadata]
2+
creation_date = "2020/04/12"
3+
integration = ["auditd_manager"]
4+
maturity = "production"
5+
min_stack_comments = "New fields added: required_fields, related_integrations, setup"
6+
min_stack_version = "8.3.0"
7+
updated_date = "2023/06/12"
8+
9+
[rule]
10+
author = ["Elastic"]
11+
description = """
12+
Loadable Kernel Modules (or LKMs) are pieces of code that can be loaded and unloaded into the kernel upon demand. They
13+
extend the functionality of the kernel without the need to reboot the system. This identifies attempts to enumerate
14+
information about a kernel module using the /proc/modules filesystem. This filesystem is used by utilities such as
15+
lsmod and kmod to list the available kernel modules.
16+
"""
17+
false_positives = [
18+
"""
19+
Security tools and device drivers may run these programs in order to enumerate kernel modules. Use of these programs
20+
by ordinary users is uncommon. These can be exempted by process name or username.
21+
""",
22+
]
23+
from = "now-9m"
24+
index = ["auditbeat-*", "logs-auditd_manager.auditd-*"]
25+
language = "eql"
26+
license = "Elastic License v2"
27+
name = "Enumeration of Kernel Modules via Proc"
28+
note = """## Setup
29+
This rule requires the use of the `auditd_manager` integration. `Auditd_manager` is a tool designed to simplify and enhance the management of the audit subsystem in Linux systems. It provides a user-friendly interface and automation capabilities for configuring and monitoring system auditing through the auditd daemon. With `auditd_manager`, administrators can easily define audit rules, track system events, and generate comprehensive audit reports, improving overall security and compliance in the system. The following steps should be executed in order to install and deploy `auditd_manager` on a Linux system.
30+
```
31+
Kibana -->
32+
Management -->
33+
Integrations -->
34+
Auditd Manager -->
35+
Add Auditd Manager
36+
```
37+
`Auditd_manager` subscribes to the kernel and receives events as they occur without any additional configuration. However, if more advanced configuration is required to detect specific behavior, audit rules can be added to the integration in either the "audit rules" configuration box or the "auditd rule files" box by specifying a file to read the audit rules from.
38+
For this detection rule to trigger, the following additional audit rules are required to be added to the integration:
39+
```
40+
-w /proc/ -p r -k audit_proc
41+
```
42+
Add the newly installed `auditd manager` to an agent policy, and deploy the agent on a Linux system from which auditd log files are desirable.
43+
"""
44+
risk_score = 47
45+
rule_id = "80084fa9-8677-4453-8680-b891d3c0c778"
46+
severity = "medium"
47+
tags = ["Elastic", "Host", "Linux", "Threat Detection", "Discovery"]
48+
timestamp_override = "event.ingested"
49+
type = "eql"
50+
51+
query = '''
52+
file where host.os.type == "linux" and event.action == "opened-file" and
53+
file.path == "/proc/modules" and not process.parent.pid == 1
54+
'''
55+
56+
57+
[[rule.threat]]
58+
framework = "MITRE ATT&CK"
59+
[[rule.threat.technique]]
60+
id = "T1082"
61+
name = "System Information Discovery"
62+
reference = "https://attack.mitre.org/techniques/T1082/"
63+
64+
65+
[rule.threat.tactic]
66+
id = "TA0007"
67+
name = "Discovery"
68+
reference = "https://attack.mitre.org/tactics/TA0007/"
69+

0 commit comments

Comments
 (0)