-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsyspce_manager_engine.py
More file actions
243 lines (178 loc) · 10.4 KB
/
syspce_manager_engine.py
File metadata and controls
243 lines (178 loc) · 10.4 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import logging
import threading
from time import sleep
from syspce_manager import Manager_
from syspce_message import *
from syspce_engine_filter import FilterEngine
from syspce_manage_tree import ManageTree
from syspce_engine_hierarchy import HierarchyEngine
from syspce_engine_baseline import BaselineEngine
from syspce_processes_tree import ProcessesTree
log = logging.getLogger('sysmoncorrelator')
class EngineManager(Manager_):
def __init__(self, data_buffer_in, data_condition_in):
Manager_.__init__(self, data_buffer_in,
data_condition_in)
self.name = 'Engine Manager'
self.module_id = Module.ENGINE_MANAGER
self.messages_accepted = [MessageType.COMMAND, MessageType.DATAIN]
self.hierarchy_engine_enabled = True
self.baseline_engine_enabled = False
self.daemon_ = False
self.processes_tree = ProcessesTree()
def _process_messages(self, message_list):
for message in message_list:
if message._subtype == MessageSubType.TERMINATE:
self._terminate()
elif message._subtype == MessageSubType.STOP_JOB:
#Stoping a daemon job
if self.daemon_module_executing(message._src):
self.daemon_ = False
self.stop_job_modules(message._src)
elif message._subtype == MessageSubType.STATS:
self._stats(message._src)
elif message._subtype == MessageSubType.SET_CONFIG:
# message._content[0] config to set, message._content[1] value
if message._content[0][0] == "hierarchy_engine_enabled":
self.hierarchy_engine_enabled = message._content[0][1]
elif message._content[0][0] == "baseline_engine_enabled":
self.baseline_engine_enabled = message._content[0][1]
# Send info related to a concret pid
elif message._subtype == MessageSubType.INFO_EVENTID:
self._info_eventid(message._src,
message._content[0][0], #pid
message._content[0][1], #eventid
message._content[0][2]) #computer
# ps command
elif message._subtype == MessageSubType.PS:
self._ps(message._src,
message._content[0][0], #tree_id
message._content[0][1]) #computer
# Filter engine, filter data from user
elif message._subtype == MessageSubType.FILTER_DATA:
self._filter_events(message._src,
message._content[0], #search filter
message._content[1], #search attributes
message._content[2]) #data
# insert events to processes tree and start detection engines
# but not in daemon mode, it dies after do the jobs
elif message._subtype == MessageSubType.DETECT_SINGLE:
self._detect_single(message._src,
message._content[0], #detection.rules
message._content[1], #baseline.rules
message._content[2], #detection.macros
message._content[3]) #data
# insert events to processes tree and start detection engines
# using daemon mode, engines are executing always
elif message._subtype == MessageSubType.DETECT_DAEMON:
self._detect_daemon(message._src,
message._content[0], #detection.rules
message._content[1], #baseline.rules
message._content[2], #detection.macros
message._content[3]) #data
def _filter_events(self, src, search_filter, filter_attribute, events):
filter_event = FilterEngine(self.data_buffer_in,
self.data_condition_in,
src,
search_filter,
filter_attribute,
events, False)
filter_event.start()
self.add_working_module(src, [filter_event])
def _info_eventid(self, src, pid, eventid, computer):
# add data to tree
manage_tree = ManageTree(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src)
manage_tree.set_method(manage_tree.info_eventid,
pid, eventid, computer )
manage_tree.start()
def _ps(self, src, tree_id, computer):
# add data to tree
manage_tree = ManageTree(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src)
manage_tree.set_method(manage_tree.ps, tree_id, computer)
manage_tree.start()
def _stats(self, src):
# getting statistics
manage_tree = ManageTree(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src)
manage_tree.set_method(manage_tree.get_ptree_stats_str)
manage_tree.start()
self.add_working_module(src, [manage_tree])
def _detect_daemon(self, src, detection_rules, baseline_rules, macros, events):
# add data to tree
manage_tree = ManageTree(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src)
manage_tree.set_method(manage_tree.add_events_to_tree, events)
manage_tree.start()
self.add_working_module(src, [manage_tree])
# Check if is already in daemon mode, don't create new intances
if not self.daemon_:
# dont like this sync, TODO
sleep(1)
# Execute engines
if self.hierarchy_engine_enabled:
# Hierarchy Engine
hierarchy_engine = HierarchyEngine(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src,
detection_rules,
macros, True)
hierarchy_engine.start()
self.add_working_module(src, [hierarchy_engine])
self.daemon_ = True
# dont like this sync, TODO
sleep(1)
# Baseline Engine
if self.baseline_engine_enabled:
baseline_engine = BaselineEngine(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src,
baseline_rules,
macros, events, True)
baseline_engine.start()
self.add_working_module(src, [baseline_engine])
def _detect_single(self, src, detection_rules, baseline_rules, macros, events):
# add data to tree
manage_tree = ManageTree(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src)
manage_tree.set_method(manage_tree.add_events_to_tree, events)
manage_tree.start()
self.add_working_module(src, [manage_tree])
# dont like this sync, TODO
sleep(1)
# Execute engines
if self.hierarchy_engine_enabled:
# Hierarchy Engine
hierarchy_engine = HierarchyEngine(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src,
detection_rules,
macros,False)
hierarchy_engine.start()
self.add_working_module(src, [hierarchy_engine])
# dont like this sync, TODO
sleep(1)
# Baseline Engine
if self.baseline_engine_enabled:
baseline_engine = BaselineEngine(self.data_buffer_in,
self.data_condition_in,
self.processes_tree,
src,
baseline_rules,
macros, events, False)
baseline_engine.start()
self.add_working_module(src, [baseline_engine])