Commit b66e695c by 钱炳权

kitty日志文件存入数据库成功

parent 41283d5e
...@@ -3,11 +3,20 @@ package com.example.fuzzControll.conf; ...@@ -3,11 +3,20 @@ package com.example.fuzzControll.conf;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component("seedProperties") @Component("AflnetProperties")
@ConfigurationProperties(prefix = "aflnet") @ConfigurationProperties(prefix = "aflnet")
public class AflnetProperties { public class AflnetProperties {
String seedPath; String seedPath;
String outputPath; String outputPath;
String aflnetPath;
public String getAflnetPath() {
return aflnetPath;
}
public void setAflnetPath(String aflnetPath) {
this.aflnetPath = aflnetPath;
}
public String getOutputPath() { public String getOutputPath() {
return outputPath; return outputPath;
......
...@@ -3,7 +3,7 @@ package com.example.fuzzControll.conf; ...@@ -3,7 +3,7 @@ package com.example.fuzzControll.conf;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component("PathProperties") @Component("IntegrationPathProperties")
@ConfigurationProperties(prefix = "integrationpath") @ConfigurationProperties(prefix = "integrationpath")
public class IntegrationPathProperties { public class IntegrationPathProperties {
String webSocketUri; String webSocketUri;
......
...@@ -15,24 +15,9 @@ public class KittyProperties { ...@@ -15,24 +15,9 @@ public class KittyProperties {
String stagesHttp; String stagesHttp;
String reportHttp; String reportHttp;
String mutationPath; String mutationPath;
String aflnetPath;
String outputPath;
public String getOutputPath() {
return outputPath;
}
public void setOutputPath(String outputPath) {
this.outputPath = outputPath;
}
public String getAflnetPath() {
return aflnetPath;
}
public void setAflnetPath(String aflnetPath) {
this.aflnetPath = aflnetPath;
}
public String getMutationPath() { public String getMutationPath() {
return mutationPath; return mutationPath;
......
...@@ -2,17 +2,18 @@ package com.example.fuzzControll.constents; ...@@ -2,17 +2,18 @@ package com.example.fuzzControll.constents;
import com.example.fuzzControll.conf.SpringContextUtil; import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.conf.KittyProperties; import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.tools.GlobalParameters;
public class CmdConstent { public class CmdConstent {
static KittyProperties kittyProperties = (KittyProperties) SpringContextUtil.getBean("kittyProperties");
public static final String GET_FILE_NAME = "ls -h "; public static final String GET_FILE_NAME = "ls -h ";
public static final String DELETE_FILE = "rm -r "; public static final String DELETE_FILE = "rm -r ";
public static final String COUNT_FILE = "ls -l | grep \"^-\" | wc -l"; public static final String COUNT_FILE = "ls -l | grep \"^-\" | wc -l";
public static final String COUNT_DIR = "ls -l | grep \"^d\" | wc -l"; public static final String COUNT_DIR = "ls -l | grep \"^d\" | wc -l";
public static final String RUN_AFLNET_BEFORE = "afl-fuzz -d -i " + kittyProperties.getAflnetPath() + "aflnet/tutorials/live555/in-rtsp -o "+ public static final String RUN_AFLNET_BEFORE = "afl-fuzz -d -i " + GlobalParameters.aflnetProperties.getAflnetPath() + "aflnet/tutorials/live555/in-rtsp -o "+
kittyProperties.getOutputPath(); GlobalParameters.aflnetProperties.getOutputPath();
public static final String RUN_AFLNET_AFTER = " -x " + kittyProperties.getAflnetPath() + "aflnet/tutorials/live555/rtsp.dict "; public static final String RUN_AFLNET_AFTER = " -x " + GlobalParameters.aflnetProperties.getAflnetPath() + "aflnet/tutorials/live555/rtsp.dict ";
public static final String RUN_PING = "ping www.baidu.com"; public static final String RUN_PING = "ping www.baidu.com";
public static final String RUN_ZIP_FILE = "zip -r ";
} }
...@@ -13,16 +13,13 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -13,16 +13,13 @@ 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;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
/** /**
* aflnet测试控制 * aflnet测试控制
*/ */
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/test") @RequestMapping("/test")
public class TestControler { public class AlfnetControler {
@Autowired @Autowired
TestService service; TestService service;
...@@ -33,13 +30,12 @@ public class TestControler { ...@@ -33,13 +30,12 @@ public class TestControler {
public AjaxResult start(@RequestBody final CmdStartParams cmdStartParams) { public AjaxResult start(@RequestBody final CmdStartParams cmdStartParams) {
//todo 捕获子线程错误 //todo 捕获子线程错误
try { try {
Thread alfnet = new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
service.testStart(cmdStartParams); service.testStart(cmdStartParams);
} }
}); }).start();
alfnet.start();
} catch (Exception e) { } catch (Exception e) {
if(e instanceof AflnetException||e instanceof CmdException){ if(e instanceof AflnetException||e instanceof CmdException){
log.error(((BaseException)e).getDefaultMessage()); log.error(((BaseException)e).getDefaultMessage());
......
...@@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -15,7 +15,6 @@ 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;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -25,7 +24,7 @@ import java.util.Map; ...@@ -25,7 +24,7 @@ import java.util.Map;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/testClass") @RequestMapping("/testClass")
public class TestClassController { public class KittyController {
@Autowired @Autowired
GenerateMethodService generateMethodService; GenerateMethodService generateMethodService;
@Autowired @Autowired
......
...@@ -10,6 +10,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -10,6 +10,6 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/aflnet") @RequestMapping("/aflnet")
@Slf4j @Slf4j
public class AflnetDataController { public class AflnetDataController {
@Autowired // @Autowired
AflnetPersistenceService aflnetPersistenceService; // AflnetPersistenceService aflnetPersistenceService;
} }
...@@ -17,5 +17,5 @@ public interface AflnetMapper { ...@@ -17,5 +17,5 @@ public interface AflnetMapper {
/** /**
* 存储alfnet测试结果 * 存储alfnet测试结果
*/ */
void aflnetOutputBackup(AflnetResult aflnetResult); int aflnetOutputBackup(AflnetResult aflnetResult);
} }
package com.example.fuzzControll.service; package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.AflnetResult;
public interface AflnetPersistenceService { public interface AflnetPersistenceService {
public void aflnetResultBackup(String filename); public int aflnetResultBackup(String filename);
} }
...@@ -7,17 +7,16 @@ import com.example.fuzzControll.tools.FileTools; ...@@ -7,17 +7,16 @@ 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;
@Service
@Slf4j @Slf4j
@Service("AflnetPersistenceService")
public class AflnetPersistenceServiceImpl implements AflnetPersistenceService { public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
@Autowired @Autowired
AflnetMapper AflnetMapper; AflnetMapper AflnetMapper;
FileTools fileTools = new FileTools(); FileTools fileTools = new FileTools();
@Override @Override
public void 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.fileReadAndBackup(filename),filename);
AflnetMapper.aflnetOutputBackup(result); return AflnetMapper.aflnetOutputBackup(result);
} }
} }
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.SeedProperties; import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.constents.CmdConstent; import com.example.fuzzControll.constents.CmdConstent;
import com.example.fuzzControll.exception.CmdException; import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.exception.FileException; import com.example.fuzzControll.exception.FileException;
...@@ -24,7 +24,7 @@ public class SeedFileServiceImpl implements SeedFileService { ...@@ -24,7 +24,7 @@ public class SeedFileServiceImpl implements SeedFileService {
CmdTools cmdTools = new CmdTools(); CmdTools cmdTools = new CmdTools();
FileTools fileTools = new FileTools(); FileTools fileTools = new FileTools();
@Autowired @Autowired
SeedProperties properties; AflnetProperties properties;
@Override @Override
public List<String> getSeedFiles() throws CmdException { public List<String> getSeedFiles() throws CmdException {
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.conf.SpringContextUtil; import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.conf.KittyProperties; import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.constents.CmdConstent; import com.example.fuzzControll.constents.CmdConstent;
import com.example.fuzzControll.exception.AflnetException; import com.example.fuzzControll.exception.AflnetException;
import com.example.fuzzControll.exception.CmdException; import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.pojo.vo.CmdStartParams; import com.example.fuzzControll.pojo.vo.CmdStartParams;
import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.service.TestService; import com.example.fuzzControll.service.TestService;
import com.example.fuzzControll.tools.CmdTools; import com.example.fuzzControll.tools.CmdTools;
import com.example.fuzzControll.tools.GlobalParameters;
import com.example.fuzzControll.tools.TestControlTools; import com.example.fuzzControll.tools.TestControlTools;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@Service("testService") @Service("testService")
@Slf4j @Slf4j
public class TestServiceImpl implements TestService { public class TestServiceImpl implements TestService {
KittyProperties kittyProperties = (KittyProperties) SpringContextUtil.getBean("kittyProperties");
CmdTools cmdTools = new CmdTools(); CmdTools cmdTools = new CmdTools();
@Autowired
AflnetPersistenceService aflnetPersistenceService;
@Autowired
AflnetProperties aflnetProperties;
//todo 不同服务不同端口 //todo 不同服务不同端口
@Override @Override
...@@ -31,10 +40,12 @@ public class TestServiceImpl implements TestService { ...@@ -31,10 +40,12 @@ public class TestServiceImpl implements TestService {
String cmd = cmdTools.parse(cmdStartParams); String cmd = cmdTools.parse(cmdStartParams);
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 outputPathName = df.format(date)+cmdStartParams.getProtopcol()+"-output"; String outputFileName = df.format(date)+cmdStartParams.getProtopcol()+"-output";
String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputPathName + CmdConstent.RUN_AFLNET_AFTER + cmd + kittyProperties.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);
log.info("The cmd is [{}]",finalCmd); log.info("The cmd is [{}]",finalCmd);
cmdTools.runProgramCmd(finalCmd,outputPathName); cmdTools.runProgramCmd(finalCmd, outputFileName + ".zip");
} }
...@@ -42,5 +53,33 @@ public class TestServiceImpl implements TestService { ...@@ -42,5 +53,33 @@ public class TestServiceImpl implements TestService {
public void testStop() { public void testStop() {
TestControlTools.setIsRunning(false); TestControlTools.setIsRunning(false);
log.info("Aflnet has been stopped ! "); log.info("Aflnet has been stopped ! ");
try {
new Thread(new Runnable() {
@Override
public void run() {
int flag = 0;
String fileName = GlobalParameters.aflnetData.get("aflnetName");
String fileZipName = fileName + ".zip";
cmdTools.runCmd(CmdConstent.RUN_ZIP_FILE + fileZipName + " " + fileName, "zip file in testStart");
List<String> files = cmdTools.runCmd(CmdConstent.GET_FILE_NAME + aflnetProperties.getOutputPath(), "getSeedFiles");
while (files.contains(fileZipName) && flag == 0) {//当前存在压缩包才存入
flag = aflnetPersistenceService.aflnetResultBackup(fileZipName);
}
/*清除生成的文件*/
try {
cmdTools.runCmd(CmdConstent.DELETE_FILE+fileName,"delete file");
cmdTools.runCmd(CmdConstent.DELETE_FILE+fileZipName,"delete zipFile");
} catch (CmdException e) {
e.printStackTrace();
log.error("file delete failed!");
}
log.info("kittyLog has been backuped!");
}
}).start();
} catch (Exception e) {
log.error("AflnetBackup Error!");
e.printStackTrace();
}
} }
} }
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.PathProperties; import com.example.fuzzControll.conf.IntegrationPathProperties;
import com.example.fuzzControll.service.websocketClientService; import com.example.fuzzControll.service.websocketClientService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient; import org.java_websocket.client.WebSocketClient;
...@@ -16,7 +16,7 @@ import java.net.URISyntaxException; ...@@ -16,7 +16,7 @@ import java.net.URISyntaxException;
public class websocketClientServiceImpl implements websocketClientService { public class websocketClientServiceImpl implements websocketClientService {
public static WebSocketClient webSocketClient = null; public static WebSocketClient webSocketClient = null;
@Autowired @Autowired
PathProperties properties; IntegrationPathProperties properties;
@Override @Override
public void connect() { public void connect() {
try { try {
......
package com.example.fuzzControll.tools; package com.example.fuzzControll.tools;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.conf.SpringContextUtil; import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.constents.CmdConstent;
import com.example.fuzzControll.exception.AflnetException; import com.example.fuzzControll.exception.AflnetException;
import com.example.fuzzControll.exception.CmdException; import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.mapper.KittyMapper; import com.example.fuzzControll.mapper.KittyMapper;
...@@ -25,8 +27,6 @@ public class CmdTools { ...@@ -25,8 +27,6 @@ public class CmdTools {
Boolean show = true; Boolean show = true;
SqlTools sqlTools = new SqlTools();
AflnetPersistenceService AflnetPersistenceService = (AflnetPersistenceService) SpringContextUtil.getBean("AflnetPersistenceService");
/** /**
* 运行不需要后台运行cmd * 运行不需要后台运行cmd
*/ */
...@@ -50,13 +50,12 @@ public class CmdTools { ...@@ -50,13 +50,12 @@ public class CmdTools {
* 运行需要后台运行cmd * 运行需要后台运行cmd
* 通过websocket返回数据 * 通过websocket返回数据
*/ */
public void runProgramCmd(String cmd,String outputPathName) 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());
printMessage(process.getErrorStream(), new ArrayList<String>()); printMessage(process.getErrorStream(), new ArrayList<String>());
process.waitFor(); process.waitFor();
AflnetPersistenceService.aflnetResultBackup(outputPathName);
log.info("Aflnet cmd have been run."); log.info("Aflnet cmd have been run.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -80,7 +79,7 @@ public class CmdTools { ...@@ -80,7 +79,7 @@ public class CmdTools {
//todo 对于无法运行和数据较长的还需要观察 //todo 对于无法运行和数据较长的还需要观察
try { try {
KittyResult kittyResult = new KittyResult(1, out.toString(), error.toString()); KittyResult kittyResult = new KittyResult(1, out.toString(), error.toString());
sqlTools.kittyBackup(kittyResult); GlobalParameters.kittyMapper.kittyResultsBackup(kittyResult);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("kitty backup error!"); log.error("kitty backup error!");
...@@ -260,6 +259,7 @@ public class CmdTools { ...@@ -260,6 +259,7 @@ public class CmdTools {
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 !");
throw new AflnetException("There is no netinfo !"); throw new AflnetException("There is no netinfo !");
} }
if (cmdStartParams.getProtopcol() != "") { if (cmdStartParams.getProtopcol() != "") {
......
package com.example.fuzzControll.tools;
import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.service.AflnetPersistenceService;
import java.util.concurrent.ConcurrentHashMap;
public class GlobalParameters {
public static ConcurrentHashMap<String, String> aflnetData = new ConcurrentHashMap<>();//当前aflnet任务的数据
public static KittyMapper kittyMapper = (KittyMapper) SpringContextUtil.getBean("KittyMapper");
public static KittyProperties kittyProperties = (KittyProperties) SpringContextUtil.getBean("kittyProperties");
public static AflnetProperties aflnetProperties = (AflnetProperties) SpringContextUtil.getBean("AflnetProperties");
public static AflnetPersistenceService aflnetPersistenceService = (AflnetPersistenceService) SpringContextUtil.getBean("AflnetPersistenceService");
}
package com.example.fuzzControll.tools;
import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.pojo.vo.KittyResult;
public class SqlTools {
KittyMapper kittyMapper = (KittyMapper) SpringContextUtil.getBean("KittyMapper");
public void kittyBackup(KittyResult kittyResult) {
kittyMapper.kittyResultsBackup(kittyResult);
}
}
...@@ -21,10 +21,10 @@ logging: ...@@ -21,10 +21,10 @@ logging:
aflnet: aflnet:
seedPath: "/usr/fuzzenv/fuzzenv/aflnet/tutorials/live555/in-rtsp" seedPath: "/usr/fuzzenv/fuzzenv/aflnet/tutorials/live555/in-rtsp"
outputPath: "D:/code/companyProjects/files" #D:/code/companyProjects/files outputPath: "/home/" #D:/code/companyProjects/files/
kitty:
aflnetPath: "/usr/fuzzenv/fuzzenv/"#alfnet路径 aflnetPath: "/usr/fuzzenv/fuzzenv/"#alfnet路径
outputPath: "/home/" #alfnet输出路径
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下变异方法路径
......
...@@ -5,6 +5,6 @@ spring: ...@@ -5,6 +5,6 @@ spring:
active: dev #默认为开发环境 active: dev #默认为开发环境
server: server:
port: 8102 port: 8103
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