Commit 65837fad by 钱炳权

aflnet日志文件和kitty日志结果文件下载功能完成

parent 2adb74cf
...@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List;
@RestController @RestController
@RequestMapping("/log") @RequestMapping("/log")
...@@ -23,7 +24,7 @@ public class FuzzLogController { ...@@ -23,7 +24,7 @@ public class FuzzLogController {
* 下载对应任务的日志;不同任务返回数据类型不同,需要做个表来区分 * 下载对应任务的日志;不同任务返回数据类型不同,需要做个表来区分
*/ */
@RequestMapping(value = "/download/{missionId}", method = RequestMethod.GET) @RequestMapping(value = "/download/{missionId}", method = RequestMethod.GET)
public FuzzLogTransEntity getFuzzLog(@PathVariable("missionId") int missionId) throws IOException { public List<FuzzLogTransEntity> getFuzzLog(@PathVariable("missionId") int missionId) throws IOException {
try { try {
return FuzzLogService.getFuzzLog(missionId); return FuzzLogService.getFuzzLog(missionId);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -4,7 +4,8 @@ import com.example.fuzzControll.pojo.vo.FuzzLogTransEntity; ...@@ -4,7 +4,8 @@ import com.example.fuzzControll.pojo.vo.FuzzLogTransEntity;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface FuzzLogService { public interface FuzzLogService {
FuzzLogTransEntity getFuzzLog(int missionId) throws IllegalAccessException; List<FuzzLogTransEntity> getFuzzLog(int missionId) throws IllegalAccessException;
} }
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.exception.MysqlException;
import com.example.fuzzControll.mapper.AflnetMapper; import com.example.fuzzControll.mapper.AflnetMapper;
import com.example.fuzzControll.mapper.KittyMapper; import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.mapper.MissionInfoMapper; import com.example.fuzzControll.mapper.MissionInfoMapper;
import com.example.fuzzControll.pojo.vo.AflnetResult; import com.example.fuzzControll.pojo.vo.*;
import com.example.fuzzControll.pojo.vo.FuzzLogTransEntity;
import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.pojo.vo.MissionInfo;
import com.example.fuzzControll.service.FuzzLogService; import com.example.fuzzControll.service.FuzzLogService;
import com.example.fuzzControll.tools.FileTools; import com.example.fuzzControll.tools.FileTools;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
@Slf4j @Slf4j
@Service("FuzzLogService") @Service("FuzzLogService")
...@@ -28,7 +29,7 @@ public class FuzzLogServiceImpl implements FuzzLogService { ...@@ -28,7 +29,7 @@ public class FuzzLogServiceImpl implements FuzzLogService {
FileTools fileTools = new FileTools(); FileTools fileTools = new FileTools();
@Override @Override
public FuzzLogTransEntity getFuzzLog(int missionId) throws IllegalAccessException { public List<FuzzLogTransEntity> getFuzzLog(int missionId) throws IllegalAccessException {
MissionInfo missionInfo = missionInfoMapper.selectByMissionId(missionId); MissionInfo missionInfo = missionInfoMapper.selectByMissionId(missionId);
if (missionInfo == null) { if (missionInfo == null) {
return null; return null;
...@@ -36,7 +37,8 @@ public class FuzzLogServiceImpl implements FuzzLogService { ...@@ -36,7 +37,8 @@ public class FuzzLogServiceImpl implements FuzzLogService {
switch (missionInfo.getTableId()) { switch (missionInfo.getTableId()) {
case 1: case 1:
return downloadAflnetFile(missionInfo); return downloadAflnetFile(missionInfo);
// case 2:return downloadKittyProtocalFile(missionInfo); case 2:
return downloadKittyProtocalFile(missionInfo);
case 3: case 3:
return downloadKittyOtherMethodFile(missionInfo); return downloadKittyOtherMethodFile(missionInfo);
default: default:
...@@ -44,15 +46,41 @@ public class FuzzLogServiceImpl implements FuzzLogService { ...@@ -44,15 +46,41 @@ public class FuzzLogServiceImpl implements FuzzLogService {
} }
} }
private FuzzLogTransEntity downloadKittyOtherMethodFile(MissionInfo missionInfo) { @Transactional(rollbackFor = MysqlException.class)
public List<FuzzLogTransEntity> downloadKittyProtocalFile(MissionInfo missionInfo) {
/*获取结果日志*/
List<FuzzLogTransEntity> fuzzLogList = new ArrayList<FuzzLogTransEntity>();
KittyResult kittyResult = kittyMapper.getKittyResultByMissionId(missionInfo.getMissionId()); KittyResult kittyResult = kittyMapper.getKittyResultByMissionId(missionInfo.getMissionId());
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append(kittyResult.getResultError()).append(System.lineSeparator()).append(kittyResult.getResultOut()); buffer.append(kittyResult.getResultError()).append(System.lineSeparator()).append(kittyResult.getResultOut());
return new FuzzLogTransEntity(buffer.toString().getBytes(), missionInfo.getMissionName()+".txt"); FuzzLogTransEntity fuzzLogTransEntity = new FuzzLogTransEntity(buffer.toString().getBytes(), missionInfo.getMissionName() + ".txt");
fuzzLogList.add(fuzzLogTransEntity);
/*获取数据包文件*/
// KittyPackageFile kittyPackageFile = kittyMapper.getKittyPackageFileById(missionInfo.getMissionId());
// FuzzLogTransEntity fuzzLogTransEntitySend = new FuzzLogTransEntity(kittyPackageFile.getKittySendFile(), kittyPackageFile.getKittyRecvFileName());
// FuzzLogTransEntity fuzzLogTransEntityRecv = new FuzzLogTransEntity(kittyPackageFile.getKittyRecvFile(), kittyPackageFile.getKittyRecvFileName());
// fuzzLogList.add(fuzzLogTransEntitySend);
// fuzzLogList.add(fuzzLogTransEntityRecv);
return fuzzLogList;
} }
private FuzzLogTransEntity downloadAflnetFile(MissionInfo missionInfo) { @Transactional(rollbackFor = MysqlException.class)
public List<FuzzLogTransEntity> downloadKittyOtherMethodFile(MissionInfo missionInfo) {
List<FuzzLogTransEntity> fuzzLogList = new ArrayList<FuzzLogTransEntity>();
KittyResult kittyResult = kittyMapper.getKittyResultByMissionId(missionInfo.getMissionId());
StringBuffer buffer = new StringBuffer();
buffer.append(kittyResult.getResultError()).append(System.lineSeparator()).append(kittyResult.getResultOut());
FuzzLogTransEntity fuzzLogTransEntity = new FuzzLogTransEntity(buffer.toString().getBytes(), missionInfo.getMissionName() + ".txt");
fuzzLogList.add(fuzzLogTransEntity);
return fuzzLogList;
}
@Transactional(rollbackFor = MysqlException.class)
public List<FuzzLogTransEntity> downloadAflnetFile(MissionInfo missionInfo) {
List<FuzzLogTransEntity> fuzzLogList = new ArrayList<FuzzLogTransEntity>();
AflnetResult aflnetResult = aflnetMapper.selectResultById(missionInfo.getMissionId()); AflnetResult aflnetResult = aflnetMapper.selectResultById(missionInfo.getMissionId());
return new FuzzLogTransEntity(aflnetResult.getFile(), aflnetResult.getFileName()); FuzzLogTransEntity fuzzLogTransEntity = new FuzzLogTransEntity(aflnetResult.getFile(), aflnetResult.getFileName());
fuzzLogList.add(fuzzLogTransEntity);
return fuzzLogList;
} }
} }
...@@ -39,14 +39,25 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ ...@@ -39,14 +39,25 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
log.error("kittyLogs backup failed!"); log.error("kittyLogs backup failed!");
} }
System.out.println("1"); System.out.println("1");
List<String> logFiles = files.stream().filter(file -> file.contains("pcap")).collect(Collectors.toList()); List<String> logFiles = null;
try {
logFiles = files.stream().filter(file -> file.contains("pcap")).collect(Collectors.toList());
} catch (Exception e) {
log.error("There is no file!");
e.printStackTrace();
}
System.out.println("2");
logFiles.forEach(System.out::println); logFiles.forEach(System.out::println);
System.out.println("3");
//todo 需要传入任务id //todo 需要传入任务id
KittyPackageFile kittyPackageFile = new KittyPackageFile(1, logFiles.get(0), logFiles.get(1), KittyPackageFile kittyPackageFile = new KittyPackageFile(missionId, "", "",
fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(0)), new byte[1],
fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(1))); new byte[1]);
// KittyPackageFile kittyPackageFile = new KittyPackageFile(missionId, logFiles.get(0), logFiles.get(1),
// fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(0)),
// fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(1)));
System.out.println(kittyPackageFile); System.out.println(kittyPackageFile);
System.out.println("2"); System.out.println("4");
return kittyMapper.kittyPackagesBackup(kittyPackageFile); return kittyMapper.kittyPackagesBackup(kittyPackageFile);
} }
...@@ -65,7 +76,7 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ ...@@ -65,7 +76,7 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
e.printStackTrace(); e.printStackTrace();
throw new MysqlException("KittyMapper.getKittyPackageFileById Error!"); throw new MysqlException("KittyMapper.getKittyPackageFileById Error!");
} }
fileTools.loadFileInLocal(kittyDataParams.getFilPath(), kittyPackageFile.getKittyRecvFileName(),kittyPackageFile.getKittyRecvFile()); fileTools.loadFileInLocal(kittyDataParams.getFilPath(), kittyPackageFile.getKittyRecvFileName(), kittyPackageFile.getKittyRecvFile());
fileTools.loadFileInLocal(kittyDataParams.getFilPath(), kittyPackageFile.getKittySendFileName(),kittyPackageFile.getKittySendFile()); fileTools.loadFileInLocal(kittyDataParams.getFilPath(), kittyPackageFile.getKittySendFileName(), kittyPackageFile.getKittySendFile());
} }
} }
...@@ -313,7 +313,7 @@ public class CmdTools { ...@@ -313,7 +313,7 @@ public class CmdTools {
} }
/*kitty的协议模板方法的日志和数据包文件存入数据库*/ /*kitty的协议模板方法的日志和数据包文件存入数据库*/
if (caller.equals("protocolTemplate")) { if (caller.equals("protocolTemplate")) {
GlobalParameters.kittyFuzzPersistenceService.KittyPackagesBackup(missionId); // GlobalParameters.kittyFuzzPersistenceService.KittyPackagesBackup(missionId);
GlobalParameters.missionInfoMapper.insertMission(new MissionInfo(missionId, 2, new Date(), missionName)); GlobalParameters.missionInfoMapper.insertMission(new MissionInfo(missionId, 2, new Date(), missionName));
} else { } else {
/*存入missionInfo信息*/ /*存入missionInfo信息*/
......
...@@ -76,7 +76,7 @@ public interface FuzzIntegrationFileApi { ...@@ -76,7 +76,7 @@ public interface FuzzIntegrationFileApi {
void disconnect(); void disconnect();
@RequestMapping(value = "/log/download/{missionId}", method = RequestMethod.GET) @RequestMapping(value = "/log/download/{missionId}", method = RequestMethod.GET)
FuzzLogTransEntity getFuzzLog(@PathVariable("missionId") int missionId); List<FuzzLogTransEntity> getFuzzLog(@PathVariable("missionId") int missionId);
/** /**
* 查询任务信息 * 查询任务信息
......
...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; ...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.List;
@Service("FuzzLogService") @Service("FuzzLogService")
public class FuzzLogServiceImpl implements FuzzLogService { public class FuzzLogServiceImpl implements FuzzLogService {
...@@ -16,11 +17,16 @@ public class FuzzLogServiceImpl implements FuzzLogService { ...@@ -16,11 +17,16 @@ public class FuzzLogServiceImpl implements FuzzLogService {
@Override @Override
public void getFuzzLog(int missionId, HttpServletResponse response) throws IllegalAccessException { public void getFuzzLog(int missionId, HttpServletResponse response) throws IllegalAccessException {
FuzzLogTransEntity fuzzLogTransEntity = fuzzIntegrationFileApi.getFuzzLog(missionId); List<FuzzLogTransEntity> fuzzLogTransEntityList = fuzzIntegrationFileApi.getFuzzLog(missionId);
if (fuzzLogTransEntity == null && fuzzLogTransEntity.getFile() == null) { if(fuzzLogTransEntityList.size()==0){
throw new IllegalStateException(); throw new IllegalStateException();
} }
downloadFile(fuzzLogTransEntity.getName(), fuzzLogTransEntity.getFile(), response); for(FuzzLogTransEntity fuzzLogTransEntity:fuzzLogTransEntityList){
if (fuzzLogTransEntity == null && fuzzLogTransEntity.getFile() == null) {
throw new IllegalStateException();
}
downloadFile(fuzzLogTransEntity.getName(), fuzzLogTransEntity.getFile(), response);
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment