9
9
"github.com/kubescape/node-agent/pkg/ruleengine"
10
10
"github.com/kubescape/node-agent/pkg/utils"
11
11
12
- ruleenginetypes "github.com/kubescape/node-agent/pkg/ruleengine/types"
13
-
14
12
apitypes "github.com/armosec/armoapi-go/armotypes"
15
13
tracerexectype "github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/trace/exec/types"
16
14
)
@@ -24,11 +22,10 @@ var R1005FilelessExecutionRuleDescriptor = RuleDescriptor{
24
22
ID : R1005ID ,
25
23
Name : R1005Name ,
26
24
Description : "Detecting Fileless Execution" ,
27
- Tags : []string {"syscall" , " fileless" , "execution" },
25
+ Tags : []string {"fileless" , "execution" },
28
26
Priority : RulePriorityHigh ,
29
27
Requirements : & RuleRequirements {
30
28
EventTypes : []utils.EventType {
31
- utils .SyscallEventType ,
32
29
utils .ExecveEventType ,
33
30
},
34
31
},
@@ -41,11 +38,10 @@ var _ ruleengine.RuleEvaluator = (*R1005FilelessExecution)(nil)
41
38
42
39
type R1005FilelessExecution struct {
43
40
BaseRule
44
- alreadyNotified bool
45
41
}
46
42
47
43
func CreateRuleR1005FilelessExecution () * R1005FilelessExecution {
48
- return & R1005FilelessExecution {alreadyNotified : false }
44
+ return & R1005FilelessExecution {}
49
45
}
50
46
51
47
func (rule * R1005FilelessExecution ) Name () string {
@@ -59,54 +55,13 @@ func (rule *R1005FilelessExecution) DeleteRule() {
59
55
}
60
56
61
57
func (rule * R1005FilelessExecution ) ProcessEvent (eventType utils.EventType , event interface {}, _ objectcache.ObjectCache ) ruleengine.RuleFailure {
62
- if eventType == utils .SyscallEventType {
63
- return rule .handleSyscallEvent (event .(* ruleenginetypes.SyscallEvent ))
64
- } else if eventType == utils .ExecveEventType {
58
+ if eventType == utils .ExecveEventType {
65
59
return rule .handleExecveEvent (event .(* tracerexectype.Event ))
66
60
}
67
61
68
62
return nil
69
63
}
70
64
71
- func (rule * R1005FilelessExecution ) handleSyscallEvent (syscallEvent * ruleenginetypes.SyscallEvent ) ruleengine.RuleFailure {
72
- if rule .alreadyNotified {
73
- return nil
74
- }
75
-
76
- if syscallEvent .SyscallName == "memfd_create" {
77
- rule .alreadyNotified = true
78
- ruleFailure := GenericRuleFailure {
79
- BaseRuntimeAlert : apitypes.BaseRuntimeAlert {
80
- AlertName : rule .Name (),
81
- InfectedPID : syscallEvent .Pid ,
82
- FixSuggestions : "If this is a legitimate action, please consider removing this workload from the binding of this rule" ,
83
- Severity : R1005FilelessExecutionRuleDescriptor .Priority ,
84
- },
85
- RuntimeProcessDetails : apitypes.ProcessTree {
86
- ProcessTree : apitypes.Process {
87
- Comm : syscallEvent .Comm ,
88
- Gid : & syscallEvent .Gid ,
89
- PID : syscallEvent .Pid ,
90
- Uid : & syscallEvent .Uid ,
91
- },
92
- ContainerID : syscallEvent .Runtime .ContainerID ,
93
- },
94
- TriggerEvent : syscallEvent .Event ,
95
- RuleAlert : apitypes.RuleAlert {
96
- RuleDescription : fmt .Sprintf ("Fileless execution detected: syscall memfd_create executed in: %s" , syscallEvent .GetContainer ()),
97
- },
98
- RuntimeAlertK8sDetails : apitypes.RuntimeAlertK8sDetails {
99
- PodName : syscallEvent .GetPod (),
100
- },
101
- RuleID : rule .ID (),
102
- }
103
-
104
- return & ruleFailure
105
- }
106
-
107
- return nil
108
- }
109
-
110
65
func (rule * R1005FilelessExecution ) handleExecveEvent (execEvent * tracerexectype.Event ) ruleengine.RuleFailure {
111
66
execFullPath := getExecFullPathFromEvent (execEvent )
112
67
execPathDir := filepath .Dir (execFullPath )
0 commit comments