1、指令新增白名单判断,命中白名单后加入到t_whitelist_hit表中,不加到t_command
2、指令新增时,记录到t_command_log表中 3、配置增加创建人、审核人 4、任务停止、结束时,规则的used_task_id也变为空 5、规则update后更新审核状态bug修复
This commit is contained in:
@@ -4,8 +4,10 @@ import com.alibaba.excel.util.ListUtils;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
||||
import com.realtime.protection.configuration.utils.Counter;
|
||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||
import com.realtime.protection.server.whitelist.WhiteListMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -23,12 +25,14 @@ public class CommandService {
|
||||
private final CommandMapper commandMapper;
|
||||
private final SqlSessionWrapper sqlSessionWrapper;
|
||||
private final Counter counter;
|
||||
private final WhiteListMapper whiteListMapper;
|
||||
private static final int BatchSize = 100;
|
||||
|
||||
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter) {
|
||||
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter, WhiteListMapper whiteListMapper) {
|
||||
this.commandMapper = commandMapper;
|
||||
this.sqlSessionWrapper = sqlSessionWrapper;
|
||||
this.counter = counter;
|
||||
this.whiteListMapper = whiteListMapper;
|
||||
}
|
||||
|
||||
@DSTransactional
|
||||
@@ -44,8 +48,21 @@ public class CommandService {
|
||||
+ String.format("%06d", counter.generateId("command"))
|
||||
);
|
||||
|
||||
//指令:白名单检查
|
||||
List<WhiteListObject> whiteListsHit = commandMapper.whiteListCommandCheck(commandInfo.getFiveTupleWithMask());
|
||||
if (!whiteListsHit.isEmpty()) {
|
||||
commandInfo.setUUID(UUID.randomUUID().toString());
|
||||
commandMapper.createCommandInWhiteListHit(commandInfo);
|
||||
commandMapper.createCommandWhiteListConnect(commandInfo.getUUID(), whiteListsHit);
|
||||
//写入历史表
|
||||
insertCommandHistory(commandInfo.getUUID());
|
||||
return commandInfo.getUUID();
|
||||
}
|
||||
|
||||
commandInfo.setUUID(UUID.randomUUID().toString());
|
||||
commandMapper.createCommand(commandInfo);
|
||||
//写入历史表
|
||||
insertCommandHistory(commandInfo.getUUID());
|
||||
return commandInfo.getUUID();
|
||||
}
|
||||
|
||||
@@ -58,13 +75,15 @@ public class CommandService {
|
||||
if (taskCommandInfoBatch.size() < BatchSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//因为createCommands只用于静态规则生成command,静态规则已经检查了白名单,所以不检查了
|
||||
commandMapper.createCommands(taskCommandInfoBatch);
|
||||
insertCommandHistoryBatch(taskCommandInfoBatch);
|
||||
taskCommandInfoBatch.clear();
|
||||
}
|
||||
|
||||
if (!taskCommandInfoBatch.isEmpty()) {
|
||||
commandMapper.createCommands(taskCommandInfoBatch);
|
||||
insertCommandHistoryBatch(taskCommandInfoBatch);
|
||||
taskCommandInfoBatch.clear();
|
||||
}
|
||||
|
||||
@@ -108,4 +127,17 @@ public class CommandService {
|
||||
String destinationIP, String destinationPort){
|
||||
return commandMapper.queryCommandTotalNum(taskId, sourceIP, sourcePort, destinationIP, destinationPort);
|
||||
}
|
||||
|
||||
public void insertCommandHistory(String commandUUID) {
|
||||
commandMapper.updateCommandHistoryExpireTime(commandUUID);
|
||||
commandMapper.insertCommandHistory(commandUUID);
|
||||
}
|
||||
|
||||
public void insertCommandHistoryBatch(List<TaskCommandInfo> commandIdList) {
|
||||
List<String> commandIds = ListUtils.newArrayListWithExpectedSize(commandIdList.size());
|
||||
commandIdList.forEach(item -> commandIds.add(item.getUUID()));
|
||||
|
||||
commandMapper.updateCommandHistoryExpireTimeBatch(commandIds);
|
||||
commandMapper.insertCommandHistoryBatch(commandIds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user