MEDIUM
Source
Tracee
ID
TRC-7
Version
0.1.0
Date
28 Jun 2022

Ld_preload

Usage of LD_PRELOAD to allow hooks on process

MITRE ATT&CK

Persistence: Hijack Execution Flow

Rego Policy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package tracee.TRC_7

import data.tracee.helpers

__rego_metadoc__ := {
	"id": "TRC-7",
	"version": "0.1.0",
	"name": "LD_PRELOAD",
	"description": "Usage of LD_PRELOAD to allow hooks on process",
	"tags": ["linux", "container"],
	"properties": {
		"Severity": 2,
		"MITRE ATT&CK": "Persistence: Hijack Execution Flow",
	},
}

eventSelectors := [
	{
		"source": "tracee",
		"name": "execve",
	},
	{
		"source": "tracee",
		"name": "security_file_open",
	},
]

tracee_selected_events[eventSelector] {
	eventSelector := eventSelectors[_]
}

tracee_match {
	input.eventName == "execve"
	envp = helpers.get_tracee_argument("envp")

	envvar := envp[_]
	startswith(envvar, "LD_PRELOAD")
}

tracee_match {
	input.eventName == "execve"
	envp = helpers.get_tracee_argument("envp")

	envvar := envp[_]
	startswith(envvar, "LD_LIBRARY_PATH")
}

tracee_match {
	input.eventName == "security_file_open"
	flags = helpers.get_tracee_argument("flags")

	helpers.is_file_write(flags)

	pathname := helpers.get_tracee_argument("pathname")

	pathname == "/etc/ld.so.preload"
}