Commit 7b43576c by 钱炳权

kitty数据报文件存入数据库成功

parent 918202f5
...@@ -6,6 +6,7 @@ import org.springframework.stereotype.Component; ...@@ -6,6 +6,7 @@ import org.springframework.stereotype.Component;
@Component("kittyProperties") @Component("kittyProperties")
@ConfigurationProperties(prefix = "kitty") @ConfigurationProperties(prefix = "kitty")
public class KittyProperties { public class KittyProperties {
String logOutPath;
String path; String path;
String venvPath; String venvPath;
String methodPath; String methodPath;
...@@ -16,8 +17,13 @@ public class KittyProperties { ...@@ -16,8 +17,13 @@ public class KittyProperties {
String reportHttp; String reportHttp;
String mutationPath; String mutationPath;
public String getLogOutPath() {
return logOutPath;
}
public void setLogOutPath(String logOutPath) {
this.logOutPath = logOutPath;
}
public String getMutationPath() { public String getMutationPath() {
return mutationPath; return mutationPath;
......
...@@ -39,8 +39,8 @@ public class KittyController { ...@@ -39,8 +39,8 @@ public class KittyController {
*/ */
@RequestMapping(value = "/protocolTemplate", method = RequestMethod.POST) @RequestMapping(value = "/protocolTemplate", method = RequestMethod.POST)
public AjaxResult protocolTemplate(@RequestBody TestEntity testEntity) { public AjaxResult protocolTemplate(@RequestBody TestEntity testEntity) {
try { try {//todo missionId
Map<String, List<String>> result = protocolTemplateService.generation(testEntity); Map<String, List<String>> result = protocolTemplateService.generation(testEntity,1);
return AjaxResult.success(result == null ? "模板文件生成未成功运行!第三方接口可能存在问题。" : result); return AjaxResult.success(result == null ? "模板文件生成未成功运行!第三方接口可能存在问题。" : result);
} catch (CmdException | FuzzException e) { } catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage()); log.error(e.getDefaultMessage());
...@@ -54,7 +54,8 @@ public class KittyController { ...@@ -54,7 +54,8 @@ public class KittyController {
@RequestMapping(value = "/generate", method = RequestMethod.POST) @RequestMapping(value = "/generate", method = RequestMethod.POST)
public AjaxResult generate(@RequestBody TestEntity testEntity) { public AjaxResult generate(@RequestBody TestEntity testEntity) {
try { try {
Map<String, List<String>> result = generateMethodService.generation(testEntity); //todo 需要传入missionId
Map<String, List<String>> result = generateMethodService.generation(testEntity,1);
return AjaxResult.success(result == null ? "生成方法未成功运行!第三方接口可能存在问题。" : result); return AjaxResult.success(result == null ? "生成方法未成功运行!第三方接口可能存在问题。" : result);
} catch (CmdException | FuzzException e) { } catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage()); log.error(e.getDefaultMessage());
...@@ -68,7 +69,7 @@ public class KittyController { ...@@ -68,7 +69,7 @@ public class KittyController {
@RequestMapping(value = "/mutation", method = RequestMethod.POST) @RequestMapping(value = "/mutation", method = RequestMethod.POST)
public AjaxResult mutation(@RequestBody TestEntity testEntity) { public AjaxResult mutation(@RequestBody TestEntity testEntity) {
try { try {
Map<String, List<String>> result = mutationService.generation(testEntity); Map<String, List<String>> result = mutationService.generation(testEntity,1);
return AjaxResult.success(result == null ? "mutationTest未成功运行!第三方接口可能存在问题。" : result); return AjaxResult.success(result == null ? "mutationTest未成功运行!第三方接口可能存在问题。" : result);
} catch (CmdException | FuzzException e) { } catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage()); log.error(e.getDefaultMessage());
...@@ -82,7 +83,7 @@ public class KittyController { ...@@ -82,7 +83,7 @@ public class KittyController {
@RequestMapping(value = "/vulnerabilityType", method = RequestMethod.POST) @RequestMapping(value = "/vulnerabilityType", method = RequestMethod.POST)
public AjaxResult vulnerability(@RequestBody TestEntity testEntity) { public AjaxResult vulnerability(@RequestBody TestEntity testEntity) {
try { try {
Map<String, List<String>> result = vulnerabilityTypeService.generation(testEntity); Map<String, List<String>> result = vulnerabilityTypeService.generation(testEntity,1);
return AjaxResult.success(result == null ? "漏洞类型未成功运行!第三方接口可能存在问题。" : result); return AjaxResult.success(result == null ? "漏洞类型未成功运行!第三方接口可能存在问题。" : result);
} catch (CmdException | FuzzException e) { } catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage()); log.error(e.getDefaultMessage());
......
package com.example.fuzzControll.controller.dataController; package com.example.fuzzControll.controller.dataController;
import com.example.fuzzControll.pojo.vo.AjaxResult; import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.KittyDataParams;
import com.example.fuzzControll.pojo.vo.KittyResult; import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.KittyFuzzPersistenceService; import com.example.fuzzControll.service.KittyFuzzPersistenceService;
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.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -17,11 +19,12 @@ import java.util.List; ...@@ -17,11 +19,12 @@ import java.util.List;
public class KittyDataController { public class KittyDataController {
@Autowired @Autowired
KittyFuzzPersistenceService fuzzPersistenceService; KittyFuzzPersistenceService fuzzPersistenceService;
/** /**
* 查询kitty结果 * 查询kitty结果
*/ */
@RequestMapping(value = "/KittyResultSelect", method = RequestMethod.GET) @RequestMapping(value = "/KittyResultSelect", method = RequestMethod.GET)
public AjaxResult KittyResultSelect( ){ public AjaxResult KittyResultSelect() {
List<KittyResult> results; List<KittyResult> results;
try { try {
results = fuzzPersistenceService.getKittyResults(); results = fuzzPersistenceService.getKittyResults();
...@@ -31,4 +34,18 @@ public class KittyDataController { ...@@ -31,4 +34,18 @@ public class KittyDataController {
} }
return AjaxResult.success(results); return AjaxResult.success(results);
} }
/**
* 查询kittyPackage
*/
@RequestMapping(value = "/kittyPackageFileLoad", method = RequestMethod.POST)
public AjaxResult kittyPackageFileLoad(@RequestBody KittyDataParams kittyDataParams) {
try {
fuzzPersistenceService.loadKittyLogFileInLocal(kittyDataParams);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error();
}
return AjaxResult.success("load success!");
}
} }
package com.example.fuzzControll.mapper; package com.example.fuzzControll.mapper;
import com.example.fuzzControll.pojo.vo.KittyLog;
import com.example.fuzzControll.pojo.vo.KittyResult; import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.pojo.vo.KittyPackageFile;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -16,7 +16,11 @@ public interface KittyMapper { ...@@ -16,7 +16,11 @@ public interface KittyMapper {
*/ */
List<KittyResult> getKittyResults(); List<KittyResult> getKittyResults();
void kittyResultsBackup(KittyResult kittyResult); int kittyResultsBackup(KittyResult kittyResult);
int kittyPackagesBackup(KittyPackageFile kittyPackageFile);
KittyPackageFile getKittyPackageFileById(int missionId);
/** /**
......
package com.example.fuzzControll.pojo.vo;
import lombok.Data;
@Data
public class KittyDataParams {
private String filPath;
private int missionId;
public KittyDataParams() {
}
public KittyDataParams(String filPath, int missionId) {
this.filPath = filPath;
this.missionId = missionId;
}
}
package com.example.fuzzControll.pojo.vo;
import lombok.Data;
@Data
public class KittyPackageFile {
private int id;
private int missionId;
private String kittyRecvFileName;
private String kittySendFileName;
private byte[] kittyRecvFile;
private byte[] kittySendFile;
public KittyPackageFile(int missionId, String kittyRecvFileName, String kittySendFileName, byte[] kittyRecvFile, byte[] kittySendFile) {
this.missionId = missionId;
this.kittyRecvFileName = kittyRecvFileName;
this.kittySendFileName = kittySendFileName;
this.kittyRecvFile = kittyRecvFile;
this.kittySendFile = kittySendFile;
}
@Override
public String toString() {
return "kittyPackageFile{" +
"id=" + id +
", missionId=" + missionId +
", kittyRecvFileName='" + kittyRecvFileName + '\'' +
", kittySendFileName='" + kittySendFileName + '\'' +
", kittyRecvFile=" + kittyRecvFile.length +
", kittySendFile=" +kittySendFile.length +
'}';
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getMissionId() {
return missionId;
}
public void setMissionId(int missionId) {
this.missionId = missionId;
}
public String getKittyRecvFileName() {
return kittyRecvFileName;
}
public void setKittyRecvFileName(String kittyRecvFileName) {
this.kittyRecvFileName = kittyRecvFileName;
}
public String getKittySendFileName() {
return kittySendFileName;
}
public void setKittySendFileName(String kittySendFileName) {
this.kittySendFileName = kittySendFileName;
}
public byte[] getKittyRecvFile() {
return kittyRecvFile;
}
public void setKittyRecvFile(byte[] kittyRecvFile) {
this.kittyRecvFile = kittyRecvFile;
}
public byte[] getKittySendFile() {
return kittySendFile;
}
public void setKittySendFile(byte[] kittySendFile) {
this.kittySendFile = kittySendFile;
}
}
...@@ -6,5 +6,5 @@ import java.util.List; ...@@ -6,5 +6,5 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public interface GenerateMethodService { public interface GenerateMethodService {
Map<String,List<String>> generation(TestEntity testEntity); Map<String,List<String>> generation(TestEntity testEntity,int missionId);
} }
package com.example.fuzzControll.service; package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.KittyDataParams;
import com.example.fuzzControll.pojo.vo.KittyResult; import com.example.fuzzControll.pojo.vo.KittyResult;
import java.util.List; import java.util.List;
public interface KittyFuzzPersistenceService { public interface KittyFuzzPersistenceService {
List<KittyResult> getKittyResults(); List<KittyResult> getKittyResults();
// void loadInFile(int missionId); public int KittyPackagesBackup(int missionId);
public int kittyResultsBackup(KittyResult kittyResult);
void loadKittyLogFileInLocal(KittyDataParams kittyDataParams);
} }
...@@ -6,5 +6,5 @@ import java.util.List; ...@@ -6,5 +6,5 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public interface MutationService { public interface MutationService {
Map<String, List<String>> generation(TestEntity testEntity); Map<String, List<String>> generation(TestEntity testEntity,int missionId);
} }
...@@ -6,6 +6,6 @@ import java.util.List; ...@@ -6,6 +6,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public interface ProtocolTemplateService { public interface ProtocolTemplateService {
Map<String,List<String>> generation(TestEntity testEntity); Map<String,List<String>> generation(TestEntity testEntity,int missionId);
} }
...@@ -6,5 +6,5 @@ import java.util.List; ...@@ -6,5 +6,5 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public interface VulnerabilityTypeService { public interface VulnerabilityTypeService {
Map<String, List<String>> generation(TestEntity testEntity); Map<String, List<String>> generation(TestEntity testEntity,int missionId);
} }
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.exception.MysqlException; import com.example.fuzzControll.exception.MysqlException;
import com.example.fuzzControll.mapper.AflnetMapper; import com.example.fuzzControll.mapper.AflnetMapper;
import com.example.fuzzControll.pojo.vo.AflnetResult; import com.example.fuzzControll.pojo.vo.AflnetResult;
...@@ -14,26 +15,28 @@ import org.springframework.stereotype.Service; ...@@ -14,26 +15,28 @@ import org.springframework.stereotype.Service;
@Service("AflnetPersistenceService") @Service("AflnetPersistenceService")
public class AflnetPersistenceServiceImpl implements AflnetPersistenceService { public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
@Autowired @Autowired
AflnetMapper AflnetMapper; AflnetMapper aflnetMapper;
@Autowired
AflnetProperties aflnetProperties;
FileTools fileTools = new FileTools(); FileTools fileTools = new FileTools();
@Override @Override
public int aflnetResultBackup(String filename) { public int aflnetResultBackup(String filename) {
//todo 需要传入任务id //todo 需要传入任务id
AflnetResult result = new AflnetResult(1, fileTools.fileReadAndBackup(filename), filename); AflnetResult result = new AflnetResult(1, fileTools.fileReadAndTranstoBytes(aflnetProperties.getOutputPath(),filename), filename);
return AflnetMapper.aflnetOutputBackup(result); return aflnetMapper.aflnetOutputBackup(result);
} }
@Override @Override
public void loadInFile(int missionId, String filePath) { public void loadInFile(int missionId, String filePath) {
AflnetResult aflnetResult = null; AflnetResult aflnetResult = null;
try { try {
aflnetResult = AflnetMapper.selectResultById(missionId); aflnetResult = aflnetMapper.selectResultById(missionId);
} catch (MysqlException e) { } catch (MysqlException e) {
e.printStackTrace(); e.printStackTrace();
throw new MysqlException("AflnetMapper.selectResultById() Error!"); throw new MysqlException("AflnetMapper.selectResultById() Error!");
} }
fileTools.loadFileInLocal(aflnetResult, filePath); fileTools.loadFileInLocal(filePath, aflnetResult.getFileName(),aflnetResult.getFile());
} }
} }
...@@ -22,12 +22,12 @@ public class GenerateMethodServiceImpl implements GenerateMethodService { ...@@ -22,12 +22,12 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
KittyProperties kitty; KittyProperties kitty;
@Override @Override
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity,int missionId) throws FuzzException, CmdException {
String cmd = parseParameters(testEntity); String cmd = parseParameters(testEntity);
if (cmd.isEmpty()) { if (cmd.isEmpty()) {
throw new FuzzException("cmd is null ! The number of parameters does not match!"); throw new FuzzException("cmd is null ! The number of parameters does not match!");
} }
return cmdTools.runProgramCmdAndResult(cmd); return cmdTools.runProgramCmdAndResult(cmd,"generate",missionId);
} }
public String parseParameters(TestEntity testEntity) { public String parseParameters(TestEntity testEntity) {
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.constents.CmdConstent;
import com.example.fuzzControll.exception.MysqlException;
import com.example.fuzzControll.mapper.KittyMapper; import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.pojo.vo.KittyDataParams;
import com.example.fuzzControll.pojo.vo.KittyResult; import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.AflnetPersistenceService; import com.example.fuzzControll.pojo.vo.KittyPackageFile;
import com.example.fuzzControll.service.KittyFuzzPersistenceService; import com.example.fuzzControll.service.KittyFuzzPersistenceService;
import com.example.fuzzControll.tools.CmdTools;
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 java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service("KittyFuzzPersistenceService")
@Slf4j @Slf4j
public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceService { public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceService {
@Autowired @Autowired
KittyMapper kittyMapper; KittyMapper kittyMapper;
FileTools fileTools = new FileTools();
CmdTools cmdTools = new CmdTools();
@Autowired @Autowired
AflnetPersistenceService aflnetPersistenceService; KittyProperties kittyProperties;
@Override @Override
public List<KittyResult> getKittyResults() { public List<KittyResult> getKittyResults() {
return kittyMapper.getKittyResults(); return kittyMapper.getKittyResults();
} }
@Override
public int KittyPackagesBackup(int missionId) {
List<String> files = cmdTools.runCmd(CmdConstent.GET_FILE_NAME + kittyProperties.getLogOutPath(), "getKittyLogFiles");
if (files.size() > 3) {
log.error("kittyLogs backup failed!");
}
System.out.println("1");
List<String> logFiles = files.stream().filter(file -> file.contains("pcap")).collect(Collectors.toList());
logFiles.forEach(System.out::println);
//todo 需要传入任务id
KittyPackageFile kittyPackageFile = new KittyPackageFile(1, 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("2");
return kittyMapper.kittyPackagesBackup(kittyPackageFile);
}
@Override
public int kittyResultsBackup(KittyResult kittyResult) {
return kittyMapper.kittyResultsBackup(kittyResult);
}
@Override
public void loadKittyLogFileInLocal(KittyDataParams kittyDataParams) {
KittyPackageFile kittyPackageFile = null;
try {
kittyPackageFile = kittyMapper.getKittyPackageFileById(kittyDataParams.getMissionId());
} catch (MysqlException e) {
e.printStackTrace();
throw new MysqlException("KittyMapper.getKittyPackageFileById Error!");
}
fileTools.loadFileInLocal(kittyDataParams.getFilPath(), kittyPackageFile.getKittyRecvFileName(),kittyPackageFile.getKittyRecvFile());
fileTools.loadFileInLocal(kittyDataParams.getFilPath(), kittyPackageFile.getKittySendFileName(),kittyPackageFile.getKittySendFile());
}
} }
...@@ -24,12 +24,12 @@ class MutationServiceImpl implements MutationService { ...@@ -24,12 +24,12 @@ class MutationServiceImpl implements MutationService {
@Override @Override
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity,int missionId) throws FuzzException, CmdException {
String cmd = parseParameters(testEntity); String cmd = parseParameters(testEntity);
if (cmd.isEmpty()) { if (cmd.isEmpty()) {
throw new FuzzException("cmd is null ! The number of parameters does not match!"); throw new FuzzException("cmd is null ! The number of parameters does not match!");
} }
return cmdTools.runProgramCmdAndResult(cmd); return cmdTools.runProgramCmdAndResult(cmd,"mutation",missionId);
} }
public String parseParameters(TestEntity testEntity) { public String parseParameters(TestEntity testEntity) {
......
...@@ -2,12 +2,14 @@ package com.example.fuzzControll.service.impl; ...@@ -2,12 +2,14 @@ package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.KittyProperties; import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.constents.CmdConstent;
import com.example.fuzzControll.constents.ProtocolConstent; import com.example.fuzzControll.constents.ProtocolConstent;
import com.example.fuzzControll.exception.CmdException; import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.exception.FuzzException; import com.example.fuzzControll.exception.FuzzException;
import com.example.fuzzControll.pojo.vo.TestEntity; import com.example.fuzzControll.pojo.vo.TestEntity;
import com.example.fuzzControll.service.ProtocolTemplateService; import com.example.fuzzControll.service.ProtocolTemplateService;
import com.example.fuzzControll.tools.CmdTools; import com.example.fuzzControll.tools.CmdTools;
import com.example.fuzzControll.tools.GlobalParameters;
import com.example.fuzzControll.tools.TestTools; import com.example.fuzzControll.tools.TestTools;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,12 +26,14 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService { ...@@ -24,12 +26,14 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
KittyProperties kitty; KittyProperties kitty;
@Override @Override
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity,int missionId) throws FuzzException, CmdException {
/*生成日志前先清除日志*/
// cmdTools.runCmd(CmdConstent.DELETE_FILE + GlobalParameters.kittyProperties.getLogOutPath(),"delete kittyLogs");
String cmd = parseParameters(testEntity); String cmd = parseParameters(testEntity);
if (cmd == null || cmd.equals("")) { if (cmd == null || cmd.equals("")) {
throw new FuzzException("cmd is null ! The number of parameters does not match!"); throw new FuzzException("cmd is null ! The number of parameters does not match!");
} }
return cmdTools.runProgramCmdAndResult(cmd); return cmdTools.runProgramCmdAndResult(cmd,"protocolTemplate",missionId);
} }
public String parseParameters(TestEntity testEntity) throws FuzzException { public String parseParameters(TestEntity testEntity) throws FuzzException {
......
...@@ -21,12 +21,12 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService { ...@@ -21,12 +21,12 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
KittyProperties kitty; KittyProperties kitty;
@Override @Override
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity,int missionId) throws FuzzException, CmdException {
String cmd = parseParameters(testEntity); String cmd = parseParameters(testEntity);
if (cmd.isEmpty()) { if (cmd.isEmpty()) {
throw new FuzzException("cmd is null ! The number of parameters does not match!"); throw new FuzzException("cmd is null ! The number of parameters does not match!");
} }
return cmdTools.runProgramCmdAndResult(cmd); return cmdTools.runProgramCmdAndResult(cmd,"vulnerability",missionId);
} }
public String parseParameters(TestEntity testEntity) { public String parseParameters(TestEntity testEntity) {
......
...@@ -50,7 +50,7 @@ public class CmdTools { ...@@ -50,7 +50,7 @@ public class CmdTools {
* 运行需要后台运行cmd * 运行需要后台运行cmd
* 通过websocket返回数据 * 通过websocket返回数据
*/ */
public void runProgramCmd(String cmd,String outputFileName) throws AflnetException { public void runProgramCmd(String cmd, String outputFileName) throws AflnetException {
try { try {
Process process = Runtime.getRuntime().exec(cmd); Process process = Runtime.getRuntime().exec(cmd);
printMessageToWeb(process.getInputStream()); printMessageToWeb(process.getInputStream());
...@@ -67,31 +67,42 @@ public class CmdTools { ...@@ -67,31 +67,42 @@ public class CmdTools {
* 运行需要后台运行cmd * 运行需要后台运行cmd
* 将数据存入文件中 * 将数据存入文件中
*/ */
public Map<String, List<String>> runProgramCmdAndResult(String cmd) throws CmdException { public Map<String, List<String>> runProgramCmdAndResult(String cmd, String caller, int missionId) throws CmdException {
Map<String, List<String>> result = new HashMap(); Map<String, List<String>> result = new HashMap();
List<String> out = Collections.synchronizedList(new ArrayList<String>()); List<String> out = Collections.synchronizedList(new ArrayList<String>());
List<String> error = Collections.synchronizedList(new ArrayList<String>()); List<String> error = Collections.synchronizedList(new ArrayList<String>());
try { try {
Process process = Runtime.getRuntime().exec(cmd); // Process process = Runtime.getRuntime().exec(cmd);
printMessageByProgramCmd(process.getInputStream(), out); // printMessageByProgramCmd(process.getInputStream(), out);
printMessageByProgramCmd(process.getErrorStream(), error); // printMessageByProgramCmd(process.getErrorStream(), error);
process.waitFor(); // process.waitFor();
//todo 对于无法运行和数据较长的还需要观察
try {
KittyResult kittyResult = new KittyResult(1, out.toString(), error.toString());
GlobalParameters.kittyMapper.kittyResultsBackup(kittyResult);
} catch (Exception e) {
e.printStackTrace();
log.error("kitty backup error!");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new CmdException("run fuzz error !"); throw new CmdException("run fuzz error !");
} }
result.put("out", out); result.put("out", out);
result.put("error", error); result.put("error", error);
//todo 需要传入任务参数,后期再开发 //todo 对于无法运行和数据较长的还需要观察
/*新开一个线程存入数据*/
new Thread(new Runnable() {
@Override
public void run() {
try {
/*kitty结果存入数据库*/
KittyResult kittyResult = new KittyResult(missionId, out.toString(), error.toString());
GlobalParameters.kittyMapper.kittyResultsBackup(kittyResult);
} catch (Exception e) {
e.printStackTrace();
log.error("kitty backup error!");
}
/*kitty的协议模板方法的日志和数据包文件存入数据库*/
if (caller.equals("protocolTemplate")) {
GlobalParameters.kittyFuzzPersistenceService.KittyPackagesBackup(missionId);
}
}
}).start();
//todo 需要传入任务参数,后期再开发
return result; return result;
} }
......
...@@ -3,7 +3,6 @@ package com.example.fuzzControll.tools; ...@@ -3,7 +3,6 @@ package com.example.fuzzControll.tools;
import com.example.fuzzControll.conf.AflnetProperties; import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.conf.SpringContextUtil; import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.exception.FileException; import com.example.fuzzControll.exception.FileException;
import com.example.fuzzControll.pojo.vo.AflnetResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -39,35 +38,37 @@ public class FileTools { ...@@ -39,35 +38,37 @@ public class FileTools {
* @param filename * @param filename
* @return * @return
*/ */
public byte[] fileReadAndBackup(String filename) { public byte[] fileReadAndTranstoBytes(String path, String filename) {
File file = new File(properties.getOutputPath() + "/" + filename); File file = new File(path + filename);
byte[] buffer = new byte[(int) file.length()];
try ( try (
FileInputStream inputStream = new FileInputStream(file); FileInputStream inputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);) { BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);) {
if (file.length() > Integer.MAX_VALUE) {
throw new IOException(); System.out.println("1-2");
if (file.length() > Integer.MAX_VALUE && file.length() <= 0) {
log.error("KittyLogFile is too long or has no content!");
} }
byte[] buffer = new byte[(int) file.length()]; System.out.println("1-3");
int bytesRead; int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) { while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
bufferedInputStream.read(buffer, 0, bytesRead); System.out.println(buffer.length);
} }
return buffer; System.out.println("1-5");
} catch (FileNotFoundException e) { } catch (Exception e) {
throw new RuntimeException(e); e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException("File is to large " + file.getName());
} }
return buffer;
} }
/** /**
* 读取数据库文件至本地 * 读取数据库文件至本地
*/ */
public void loadFileInLocal(AflnetResult aflnetResult, String fileLoadPath) { public void loadFileInLocal(String fileLoadPath, String fileName, byte[] fileBytes) {
File file = new File(fileLoadPath+"/"+aflnetResult.getFileName()); File file = new File(fileLoadPath + "/" + fileName);
try (FileOutputStream fileOutputStream = new FileOutputStream(file); try (FileOutputStream fileOutputStream = new FileOutputStream(file);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(aflnetResult.getFile()); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
BufferedInputStream bufferedInputStream = new BufferedInputStream(byteArrayInputStream);) { BufferedInputStream bufferedInputStream = new BufferedInputStream(byteArrayInputStream);) {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int bytesRead; int bytesRead;
...@@ -75,7 +76,7 @@ public class FileTools { ...@@ -75,7 +76,7 @@ public class FileTools {
bufferedOutputStream.write(buffer, 0, bytesRead); bufferedOutputStream.write(buffer, 0, bytesRead);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new FileException("Cannot find path:" + fileLoadPath+"! Maybe there is no permission for this file!"); throw new FileException("Cannot find path:" + fileLoadPath + "! Maybe there is no permission for this file!");
} catch (IOException e) { } catch (IOException e) {
throw new FileException("Load file failed!"); throw new FileException("Load file failed!");
} }
......
...@@ -5,6 +5,7 @@ import com.example.fuzzControll.conf.KittyProperties; ...@@ -5,6 +5,7 @@ import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.conf.SpringContextUtil; import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.mapper.KittyMapper; import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.service.AflnetPersistenceService; import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.service.KittyFuzzPersistenceService;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -12,6 +13,7 @@ public class GlobalParameters { ...@@ -12,6 +13,7 @@ public class GlobalParameters {
public static ConcurrentHashMap<String, String> aflnetData = new ConcurrentHashMap<>();//当前aflnet任务的数据 public static ConcurrentHashMap<String, String> aflnetData = new ConcurrentHashMap<>();//当前aflnet任务的数据
public static KittyMapper kittyMapper = (KittyMapper) SpringContextUtil.getBean("KittyMapper"); public static KittyMapper kittyMapper = (KittyMapper) SpringContextUtil.getBean("KittyMapper");
public static KittyProperties kittyProperties = (KittyProperties) SpringContextUtil.getBean("kittyProperties"); public static KittyProperties kittyProperties = (KittyProperties) SpringContextUtil.getBean("kittyProperties");
public static KittyFuzzPersistenceService kittyFuzzPersistenceService =(KittyFuzzPersistenceService) SpringContextUtil.getBean("KittyFuzzPersistenceService");
public static AflnetProperties aflnetProperties = (AflnetProperties) SpringContextUtil.getBean("AflnetProperties"); public static AflnetProperties aflnetProperties = (AflnetProperties) SpringContextUtil.getBean("AflnetProperties");
public static AflnetPersistenceService aflnetPersistenceService = (AflnetPersistenceService) SpringContextUtil.getBean("AflnetPersistenceService"); public static AflnetPersistenceService aflnetPersistenceService = (AflnetPersistenceService) SpringContextUtil.getBean("AflnetPersistenceService");
......
...@@ -20,11 +20,12 @@ logging: ...@@ -20,11 +20,12 @@ logging:
max-file-size: 10MB max-file-size: 10MB
aflnet: aflnet:
seedPath: "/usr/fuzzenv/fuzzenv/aflnet/tutorials/live555/in-rtsp" seedPath: "/usr/fuzzenv/fuzzenv/aflnet/tutorials/live555/in-rtsp"#aflnet日志
outputPath: "/home/" #D:/code/companyProjects/files/ outputPath: "/home/" #D:/code/companyProjects/files/
aflnetPath: "/usr/fuzzenv/fuzzenv/"#alfnet路径 aflnetPath: "/usr/fuzzenv/fuzzenv/"#alfnet路径
kitty: kitty:
logOutPath: "/home/kittylogs/"#kitty协议模板日志生成路径
path: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/renix/" #kitty项目下的各协议生成模板python文件路径 path: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/renix/" #kitty项目下的各协议生成模板python文件路径
venvPath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/venv/bin/python" venvPath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/venv/bin/python"
methodPath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/2020test/"#kitty下变异方法路径 methodPath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/2020test/"#kitty下变异方法路径
......
...@@ -10,16 +10,34 @@ ...@@ -10,16 +10,34 @@
<result property="resultOut" column="resultOut" /> <result property="resultOut" column="resultOut" />
<result property="resultError" column="resultError" /> <result property="resultError" column="resultError" />
</resultMap> </resultMap>
<resultMap type="com.example.fuzzControll.pojo.vo.KittyPackageFile" id="kittyPackageFile">
<result property="id" column="id" />
<result property="missionId" column="missionId" />
<result property="kittyRecvFile" column="kittyRecvFile" />
<result property="kittySendFile" column="kittySendFile" />
<result property="kittyRecvFileName" column="kittyRecvFileName" />
<result property="kittySendFileName" column="kittySendFileName" />
</resultMap>
<sql id="selectKittyResult"> <sql id="selectKittyResult">
select id, missionId,resultOut, resultError from kittyResult; select id, missionId,resultOut, resultError from kittyResult;
</sql> </sql>
<sql id="selectKittyPackageFile">
select id,missionId, kittyRecvFile, kittySendFile,kittyRecvFileName,kittySendFileName from kittyPackageFile;
</sql>
<insert id="kittyResultsBackup"> <insert id="kittyResultsBackup">
insert into kittyResult(id,missionId, resultOut, resultError) values(#{id}, #{missionId},#{resultOut}, #{resultError}) insert into kittyResult(id,missionId, resultOut, resultError) values(#{id}, #{missionId},#{resultOut}, #{resultError})
</insert> </insert>
<insert id="kittyPackagesBackup">
insert into kittyPackageFile(id,missionId, kittyRecvFile, kittySendFile,kittyRecvFileName,kittySendFileName) values(#{id}, #{missionId},#{kittyRecvFile}, #{kittySendFile}, #{kittyRecvFileName}, #{kittySendFileName})
</insert>
<select id="getKittyResults" resultMap="KittyResult"> <select id="getKittyResults" resultMap="KittyResult">
<include refid="selectKittyResult"/> <include refid="selectKittyResult"/>
</select> </select>
<select id="getKittyPackageFileById" resultType="com.example.fuzzControll.pojo.vo.KittyPackageFile">
<include refid="selectKittyPackageFile"/>
where missionId=#{missionId}
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -5,6 +5,6 @@ spring: ...@@ -5,6 +5,6 @@ spring:
active: dev #默认为开发环境 active: dev #默认为开发环境
server: server:
port: 8101 port: 8104
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