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"
 5updated_date = "2024/10/17"
 6
 7[rule]
 8author = ["Elastic"]
 9description = """
10Monitors for the execution of a unix binary with read, write and execute memory region permissions, followed by a
11network connection. The mprotect() system call is used to change the access protections on a region of memory that has
12already been allocated. This syscall allows a process to modify the permissions of pages in its virtual address space,
13enabling or disabling permissions such as read, write, and execute for those pages. RWX permissions on memory is in many
14cases overly permissive, and should (especially in conjunction with an outbound network connection) be analyzed
15thoroughly.
16"""
17from = "now-9m"
18index = ["logs-endpoint.events.*", "auditbeat-*", "logs-auditd_manager.auditd-*"]
19language = "eql"
20license = "Elastic License v2"
21name = "Network Connection from Binary with RWX Memory Region"
22references = [
23    "https://man7.org/linux/man-pages/man2/mprotect.2.html",
24    "https://www.elastic.co/security-labs/linux-detection-engineering-with-auditd",
25]
26risk_score = 47
27rule_id = "32300431-c2d5-432d-8ec8-0e03f9924756"
28setup = """## Setup
29
30This 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" and
18   not process.name == "httpd"]
19  [network where host.os.type == "linux" and event.type == "start" and event.action == "connection_attempted" and
20   not cidrmatch(destination.ip, "127.0.0.0/8", "169.254.0.0/16", "224.0.0.0/4", "::1")]
21'''
22
23[[rule.threat]]
24framework = "MITRE ATT&CK"
25
26[[rule.threat.technique]]
27id = "T1059"
28name = "Command and Scripting Interpreter"
29reference = "https://attack.mitre.org/techniques/T1059/"
30
31[[rule.threat.technique.subtechnique]]
32id = "T1059.004"
33name = "Unix Shell"
34reference = "https://attack.mitre.org/techniques/T1059/004/"
35
36[rule.threat.tactic]
37id = "TA0002"
38name = "Execution"
39reference = "https://attack.mitre.org/tactics/TA0002/"
40
41[[rule.threat]]
42framework = "MITRE ATT&CK"
43
44[[rule.threat.technique]]
45id = "T1071"
46name = "Application Layer Protocol"
47reference = "https://attack.mitre.org/techniques/T1071/"
48
49[rule.threat.tactic]
50id = "TA0011"
51name = "Command and Control"
52reference = "https://attack.mitre.org/tactics/TA0011/"

References

Related rules

to-top