2021-12-31 09:54:47 -05:00
|
|
|
#include "module_manager.h"
|
2022-01-04 13:26:13 -05:00
|
|
|
#include "xdp.h"
|
|
|
|
|
#include "sched.h"
|
2022-01-04 20:09:59 -05:00
|
|
|
#include "fs.h"
|
2022-02-06 14:15:57 -05:00
|
|
|
#include "exec.h"
|
2022-03-03 05:53:51 -05:00
|
|
|
#include "injection.h"
|
2021-12-31 09:54:47 -05:00
|
|
|
|
|
|
|
|
module_config_t module_config = {
|
|
|
|
|
.xdp_module = {
|
|
|
|
|
.all = ON,
|
2022-01-04 13:26:13 -05:00
|
|
|
.xdp_receive = OFF
|
2021-12-31 09:54:47 -05:00
|
|
|
},
|
|
|
|
|
.sched_module = {
|
|
|
|
|
.all = ON,
|
2022-01-04 13:26:13 -05:00
|
|
|
.handle_sched_process_exec = OFF
|
2022-01-04 20:09:59 -05:00
|
|
|
},
|
|
|
|
|
.fs_module = {
|
|
|
|
|
.all = ON,
|
2022-01-26 13:04:23 -05:00
|
|
|
.tp_sys_enter_read = OFF,
|
2022-02-05 13:49:20 -05:00
|
|
|
.tp_sys_exit_read = OFF,
|
|
|
|
|
.tp_sys_enter_openat = OFF
|
2022-02-06 14:15:57 -05:00
|
|
|
},
|
|
|
|
|
.exec_module = {
|
|
|
|
|
.all = ON,
|
|
|
|
|
.tp_sys_enter_execve = OFF
|
2022-03-03 05:53:51 -05:00
|
|
|
},
|
|
|
|
|
.injection_module = {
|
|
|
|
|
.all = ON,
|
|
|
|
|
.uprobe_execute_command = OFF
|
2021-12-31 09:54:47 -05:00
|
|
|
}
|
2022-01-04 20:09:59 -05:00
|
|
|
|
2021-12-31 09:54:47 -05:00
|
|
|
};
|
2022-01-04 13:26:13 -05:00
|
|
|
|
|
|
|
|
module_config_attr_t module_config_attr = {
|
|
|
|
|
.skel = NULL,
|
|
|
|
|
.xdp_module = {
|
|
|
|
|
.ifindex = -1,
|
|
|
|
|
.flags = -1
|
|
|
|
|
},
|
2022-01-14 22:05:08 -05:00
|
|
|
.sched_module = {},
|
2022-02-06 14:15:57 -05:00
|
|
|
.fs_module = {},
|
2022-03-03 05:53:51 -05:00
|
|
|
.exec_module = {},
|
|
|
|
|
.injection_module = {}
|
2022-01-04 13:26:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int setup_all_modules(){
|
|
|
|
|
//Alias
|
|
|
|
|
module_config_t config = module_config;
|
|
|
|
|
module_config_attr_t attr = module_config_attr;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
//XDP
|
|
|
|
|
if(config.xdp_module.all == ON){
|
|
|
|
|
ret = attach_xdp_all(attr.skel, attr.xdp_module.ifindex, attr.xdp_module.flags);
|
|
|
|
|
}else{
|
|
|
|
|
if(config.xdp_module.xdp_receive == ON) ret = attach_xdp_receive(attr.skel, attr.xdp_module.ifindex, attr.xdp_module.flags);
|
|
|
|
|
}
|
|
|
|
|
if(ret!=0) return -1;
|
|
|
|
|
|
|
|
|
|
//SCHED
|
|
|
|
|
if(config.sched_module.all == ON){
|
|
|
|
|
ret = attach_sched_all(attr.skel);
|
|
|
|
|
}else{
|
|
|
|
|
if(config.sched_module.handle_sched_process_exec == ON) ret = attach_handle_sched_process_exec(attr.skel);
|
|
|
|
|
}
|
|
|
|
|
if(ret!=0) return -1;
|
|
|
|
|
|
2022-01-04 20:09:59 -05:00
|
|
|
//FS (File system)
|
|
|
|
|
if(config.fs_module.all == ON){
|
|
|
|
|
ret = attach_fs_all(attr.skel);
|
|
|
|
|
}else{
|
2022-01-26 13:04:23 -05:00
|
|
|
if(config.fs_module.tp_sys_enter_read == ON) ret = attach_tp_sys_enter_read(attr.skel);
|
|
|
|
|
if(config.fs_module.tp_sys_exit_read == ON) ret = attach_tp_sys_exit_read(attr.skel);
|
2022-02-05 13:49:20 -05:00
|
|
|
if(config.fs_module.tp_sys_enter_openat == ON) ret = attach_tp_sys_enter_openat(attr.skel);
|
2022-01-04 20:09:59 -05:00
|
|
|
}
|
|
|
|
|
if(ret!=0) return -1;
|
|
|
|
|
|
2022-02-06 14:15:57 -05:00
|
|
|
//EXEC
|
|
|
|
|
if(config.exec_module.all == ON){
|
|
|
|
|
ret = attach_exec_all(attr.skel);
|
|
|
|
|
}else{
|
|
|
|
|
if(config.exec_module.tp_sys_enter_execve == ON) ret = attach_tp_sys_enter_execve(attr.skel);
|
|
|
|
|
}
|
|
|
|
|
if(ret!=0) return -1;
|
|
|
|
|
|
2022-03-03 05:53:51 -05:00
|
|
|
//INJECTION
|
|
|
|
|
if(config.injection_module.all == ON){
|
|
|
|
|
ret = attach_injection_all(attr.skel);
|
|
|
|
|
}else{
|
|
|
|
|
if(config.injection_module.uprobe_execute_command == ON) ret = attach_uprobe_execute_command(attr.skel);
|
|
|
|
|
}
|
|
|
|
|
if(ret!=0) return -1;
|
2022-01-04 13:26:13 -05:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|