Commit 99d14daf by 钱炳权

异常重放数据可获取

parent 167180d6
...@@ -3,7 +3,6 @@ package com.example.fuzzControll.controller.agentController; ...@@ -3,7 +3,6 @@ package com.example.fuzzControll.controller.agentController;
import com.example.fuzzControll.domain.bo.AflnetDataParams; import com.example.fuzzControll.domain.bo.AflnetDataParams;
import com.example.fuzzControll.domain.vo.AjaxResult; import com.example.fuzzControll.domain.vo.AjaxResult;
import com.example.fuzzControll.service.AgentOfKittyService; import com.example.fuzzControll.service.AgentOfKittyService;
import jdk.internal.agent.resources.agent;
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.*; import org.springframework.web.bind.annotation.*;
......
...@@ -3,16 +3,24 @@ package com.example.fuzzControll.controller.dataController; ...@@ -3,16 +3,24 @@ package com.example.fuzzControll.controller.dataController;
import com.example.fuzzControll.domain.bo.AflnetDataParams; import com.example.fuzzControll.domain.bo.AflnetDataParams;
import com.example.fuzzControll.domain.vo.AjaxResult; import com.example.fuzzControll.domain.vo.AjaxResult;
import com.example.fuzzControll.service.AflnetPersistenceService; import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.service.TestService;
import com.example.fuzzControll.tools.test.TestCmdTools;
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.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController @RestController
@RequestMapping("/aflnet") @RequestMapping("/aflnet")
@Slf4j @Slf4j
public class AflnetDataController { public class AflnetDataController {
@Autowired @Autowired
AflnetPersistenceService aflnetPersistenceService; AflnetPersistenceService aflnetPersistenceService;
@Autowired
TestService testService;
TestCmdTools testCmdTools = new TestCmdTools();
/** /**
* 读取数据库文件至指定目录 * 读取数据库文件至指定目录
...@@ -20,7 +28,7 @@ public class AflnetDataController { ...@@ -20,7 +28,7 @@ public class AflnetDataController {
@RequestMapping(value = "/loadFile", method = RequestMethod.GET) @RequestMapping(value = "/loadFile", method = RequestMethod.GET)
public AjaxResult AflnetResultSelect(@RequestBody AflnetDataParams aflnetDataParams) { public AjaxResult AflnetResultSelect(@RequestBody AflnetDataParams aflnetDataParams) {
try { try {
aflnetPersistenceService.loadInFile(aflnetDataParams.getMissionId(),aflnetDataParams.getFilPath()); aflnetPersistenceService.loadInFile(aflnetDataParams.getMissionId(), aflnetDataParams.getFilPath());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return AjaxResult.error("File load failed!"); return AjaxResult.error("File load failed!");
...@@ -28,4 +36,37 @@ public class AflnetDataController { ...@@ -28,4 +36,37 @@ public class AflnetDataController {
return AjaxResult.success("File loaded successfully!"); return AjaxResult.success("File loaded successfully!");
} }
/**
* 异常重放(查看堆栈)
*/
@RequestMapping(value = "/replay", method = RequestMethod.GET)
public AjaxResult replay(@RequestParam String programPath) {
try {
new Thread(new Runnable() {
@Override
public void run() {
testService.replay(programPath);
}
}).start();
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("Replay failed!");
}
return AjaxResult.success("Start replay success!");
}
/**
* 读取异常定位分析结果
*/
@RequestMapping(value = "/getreplayresult", method = RequestMethod.GET)
public AjaxResult readReplayResult() {
List<String> result = new ArrayList<String>();
try {
result = testService.getReplayResult();
} catch (Exception e) {
return AjaxResult.error("Get replayResult failed!");
}
return AjaxResult.success(result);
}
} }
...@@ -3,6 +3,7 @@ package com.example.fuzzControll.service; ...@@ -3,6 +3,7 @@ package com.example.fuzzControll.service;
import com.example.fuzzControll.domain.bo.CmdStartParams; import com.example.fuzzControll.domain.bo.CmdStartParams;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public interface TestService { public interface TestService {
...@@ -12,4 +13,8 @@ public interface TestService { ...@@ -12,4 +13,8 @@ public interface TestService {
void testStop(); void testStop();
LinkedHashMap<String,String> getProcessInfo(); LinkedHashMap<String,String> getProcessInfo();
void replay(String programPath);
List<String> getReplayResult();
} }
...@@ -11,6 +11,7 @@ import com.example.fuzzControll.domain.bo.CmdStartParams; ...@@ -11,6 +11,7 @@ import com.example.fuzzControll.domain.bo.CmdStartParams;
import com.example.fuzzControll.service.AflnetPersistenceService; import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.service.FuzzParamsService; import com.example.fuzzControll.service.FuzzParamsService;
import com.example.fuzzControll.service.TestService; import com.example.fuzzControll.service.TestService;
import com.example.fuzzControll.tools.file.FileTools;
import com.example.fuzzControll.tools.system.GlobalClass; import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.JsonUtils; import com.example.fuzzControll.tools.test.JsonUtils;
import com.example.fuzzControll.tools.test.TestCmdTools; import com.example.fuzzControll.tools.test.TestCmdTools;
...@@ -22,8 +23,10 @@ import org.springframework.stereotype.Service; ...@@ -22,8 +23,10 @@ import org.springframework.stereotype.Service;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Service("testService") @Service("testService")
...@@ -44,21 +47,32 @@ public class TestServiceImpl implements TestService { ...@@ -44,21 +47,32 @@ public class TestServiceImpl implements TestService {
@Override @Override
public void testStart(CmdStartParams cmdStartParams) throws AflnetException, CmdException { public void testStart(CmdStartParams cmdStartParams) throws AflnetException, CmdException {
/*存入参数*/ /*存入参数*/
System.out.println(JSON.toJSONString(cmdStartParams)); System.out.println("1111111111111111111111111111111111111111111111111111111111111111");
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1; int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1;
boolean flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(cmdStartParams), new Date(), missionId)); boolean flag = false;
try {
flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(cmdStartParams), new Date(), missionId));
System.out.println("flag = " + flag);
} catch (Exception e) {
log.error("Save fuzz error:{}", e.getMessage());
throw new RuntimeException(e);
}
System.out.println("2222222222222222222222222222222222222222222222222222222222222222");
if (!flag) { if (!flag) {
log.error("Save fuzzParams failed!");
throw new AflnetException("Save params error!"); throw new AflnetException("Save params error!");
} }
/*拼接指令*/ /*拼接指令*/
TestControlTools.setIsRunning(true); TestControlTools.setIsRunning(true);
String cmd = cmdTools.parse(cmdStartParams); String cmd = cmdTools.parse(cmdStartParams);
System.out.println("33333333333333333333333333333333333333333333333333333333333333333");
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";
SystemRunningParams.aflnetData.put("aflnetName", outputFileName); SystemRunningParams.aflnetData.put("aflnetName", outputFileName);
log.info("The cmd is [{}]", finalCmd); log.info("The cmd is [{}]", finalCmd);
System.out.println("444444444444444444444444444444444444444444444444444444444444444444");
/*执行指令*/ /*执行指令*/
System.out.println("testStart"); System.out.println("testStart");
cmdTools.runProgramCmd(finalCmd, outputFileName + ".zip"); cmdTools.runProgramCmd(finalCmd, outputFileName + ".zip");
...@@ -73,7 +87,48 @@ public class TestServiceImpl implements TestService { ...@@ -73,7 +87,48 @@ public class TestServiceImpl implements TestService {
} }
@Override @Override
public LinkedHashMap<String,String> getProcessInfo() { public LinkedHashMap<String, String> getProcessInfo() {
return SystemRunningParams.TestProgressMap; return SystemRunningParams.TestProgressMap;
} }
@Override
public void replay(String programPath) {
String cmd = "gdb /usr/fuzzenv/fuzzenv/live555/testProgs/" + programPath + " /usr/fuzzenv/fuzzenv/live555/testProgs/core" +
" > /usr/dump.txt";
log.info("Replay cmd is {}", cmd);
SystemRunningParams.ReplayResults = new ArrayList<>();
try {
SystemRunningParams.ReplayResults = cmdTools.runCmd(cmd, "replay");
} catch (CmdException e) {
log.error("Replay failed:{}", e.getMessage());
throw new RuntimeException(e);
}
}
@Override
public List<String> getReplayResult() {
/*停止GDB*/
try {
cmdTools.runCmd("pkill gdb", "getReplayResult-stopGdb");
} catch (CmdException e) {
log.error("StopGdb failed:{}", e.getMessage());
throw new RuntimeException(e);
}
/*给程序停止并存放数据反应时间*/
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
/*读取文件内容到响应*/
// FileTools fileTools = new FileTools();
// List<String> result = null;
// try {
// result = fileTools.fileReadAndTranstoStringList("/usr/", "dump.txt");
// } catch (Exception e) {
// log.error("File read failed:{}", e.getMessage());
// throw new RuntimeException(e);
// }
return SystemRunningParams.ReplayResults;
}
} }
...@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.util.ArrayList;
import java.util.List;
@Slf4j @Slf4j
public class FileTools { public class FileTools {
...@@ -78,4 +80,28 @@ public class FileTools { ...@@ -78,4 +80,28 @@ public class FileTools {
throw new FileException("Load file failed!"); throw new FileException("Load file failed!");
} }
} }
/**
* 读取文件到字符串数组
*/
public List<String> fileReadAndTranstoStringList(String path, String filename) {
File file = new File(path + filename);
String line = new String();
List<String> result = new ArrayList<String>();
try (
FileInputStream inputStream = new FileInputStream(file);
Reader reader = new InputStreamReader(inputStream);
BufferedReader bf = new BufferedReader(reader);) {
if (file.length() > Integer.MAX_VALUE && file.length() <= 0) {
log.error("File is too long or has no content!");
}
int bytesRead;
while ((line = bf.readLine()) != null) {
result.add(line);
}
} catch (Exception e) {
throw new RuntimeException();
}
return result;
}
} }
package com.example.fuzzControll.tools.system; package com.example.fuzzControll.tools.system;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
...@@ -38,6 +40,10 @@ public class SystemRunningParams { ...@@ -38,6 +40,10 @@ public class SystemRunningParams {
*/ */
public static LinkedHashMap<String, String> TestProgressMap = new LinkedHashMap<>(); public static LinkedHashMap<String, String> TestProgressMap = new LinkedHashMap<>();
/**
* 异常重放数据
*/
public static List<String> ReplayResults = new ArrayList<>();
public static void init() { public static void init() {
/*初始化aflnet和kitty时间参数*/ /*初始化aflnet和kitty时间参数*/
testTimeMessage.put("aflnet", new ConcurrentHashMap<>()); testTimeMessage.put("aflnet", new ConcurrentHashMap<>());
......
...@@ -35,12 +35,13 @@ public class TestCmdTools { ...@@ -35,12 +35,13 @@ public class TestCmdTools {
*/ */
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>();
List<String> error = new ArrayList<String>();
try { try {
log.info(caller + " is running!"); log.info(caller + " is running!");
log.info("Running cmd:[{}]", cmd); log.info("Running cmd:[{}]", cmd);
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(), error);
process.waitFor(); process.waitFor();
log.info(caller + " end!"); log.info(caller + " end!");
} catch (Exception e) { } catch (Exception e) {
...@@ -318,6 +319,8 @@ public class TestCmdTools { ...@@ -318,6 +319,8 @@ public class TestCmdTools {
} }
public String parse(CmdStartParams cmdStartParams) throws AflnetException { public String parse(CmdStartParams cmdStartParams) throws AflnetException {
System.out.println("************************1111111111111111111111");
System.out.println("cmd is :" + cmdStartParams);
if (cmdStartParams == null) { if (cmdStartParams == null) {
throw new AflnetException("CmdStartParams is null !"); throw new AflnetException("CmdStartParams is null !");
} }
...@@ -358,6 +361,7 @@ public class TestCmdTools { ...@@ -358,6 +361,7 @@ public class TestCmdTools {
if (cmdStartParams.getSeedSelectionAlgo() != 0) { if (cmdStartParams.getSeedSelectionAlgo() != 0) {
cmd.append(" -s " + cmdStartParams.getSeedSelectionAlgo() + " "); cmd.append(" -s " + cmdStartParams.getSeedSelectionAlgo() + " ");
} }
System.out.println("************************22222222222222222222222");
return cmd.toString(); return cmd.toString();
} }
......
...@@ -46,4 +46,20 @@ public class TestController { ...@@ -46,4 +46,20 @@ public class TestController {
//停止时就开始关闭 //停止时就开始关闭
return fuzzIntegrationFileApi.getProcessInfo(); return fuzzIntegrationFileApi.getProcessInfo();
} }
/**
* 异常重放分析
*/
@RequestMapping(value = "/replay", method = RequestMethod.GET)
public AjaxResult replay(@RequestParam String programPath) {
return fuzzIntegrationFileApi.replay(programPath);
}
/**
* 异常结果获取
*/
@RequestMapping(value = "/getreplayresult", method = RequestMethod.GET)
public AjaxResult getReplayResult() {
return fuzzIntegrationFileApi.getReplayResult( );
}
} }
\ No newline at end of file
...@@ -117,13 +117,14 @@ public interface FuzzIntegrationFileApi { ...@@ -117,13 +117,14 @@ public interface FuzzIntegrationFileApi {
* 开启网络代理 * 开启网络代理
*/ */
@RequestMapping(value = "/agent/kittyNetworkAgent", method = RequestMethod.GET) @RequestMapping(value = "/agent/kittyNetworkAgent", method = RequestMethod.GET)
AjaxResult startNetworkAgent(@RequestParam String networkCard,@RequestParam String monitorName); AjaxResult startNetworkAgent(@RequestParam String networkCard, @RequestParam String monitorName);
/** /**
* 获取代理生成的pcap文件 * 获取代理生成的pcap文件
*/ */
@RequestMapping(value = "/agent/getAgentPcap", method = RequestMethod.GET) @RequestMapping(value = "/agent/getAgentPcap", method = RequestMethod.GET)
byte[] getAgentPcap(); byte[] getAgentPcap();
/** /**
* 开启ssh代理 * 开启ssh代理
*/ */
...@@ -131,4 +132,16 @@ public interface FuzzIntegrationFileApi { ...@@ -131,4 +132,16 @@ public interface FuzzIntegrationFileApi {
AjaxResult startSshAgent(@RequestParam String MonitorName, @RequestParam String SshUserName, AjaxResult startSshAgent(@RequestParam String MonitorName, @RequestParam String SshUserName,
@RequestParam String SshPassword, @RequestParam String SshIp, @RequestParam String SshPassword, @RequestParam String SshIp,
@RequestParam String SshPort, @RequestParam String Command); @RequestParam String SshPort, @RequestParam String Command);
/**
* 异常重放分析
*/
@RequestMapping(value = "/aflnet/replay", method = RequestMethod.GET)
AjaxResult replay(@RequestParam String programPath);
/**
* 获取异常分析结果
*/
@RequestMapping(value = "/aflnet/getreplayresult", method = RequestMethod.GET)
AjaxResult getReplayResult();
} }
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