2024-01-17 19:20:45 +08:00
|
|
|
|
package com.realtime.protection.server.alertmessage;
|
|
|
|
|
|
|
2024-01-18 23:35:56 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
|
2024-01-17 19:20:45 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage;
|
2024-01-18 23:35:56 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
2024-01-17 19:20:45 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
2024-01-19 15:45:06 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
|
|
|
|
|
import com.realtime.protection.server.command.CommandService;
|
2024-01-17 19:20:45 +08:00
|
|
|
|
import com.realtime.protection.server.task.TaskService;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class AlertMessageService {
|
|
|
|
|
|
private final CommandService commandService;
|
2024-01-18 23:35:56 +08:00
|
|
|
|
private final AlertMessageMapper alertMessageMapper;
|
2024-01-17 19:20:45 +08:00
|
|
|
|
private final TaskService taskService;
|
|
|
|
|
|
|
2024-01-18 23:35:56 +08:00
|
|
|
|
public AlertMessageService(CommandService commandService,TaskService taskService,
|
|
|
|
|
|
AlertMessageMapper alertMessageMapper) {
|
2024-01-17 19:20:45 +08:00
|
|
|
|
this.commandService = commandService;
|
|
|
|
|
|
this.taskService = taskService;
|
2024-01-18 23:35:56 +08:00
|
|
|
|
this.alertMessageMapper = alertMessageMapper;
|
2024-01-17 19:20:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-18 23:35:56 +08:00
|
|
|
|
public void processAlertMessage(AlertMessage alertMessage) {
|
2024-01-17 19:20:45 +08:00
|
|
|
|
Long taskId = alertMessage.getTaskId();
|
|
|
|
|
|
//检查task status是否为running?
|
2024-01-18 23:35:56 +08:00
|
|
|
|
Integer taskStatus = taskService.queryTaskStatus(taskId);
|
|
|
|
|
|
Integer temp = StateEnum.RUNNING.getStateNum();
|
|
|
|
|
|
// if (taskStatus != StateEnum.RUNNING.getStateNum()) {
|
2024-01-17 19:20:45 +08:00
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2024-01-18 23:35:56 +08:00
|
|
|
|
//查task信息,和alertMessage中的fiveTuple信息 合并成 TaskCommandInfo
|
|
|
|
|
|
TaskCommandInfo dynamicTaskCommandInfo = alertMessageMapper.getDynamicTaskInfos(taskId);
|
2024-01-17 19:20:45 +08:00
|
|
|
|
|
2024-01-18 23:35:56 +08:00
|
|
|
|
//根据策略模板更新五元组
|
|
|
|
|
|
ProtectLevel templateProtectLevel = alertMessageMapper.queryTemplateProtectLevel(
|
|
|
|
|
|
dynamicTaskCommandInfo.getTemplateId(),
|
|
|
|
|
|
dynamicTaskCommandInfo.getProtectLevel(),
|
|
|
|
|
|
alertMessage.getFiveTupleWithMask());
|
|
|
|
|
|
updateFiveTupleWithMask(alertMessage.getFiveTupleWithMask(), templateProtectLevel);
|
|
|
|
|
|
dynamicTaskCommandInfo.setFiveTupleWithMask(alertMessage.getFiveTupleWithMask());
|
2024-01-17 19:20:45 +08:00
|
|
|
|
|
2024-01-18 23:35:56 +08:00
|
|
|
|
// command入库
|
|
|
|
|
|
commandService.createCommand(dynamicTaskCommandInfo);
|
2024-01-17 19:20:45 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-18 23:35:56 +08:00
|
|
|
|
|
|
|
|
|
|
private void updateFiveTupleWithMask(FiveTupleWithMask alertMessageFiveTupleW, ProtectLevel templateProtectLevel) {
|
|
|
|
|
|
if(!templateProtectLevel.getHasProtectObjectIP()){
|
|
|
|
|
|
alertMessageFiveTupleW.setDestinationIP(null);
|
|
|
|
|
|
alertMessageFiveTupleW.setMaskDestinationIP(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!templateProtectLevel.getHasProtectObjectPort()){
|
|
|
|
|
|
alertMessageFiveTupleW.setDestinationPort(null);
|
|
|
|
|
|
alertMessageFiveTupleW.setMaskDestinationPort(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!templateProtectLevel.getHasPeerIP()){
|
|
|
|
|
|
alertMessageFiveTupleW.setSourceIP(null);
|
|
|
|
|
|
alertMessageFiveTupleW.setMaskSourceIP(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!templateProtectLevel.getHasPeerPort()){
|
|
|
|
|
|
alertMessageFiveTupleW.setSourcePort(null);
|
|
|
|
|
|
alertMessageFiveTupleW.setMaskSourcePort(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!templateProtectLevel.getHasProtocol()) {
|
|
|
|
|
|
alertMessageFiveTupleW.setProtocol(null);
|
|
|
|
|
|
alertMessageFiveTupleW.setMaskProtocol(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
//目前告警信息还只是五元组,没有url、dns
|
|
|
|
|
|
}
|
2024-01-17 19:20:45 +08:00
|
|
|
|
}
|