Network Connection from Binary with RWX Memory Region

Monitors for the execution of a unix binary with read, write and execute memory region permissions, followed by a network connection. The mprotect() system call is used to change the access protections on a region of memory that has already been allocated. This syscall allows a process to modify the permissions of pages in its virtual address space, enabling or disabling permissions such as read, write, and execute for those pages. RWX permissions on memory is in many cases overly permissive, and should (especially in conjunction with an outbound network connection) be analyzed thoroughly.

Elastic rule (View on GitHub)

 1[metadata]
 2creation_date = "2024/03/13"
 3integration = ["auditd_manager", "endpoint"]
 4maturity = "production"
 5min_stack_comments = "The sampling feature within EQL was introduced in 8.6.0"
 6min_stack_version = "8.6.0"
 7updated_date = "2024/03/13"
 8
 9[rule]
10author = ["Elastic"]
11description = """
12Monitors for the execution of a unix binary with read, write and execute memory region permissions, followed by a 
13network connection. The mprotect() system call is used to change the access protections on a region of memory that has
14already been allocated. This syscall allows a process to modify the permissions of pages in its virtual address space,
15enabling or disabling permissions such as read, write, and execute for those pages. RWX permissions on memory is in many
16cases overly permissive, and should (especially in conjunction with an outbound network connection) be analyzed 
17thoroughly. 
18"""
19from = "now-9m"
20index = ["logs-endpoint.events.*", "auditbeat-*", "logs-auditd_manager.auditd-*"]
21language = "eql"
22license = "Elastic License v2"
23name = "Network Connection from Binary with RWX Memory Region"
24references = [
25    "https://man7.org/linux/man-pages/man2/mprotect.2.html"
26]
27risk_score = 47
28rule_id = "32300431-c2d5-432d-8ec8-0e03f9924756"
29setup = """## Setup
30
31This 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.

Kibana --> Management --> Integrations --> Auditd Manager --> Add Auditd Manager

1`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.
2For this detection rule to trigger, the following additional audit rules are required to be added to the integration:

-a always,exit -F arch=b64 -S mprotect

 1Add the newly installed `auditd manager` to an agent policy, and deploy the agent on a Linux system from which auditd log files are desirable.
 2"""
 3severity = "medium"
 4tags = [
 5        "Domain: Endpoint",
 6        "OS: Linux",
 7        "Use Case: Threat Detection",
 8        "Tactic: Execution",
 9        "Data Source: Elastic Defend",
10        "Data Source: Auditd Manager"
11        ]
12timestamp_override = "event.ingested"
13type = "eql"
14query = '''
15sample by host.id, process.pid, process.name
16  /* auditd.data.a2 == "7" translates to RWX memory region protection (PROT_READ | PROT_WRITE | PROT_EXEC) */
17  [process where host.os.type == "linux" and auditd.data.syscall == "mprotect" and auditd.data.a2 == "7"]
18  [network where host.os.type == "linux" and event.type == "start" and event.action == "connection_attempted" and
19   not cidrmatch(destination.ip, "127.0.0.0/8", "169.254.0.0/16", "224.0.0.0/4", "::1")]
20'''
21
22[[rule.threat]]
23framework = "MITRE ATT&CK"
24
25[rule.threat.tactic]
26name = "Execution"
27id = "TA0002"
28reference = "https://attack.mitre.org/tactics/TA0002/"
29
30[[rule.threat.technique]]
31id = "T1059"
32name = "Command and Scripting Interpreter"
33reference = "https://attack.mitre.org/techniques/T1059/"
34
35[[rule.threat.technique.subtechnique]]
36id = "T1059.004"
37name = "Unix Shell"
38reference = "https://attack.mitre.org/techniques/T1059/004/"
39
40[[rule.threat]]
41framework = "MITRE ATT&CK"
42
43[rule.threat.tactic]
44name = "Command and Control"
45id = "TA0011"
46reference = "https://attack.mitre.org/tactics/TA0011/"
47
48[[rule.threat.technique]]
49name = "Application Layer Protocol"
50id = "T1071"
51reference = "https://attack.mitre.org/techniques/T1071/"

References

Related rules

to-top