Commit e47c4040 by 钱炳权

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

parent e8313a6d
package com.example.fuzzControll.constents;
public enum ServerClassEnum {
}
...@@ -38,7 +38,6 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ ...@@ -38,7 +38,6 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
if (files.size() > 3) { if (files.size() > 3) {
log.error("kittyLogs backup failed!"); log.error("kittyLogs backup failed!");
} }
System.out.println("1");
List<String> logFiles = null; List<String> logFiles = null;
try { try {
logFiles = files.stream().filter(file -> file.contains("pcap")).collect(Collectors.toList()); logFiles = files.stream().filter(file -> file.contains("pcap")).collect(Collectors.toList());
...@@ -46,9 +45,7 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ ...@@ -46,9 +45,7 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
log.error("There is no file!"); log.error("There is no file!");
e.printStackTrace(); 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(missionId, "", "", KittyPackageFile kittyPackageFile = new KittyPackageFile(missionId, "", "",
new byte[1], new byte[1],
...@@ -56,8 +53,6 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ ...@@ -56,8 +53,6 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
// KittyPackageFile kittyPackageFile = new KittyPackageFile(missionId, logFiles.get(0), logFiles.get(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(0)),
// fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(1))); // fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(1)));
System.out.println(kittyPackageFile);
System.out.println("4");
return kittyMapper.kittyPackagesBackup(kittyPackageFile); return kittyMapper.kittyPackagesBackup(kittyPackageFile);
} }
......
...@@ -41,7 +41,7 @@ public class TestServiceImpl implements TestService { ...@@ -41,7 +41,7 @@ public class TestServiceImpl implements TestService {
Date date = new Date(); Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss-"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss-");
String outputFileName = df.format(date)+cmdStartParams.getProtopcol()+"-output"; String outputFileName = df.format(date)+cmdStartParams.getProtopcol()+"-output";
String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputFileName + CmdConstent.RUN_AFLNET_AFTER + cmd + aflnetProperties.getAflnetPath() + "live555/testProgs/testOnDemandRTSPServer 8554"; String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputFileName + CmdConstent.RUN_AFLNET_AFTER + cmd + aflnetProperties.getAflnetPath() + "live555/testProgs/"+"testOnDemandRTSPServer 8554";
GlobalParameters.aflnetData.put("aflnetName", outputFileName); GlobalParameters.aflnetData.put("aflnetName", outputFileName);
log.info("The cmd is [{}]",finalCmd); log.info("The cmd is [{}]",finalCmd);
cmdTools.runProgramCmd(finalCmd, outputFileName + ".zip"); cmdTools.runProgramCmd(finalCmd, outputFileName + ".zip");
...@@ -62,6 +62,10 @@ public class TestServiceImpl implements TestService { ...@@ -62,6 +62,10 @@ public class TestServiceImpl implements TestService {
String fileZipName = fileName + ".zip"; String fileZipName = fileName + ".zip";
cmdTools.runCmd(CmdConstent.RUN_ZIP_FILE + fileZipName + " " + fileName, "zip file in testStart"); cmdTools.runCmd(CmdConstent.RUN_ZIP_FILE + fileZipName + " " + fileName, "zip file in testStart");
List<String> files = cmdTools.runCmd(CmdConstent.GET_FILE_NAME + aflnetProperties.getOutputPath(), "getSeedFiles"); List<String> files = cmdTools.runCmd(CmdConstent.GET_FILE_NAME + aflnetProperties.getOutputPath(), "getSeedFiles");
files.stream().forEach(System.out::println);
if(!files.contains(fileZipName)){
log.error("File zip error!");
}
while (files.contains(fileZipName) && flag == 0) {//当前存在压缩包才存入 while (files.contains(fileZipName) && flag == 0) {//当前存在压缩包才存入
flag = aflnetPersistenceService.aflnetResultBackup(fileZipName,GlobalParameters.aflnetData.get("missionName")); flag = aflnetPersistenceService.aflnetResultBackup(fileZipName,GlobalParameters.aflnetData.get("missionName"));
} }
...@@ -74,7 +78,7 @@ public class TestServiceImpl implements TestService { ...@@ -74,7 +78,7 @@ public class TestServiceImpl implements TestService {
log.error("file delete failed!"); log.error("file delete failed!");
} }
log.info("kittyLog has been backuped!"); log.info("Aflnet Logs has been backuped!");
} }
}).start(); }).start();
} catch (Exception e) { } catch (Exception e) {
......
...@@ -35,10 +35,12 @@ public class CmdTools { ...@@ -35,10 +35,12 @@ public class CmdTools {
public List<String> runCmd(String cmd, String caller) throws CmdException { public List<String> runCmd(String cmd, String caller) throws CmdException {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
try { try {
log.info(caller+" is running!");
Process process = Runtime.getRuntime().exec(cmd); Process process = Runtime.getRuntime().exec(cmd);
printMessage(process.getInputStream(), result); printMessage(process.getInputStream(), result);
printMessage(process.getErrorStream(), new ArrayList<String>()); printMessage(process.getErrorStream(), new ArrayList<String>());
process.waitFor(); process.waitFor();
log.info(caller+" end!");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new CmdException(caller + " run cmd failed!"); throw new CmdException(caller + " run cmd failed!");
...@@ -262,37 +264,37 @@ public class CmdTools { ...@@ -262,37 +264,37 @@ public class CmdTools {
} }
StringBuilder cmd = new StringBuilder(); StringBuilder cmd = new StringBuilder();
if (cmdStartParams.getNetinfo() != "" && cmdStartParams.getNetinfo() != null) { if (cmdStartParams.getNetinfo() != "" && cmdStartParams.getNetinfo() != null) {
cmd.append(" -N " + cmdStartParams.getNetinfo()); cmd.append(" -N " + cmdStartParams.getNetinfo()+ " ");
} else { } else {
log.error("There is no netinfo !"); log.error("There is no netinfo !");
throw new AflnetException("There is no netinfo !"); throw new AflnetException("There is no netinfo !");
} }
if (cmdStartParams.getProtopcol() != "") { if (cmdStartParams.getProtopcol() != "") {
cmd.append(" -P " + cmdStartParams.getProtopcol()); cmd.append(" -P " + cmdStartParams.getProtopcol()+ " ");
} }
if (cmdStartParams.getWaiting() != 0) { if (cmdStartParams.getWaiting() != 0) {
cmd.append(" -D " + cmdStartParams.getWaiting()); cmd.append(" -D " + cmdStartParams.getWaiting()+ " ");
} }
if (cmdStartParams.getNsname() != "") { if (cmdStartParams.getNsname() != "") {
cmd.append(" -e " + cmdStartParams.getNsname()); cmd.append(" -e " + cmdStartParams.getNsname()+ " ");
} }
if (cmdStartParams.getKill()) { if (cmdStartParams.getKill()) {
cmd.append(" -K "); cmd.append(" -K ");
} }
if (cmdStartParams.getAwareMode()) { if (cmdStartParams.getAwareMode()) {
cmd.append(" -E "); cmd.append(" -E "+ " ");
} }
if (cmdStartParams.getRegionMutationOperators()) { if (cmdStartParams.getRegionMutationOperators()) {
cmd.append(" -R "); cmd.append(" -R "+ " ");
} }
if (cmdStartParams.getFalseNegativeMode()) { if (cmdStartParams.getFalseNegativeMode()) {
cmd.append(" -F "); cmd.append(" -F "+ " ");
} }
if (cmdStartParams.getScript() != "") { if (cmdStartParams.getScript() != "") {
cmd.append(" -c " + cmdStartParams.getScript()); cmd.append(" -c " + cmdStartParams.getScript()+ " ");
} }
if (cmdStartParams.getStateSelectionAlgo() != 0) { if (cmdStartParams.getStateSelectionAlgo() != 0) {
cmd.append(" -q " + cmdStartParams.getStateSelectionAlgo()); cmd.append(" -q " + cmdStartParams.getStateSelectionAlgo()+ " ");
} }
if (cmdStartParams.getSeedSelectionAlgo() != 0) { if (cmdStartParams.getSeedSelectionAlgo() != 0) {
cmd.append(" -s " + cmdStartParams.getSeedSelectionAlgo() + " "); cmd.append(" -s " + cmdStartParams.getSeedSelectionAlgo() + " ");
......
...@@ -49,16 +49,13 @@ public class FileTools { ...@@ -49,16 +49,13 @@ public class FileTools {
FileInputStream inputStream = new FileInputStream(file); FileInputStream inputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);) { BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);) {
System.out.println("1-2");
if (file.length() > Integer.MAX_VALUE && file.length() <= 0) { if (file.length() > Integer.MAX_VALUE && file.length() <= 0) {
log.error("KittyLogFile is too long or has no content!"); log.error("KittyLogFile is too long or has no content!");
} }
System.out.println("1-3");
int bytesRead; int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) { while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
System.out.println(buffer.length); System.out.println(buffer.length);
} }
System.out.println("1-5");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/test") @RequestMapping("/aflnet")
@CrossOrigin @CrossOrigin
public class TestController { public class TestController {
@Autowired @Autowired
......
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