Commit e8df61c8 by 钱炳权

测试参数可存入

parent 5148ec7b
...@@ -67,7 +67,7 @@ public class aroundAop implements Ordered { ...@@ -67,7 +67,7 @@ public class aroundAop implements Ordered {
} }
if ("generation".equals(function)) { if ("generation".equals(function)) {
/*运行前处理*/ /*运行前处理*/
/*存入kitty启动时的任务信息*/ /*存入kitty启动时的任务信息*/
try { try {
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1; int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1;
SystemRunningParams.kittyMissionId = missionId; SystemRunningParams.kittyMissionId = missionId;
......
...@@ -36,11 +36,11 @@ public class FuzzParamsController { ...@@ -36,11 +36,11 @@ public class FuzzParamsController {
/** /**
* 跟据id获取参数 * 跟据id获取参数
*/ */
@RequestMapping(value = "/getParam/{id}", method = RequestMethod.GET) @RequestMapping(value = "/getParam/{missionId}", method = RequestMethod.GET)
public AjaxResult getById(@PathVariable("id") int id) { public AjaxResult getById(@PathVariable("missionId") int missionId) {
FuzzParams result; FuzzParams result;
try { try {
result = fuzzParamsService.getFuzzParamById(id); result = fuzzParamsService.getFuzzParamById(missionId);
} catch (Exception e) { } catch (Exception e) {
log.error("Get params of fuzz with id error:{}", e.getMessage()); log.error("Get params of fuzz with id error:{}", e.getMessage());
return AjaxResult.error(); return AjaxResult.error();
......
...@@ -30,7 +30,6 @@ public class AlfnetController { ...@@ -30,7 +30,6 @@ public class AlfnetController {
*/ */
@RequestMapping(value = "/testStart", method = RequestMethod.POST) @RequestMapping(value = "/testStart", method = RequestMethod.POST)
public AjaxResult start(@RequestBody final CmdStartParams cmdStartParams) { public AjaxResult start(@RequestBody final CmdStartParams cmdStartParams) {
//todo 捕获子线程错误
try { try {
SystemRunningParams.aflnetData.put("missionName", cmdStartParams.getProtopcol()); SystemRunningParams.aflnetData.put("missionName", cmdStartParams.getProtopcol());
Thread subThread = new Thread(new Runnable() { Thread subThread = new Thread(new Runnable() {
......
...@@ -43,7 +43,7 @@ public class KittyController { ...@@ -43,7 +43,7 @@ public class KittyController {
public AjaxResult protocolTemplate(@RequestBody TestEntity testEntity) { public AjaxResult protocolTemplate(@RequestBody TestEntity testEntity) {
try { try {
SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName()); SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName());
Map<String, List<String>> result = protocolTemplateService.generation(testEntity,1); Map<String, List<String>> result = protocolTemplateService.generation(testEntity);
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());
...@@ -58,7 +58,7 @@ public class KittyController { ...@@ -58,7 +58,7 @@ public class KittyController {
public AjaxResult generate(@RequestBody TestEntity testEntity) { public AjaxResult generate(@RequestBody TestEntity testEntity) {
try { try {
SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName()); SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName());
Map<String, List<String>> result = generateMethodService.generation(testEntity,1); Map<String, List<String>> result = generateMethodService.generation(testEntity);
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());
...@@ -73,7 +73,7 @@ public class KittyController { ...@@ -73,7 +73,7 @@ public class KittyController {
public AjaxResult mutation(@RequestBody TestEntity testEntity) { public AjaxResult mutation(@RequestBody TestEntity testEntity) {
try { try {
SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName()); SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName());
Map<String, List<String>> result = mutationService.generation(testEntity,1); Map<String, List<String>> result = mutationService.generation(testEntity);
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());
...@@ -88,7 +88,7 @@ public class KittyController { ...@@ -88,7 +88,7 @@ public class KittyController {
public AjaxResult vulnerability(@RequestBody TestEntity testEntity) { public AjaxResult vulnerability(@RequestBody TestEntity testEntity) {
try { try {
SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName()); SystemRunningParams.kittyData.put("missionName",testEntity.getTestClassName());
Map<String, List<String>> result = vulnerabilityTypeService.generation(testEntity,1); Map<String, List<String>> result = vulnerabilityTypeService.generation(testEntity);
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());
......
...@@ -13,8 +13,61 @@ import java.util.Date; ...@@ -13,8 +13,61 @@ import java.util.Date;
@Getter @Getter
@Setter @Setter
public class FuzzParams { public class FuzzParams {
private int id; private int id;
private String params; private String params;
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")
private Date editTime; private Date editTime;
private int missionId;
public FuzzParams() {
}
public FuzzParams(int id, String params, Date editTime, int missionId) {
this.id = id;
this.params = params;
this.editTime = editTime;
this.missionId = missionId;
}
public FuzzParams(String params, Date editTime, int missionId) {
this.params = params;
this.editTime = editTime;
this.missionId = missionId;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public Date getEditTime() {
return editTime;
}
public void setEditTime(Date editTime) {
this.editTime = editTime;
}
public int getMissionId() {
return missionId;
}
public void setMissionId(int missionId) {
this.missionId = missionId;
}
} }
...@@ -10,7 +10,7 @@ import java.util.List; ...@@ -10,7 +10,7 @@ import java.util.List;
@Mapper @Mapper
@Component("FuzzParamsMapper") @Component("FuzzParamsMapper")
public interface FuzzParamsMapper { public interface FuzzParamsMapper {
void saveFuzzParams(FuzzParams fuzzParams); boolean saveFuzzParams(FuzzParams fuzzParams);
List<FuzzParams> getFuzzParamsList(); List<FuzzParams> getFuzzParamsList();
FuzzParams getFuzzParamsById(int id); FuzzParams getFuzzParamsById(int id);
......
...@@ -8,7 +8,7 @@ import java.util.List; ...@@ -8,7 +8,7 @@ import java.util.List;
public interface FuzzParamsService { public interface FuzzParamsService {
List<FuzzParams> getFuzzParamsList(); List<FuzzParams> getFuzzParamsList();
FuzzParams getFuzzParamById(int id); FuzzParams getFuzzParamById(int missionId);
//todo 使用切面在运行时插入参数 //todo 使用切面在运行时插入参数
boolean saveFuzzParams(FuzzParams fuzzParams); boolean saveFuzzParams(FuzzParams fuzzParams);
......
...@@ -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,int missionId); Map<String,List<String>> generation(TestEntity testEntity);
} }
...@@ -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,int missionId); Map<String, List<String>> generation(TestEntity testEntity);
} }
...@@ -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,int missionId); Map<String,List<String>> generation(TestEntity testEntity);
} }
...@@ -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,int missionId); Map<String, List<String>> generation(TestEntity testEntity);
} }
...@@ -30,10 +30,10 @@ public class FuzzParamsServiceImpl implements FuzzParamsService { ...@@ -30,10 +30,10 @@ public class FuzzParamsServiceImpl implements FuzzParamsService {
} }
@Override @Override
public FuzzParams getFuzzParamById(int id) { public FuzzParams getFuzzParamById(int missionId) {
FuzzParams fuzzParams = null; FuzzParams fuzzParams = null;
try { try {
fuzzParams = fuzzParamsMapper.getFuzzParamsById(id); fuzzParams = fuzzParamsMapper.getFuzzParamsById(missionId);
} catch (Exception e) { } catch (Exception e) {
log.error("FuzzParamsService.getFuzzParamById error:{}",e.getMessage()); log.error("FuzzParamsService.getFuzzParamById error:{}",e.getMessage());
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -43,7 +43,7 @@ public class FuzzParamsServiceImpl implements FuzzParamsService { ...@@ -43,7 +43,7 @@ public class FuzzParamsServiceImpl implements FuzzParamsService {
@Override @Override
public boolean saveFuzzParams(FuzzParams fuzzParams) { public boolean saveFuzzParams(FuzzParams fuzzParams) {
return false; return fuzzParamsMapper.saveFuzzParams(fuzzParams);
} }
@Override @Override
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAround; import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore; import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.conf.KittyProperties; import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.domain.bo.FuzzParams;
import com.example.fuzzControll.exception.testException.AflnetException;
import com.example.fuzzControll.exception.testException.CmdException; import com.example.fuzzControll.exception.testException.CmdException;
import com.example.fuzzControll.exception.testException.FuzzException; import com.example.fuzzControll.exception.testException.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity; import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
import com.example.fuzzControll.service.GenerateMethodService; import com.example.fuzzControll.service.GenerateMethodService;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.TestCmdTools; import com.example.fuzzControll.tools.test.TestCmdTools;
import com.example.fuzzControll.tools.test.TestTools; import com.example.fuzzControll.tools.test.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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -22,10 +28,18 @@ public class GenerateMethodServiceImpl implements GenerateMethodService { ...@@ -22,10 +28,18 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
TestCmdTools cmdTools = new TestCmdTools(); TestCmdTools cmdTools = new TestCmdTools();
@Autowired @Autowired
KittyProperties kitty; KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override @Override
@NeedCutAround(name ="kitty",function = "generation") @NeedCutAround(name ="kitty",function = "generation")
public Map<String, List<String>> generation(TestEntity testEntity,int missionId) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
/*存入参数*/
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId();
boolean flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(testEntity.getParamJson()), new Date(), missionId));
if (!flag) {
throw new AflnetException("Save params error!");
}
/*运行指令*/
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!");
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAfter; import com.example.fuzzControll.annotion.NeedCutAfter;
import com.example.fuzzControll.annotion.NeedCutAround; import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore; import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.conf.KittyProperties; import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.constents.MutationConstent; import com.example.fuzzControll.constents.MutationConstent;
import com.example.fuzzControll.domain.bo.FuzzParams;
import com.example.fuzzControll.exception.testException.AflnetException;
import com.example.fuzzControll.exception.testException.CmdException; import com.example.fuzzControll.exception.testException.CmdException;
import com.example.fuzzControll.exception.testException.FuzzException; import com.example.fuzzControll.exception.testException.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity; import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
import com.example.fuzzControll.service.MutationService; import com.example.fuzzControll.service.MutationService;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.TestCmdTools; import com.example.fuzzControll.tools.test.TestCmdTools;
import com.example.fuzzControll.tools.test.TestTools; import com.example.fuzzControll.tools.test.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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -24,11 +30,18 @@ class MutationServiceImpl implements MutationService { ...@@ -24,11 +30,18 @@ class MutationServiceImpl implements MutationService {
TestCmdTools cmdTools = new TestCmdTools(); TestCmdTools cmdTools = new TestCmdTools();
@Autowired @Autowired
KittyProperties kitty; KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override @Override
@NeedCutAround(name ="kitty",function = "generation") @NeedCutAround(name ="kitty",function = "generation")
public Map<String, List<String>> generation(TestEntity testEntity, int missionId) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
/*存入参数*/
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId();
boolean flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(testEntity.getParamJson()), new Date(), missionId));
if (!flag) {
throw new AflnetException("Save params error!");
}
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!");
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAround; import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore; import com.example.fuzzControll.annotion.NeedCutBefore;
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.constents.ProtocolConstent; import com.example.fuzzControll.constents.ProtocolConstent;
import com.example.fuzzControll.domain.bo.FuzzParams;
import com.example.fuzzControll.exception.testException.AflnetException;
import com.example.fuzzControll.exception.testException.CmdException; import com.example.fuzzControll.exception.testException.CmdException;
import com.example.fuzzControll.exception.testException.FuzzException; import com.example.fuzzControll.exception.testException.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity; import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
import com.example.fuzzControll.service.ProtocolTemplateService; import com.example.fuzzControll.service.ProtocolTemplateService;
import com.example.fuzzControll.tools.system.GlobalClass; import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.SingleCmdTools; import com.example.fuzzControll.tools.test.SingleCmdTools;
...@@ -18,6 +22,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -18,6 +22,7 @@ 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.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -28,10 +33,18 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService { ...@@ -28,10 +33,18 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
TestCmdTools testCmdTools = new TestCmdTools(); TestCmdTools testCmdTools = new TestCmdTools();
@Autowired @Autowired
KittyProperties kitty; KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override @Override
@NeedCutAround(name ="kitty",function = "generation") @NeedCutAround(name ="kitty",function = "generation")
public Map<String, List<String>> generation(TestEntity testEntity, int missionId) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
/*存入参数*/
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId();
boolean flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(testEntity.getParamJson()), new Date(), missionId));
if (!flag) {
throw new AflnetException("Save params error!");
}
/*生成日志前先清除日志*/ /*生成日志前先清除日志*/
singleCmdTools.runCmd(CmdConstent.DELETE_FILE + GlobalClass.kittyProperties.getLogOutPath(), "delete kittyLogs"); singleCmdTools.runCmd(CmdConstent.DELETE_FILE + GlobalClass.kittyProperties.getLogOutPath(), "delete kittyLogs");
String cmd = parseParameters(testEntity); String cmd = parseParameters(testEntity);
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutBefore; import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.conf.AflnetProperties; import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.constents.CmdConstent; import com.example.fuzzControll.constents.CmdConstent;
import com.example.fuzzControll.domain.bo.FuzzParams;
import com.example.fuzzControll.exception.testException.AflnetException; import com.example.fuzzControll.exception.testException.AflnetException;
import com.example.fuzzControll.exception.testException.CmdException; import com.example.fuzzControll.exception.testException.CmdException;
import com.example.fuzzControll.domain.bo.CmdStartParams; 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.TestService; import com.example.fuzzControll.service.TestService;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.JsonUtils;
import com.example.fuzzControll.tools.test.TestCmdTools; import com.example.fuzzControll.tools.test.TestCmdTools;
import com.example.fuzzControll.tools.test.TestControlTools; import com.example.fuzzControll.tools.test.TestControlTools;
import com.example.fuzzControll.tools.system.SystemRunningParams; import com.example.fuzzControll.tools.system.SystemRunningParams;
...@@ -30,10 +35,19 @@ public class TestServiceImpl implements TestService { ...@@ -30,10 +35,19 @@ public class TestServiceImpl implements TestService {
@Autowired @Autowired
AflnetProperties aflnetProperties; AflnetProperties aflnetProperties;
@Autowired
FuzzParamsService fuzzParamsService;
//todo 不同服务不同端口 //todo 不同服务不同端口
@Override @Override
public void testStart(CmdStartParams cmdStartParams) throws AflnetException, CmdException { public void testStart(CmdStartParams cmdStartParams) throws AflnetException, CmdException {
/*存入参数*/
System.out.println(JSON.toJSONString(cmdStartParams));
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1;
boolean flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(cmdStartParams), new Date(), missionId));
if (!flag) {
throw new AflnetException("Save params error!");
}
/*拼接指令*/ /*拼接指令*/
TestControlTools.setIsRunning(true); TestControlTools.setIsRunning(true);
String cmd = cmdTools.parse(cmdStartParams); String cmd = cmdTools.parse(cmdStartParams);
...@@ -49,7 +63,7 @@ public class TestServiceImpl implements TestService { ...@@ -49,7 +63,7 @@ public class TestServiceImpl implements TestService {
} }
@Override @Override
@NeedCutBefore(name = "aflnet", function = "stopBackup")//停止时完成数据入库 @NeedCutBefore(name = "aflnet", function = "stopBackup")//停止时完成数据入库
public void testStop() { public void testStop() {
TestControlTools.setIsRunning(false);//指令终止 todo 后期需要考虑,发送终止指令停止测试 TestControlTools.setIsRunning(false);//指令终止 todo 后期需要考虑,发送终止指令停止测试
SystemRunningParams.testTimeMessage.get("aflnet").put("end", System.currentTimeMillis());//指令停止时间 SystemRunningParams.testTimeMessage.get("aflnet").put("end", System.currentTimeMillis());//指令停止时间
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAround; import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore; import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.conf.KittyProperties; import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.domain.bo.FuzzParams;
import com.example.fuzzControll.exception.testException.AflnetException;
import com.example.fuzzControll.exception.testException.CmdException; import com.example.fuzzControll.exception.testException.CmdException;
import com.example.fuzzControll.exception.testException.FuzzException; import com.example.fuzzControll.exception.testException.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity; import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
import com.example.fuzzControll.service.VulnerabilityTypeService; import com.example.fuzzControll.service.VulnerabilityTypeService;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.TestCmdTools; 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.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -21,10 +27,17 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService { ...@@ -21,10 +27,17 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
TestCmdTools cmdTools = new TestCmdTools(); TestCmdTools cmdTools = new TestCmdTools();
@Autowired @Autowired
KittyProperties kitty; KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override @Override
@NeedCutAround(name ="kitty",function = "generation") @NeedCutAround(name ="kitty",function = "generation")
public Map<String, List<String>> generation(TestEntity testEntity,int missionId) throws FuzzException, CmdException { public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
/*存入参数*/
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId();
boolean flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(testEntity.getParamJson()), new Date(), missionId));
if (!flag) {
throw new AflnetException("Save params error!");
}
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!");
......
package com.example.fuzzControll.tools.test;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.domain.bo.TestEntity;
/**
* json相关工具
*/
public class JsonUtils {
public static String EntityToJsonString(TestEntity testEntity){
return JSON.toJSONString(testEntity.getParamJson());
}
}
...@@ -41,7 +41,7 @@ spring: ...@@ -41,7 +41,7 @@ spring:
discovery: discovery:
server-addr: http://${nacos-docker.ip}:8848 server-addr: http://${nacos-docker.ip}:8848
datasource: datasource:
url: jdbc:mysql://${mysql-docker.ip}:3307/fuzz?allowPublicKeyRetrieval=true&useSSL=falseuseUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://${mysql-docker.ip}:${mysql-docker.port}/fuzz?allowPublicKeyRetrieval=true&useSSL=falseuseUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: 123456 password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
...@@ -49,10 +49,11 @@ integrationpath: ...@@ -49,10 +49,11 @@ integrationpath:
webSocketUri: ws://${fuzzmaster-docker.ip}:8101/websocket/testResult/ webSocketUri: ws://${fuzzmaster-docker.ip}:8101/websocket/testResult/
nacos-docker: nacos-docker:
ip: 192.168.50.247 ip: 192.168.50.251
fuzzmaster-docker: fuzzmaster-docker:
ip: 192.168.50.247 ip: 192.168.50.251
mysql-docker: mysql-docker:
ip: 192.168.50.247 ip: 192.168.50.251
\ No newline at end of file port: 3307
\ No newline at end of file
...@@ -5,6 +5,6 @@ spring: ...@@ -5,6 +5,6 @@ spring:
active: dev #默认为开发环境 active: dev #默认为开发环境
server: server:
port: 8103 port: 8104
...@@ -8,20 +8,21 @@ ...@@ -8,20 +8,21 @@
<result property="id" column="id" /> <result property="id" column="id" />
<result property="params" column="params" /> <result property="params" column="params" />
<result property="editTime" column="editTime" /> <result property="editTime" column="editTime" />
<result property="missionId" column="missionId" />
</resultMap> </resultMap>
<sql id="selectFuzzParams"> <sql id="selectFuzzParams">
select id, params,editTime from fuzz_params select id, params,editTime,missionId from fuzz_params
</sql> </sql>
<insert id="saveFuzzParams"> <insert id="saveFuzzParams">
insert into fuzz_params(id, params,editTime) values(#{id}, #{params},#{editTime}) insert into fuzz_params(id, params,editTime,missionId) values(#{id}, #{params},#{editTime},#{missionId})
</insert> </insert>
<update id="editFuzzParams"> <update id="editFuzzParams">
update fuzz_params set params = #{params} ,editTime = #{editTime} where missionId = #{missionId}
</update> </update>
<select id="getFuzzParamsById" resultMap="fuzzParams"> <select id="getFuzzParamsById" resultMap="fuzzParams">
<include refid="selectFuzzParams"/> <include refid="selectFuzzParams"/>
where id = #{id} where missionId = #{missionId}
</select> </select>
<select id="getFuzzParamsList" resultMap="fuzzParams"> <select id="getFuzzParamsList" resultMap="fuzzParams">
<include refid="selectFuzzParams"/> <include refid="selectFuzzParams"/>
......
package com.example.fuzzbackendmaster.controller;
import com.example.fuzzbackendmaster.pojo.vo.AjaxResult;
import com.example.fuzzbackendmaster.pojo.vo.FuzzParams;
import com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/fuzzParams")
@Slf4j
public class FuzzParamsController {
@Autowired
FuzzIntegrationFileApi fuzzIntegrationFileApi;
/**
* 获取参数列表
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public AjaxResult list() {
try {
return AjaxResult.success(fuzzIntegrationFileApi.getFuzzParamsList());
} catch (Exception e) {
log.error("Get params of fuzz error:{}", e.getMessage());
return AjaxResult.error();
}
}
/**
* 跟据id获取参数
*/
@RequestMapping(value = "/getParam/{id}", method = RequestMethod.GET)
public AjaxResult getById(@PathVariable("id") int id) {
FuzzParams result;
try {
return AjaxResult.success(fuzzIntegrationFileApi.getFuzzParamById(id));
} catch (Exception e) {
log.error("Get params of fuzz with id error:{}", e.getMessage());
return AjaxResult.error();
}
}
/**
* 跟据id修改参数
*/
@RequestMapping(value = "/editParam", method = RequestMethod.POST)
public AjaxResult editById(@RequestBody FuzzParams fuzzParams) {
try {
return AjaxResult.success(fuzzIntegrationFileApi.editFuzzParams(fuzzParams));
} catch (Exception e) {
log.error("Edit params with id error:{}", e.getMessage());
return AjaxResult.error();
}
}
}
...@@ -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("/aflnet") @RequestMapping("/test")
@CrossOrigin @CrossOrigin
public class TestController { public class TestController {
@Autowired @Autowired
......
package com.example.fuzzbackendmaster.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@Data
@Getter
@Setter
public class FuzzParams {
private int id;
private String params;
@JsonFormat(pattern = "yyyy-MM-dd")
private Date editTime;
private int missionId;
public FuzzParams() {
}
public FuzzParams(int id, String params, Date editTime, int missionId) {
this.id = id;
this.params = params;
this.editTime = editTime;
this.missionId = missionId;
}
public FuzzParams(String params, Date editTime, int missionId) {
this.params = params;
this.editTime = editTime;
this.missionId = missionId;
}
public void setId(int id) {
this.id = id;
}
public int getMissionId() {
return missionId;
}
public void setMissionId(int missionId) {
this.missionId = missionId;
}
public void setParams(String params) {
this.params = params;
}
public void setEditTime(Date editTime) {
this.editTime = editTime;
}
public int getId() {
return id;
}
public String getParams() {
return params;
}
public Date getEditTime() {
return editTime;
}
}
package com.example.fuzzbackendmaster.service; package com.example.fuzzbackendmaster.service;
import com.example.fuzzbackendmaster.pojo.vo.AjaxResult; import com.example.fuzzbackendmaster.pojo.vo.*;
import com.example.fuzzbackendmaster.pojo.vo.CmdStartParams;
import com.example.fuzzbackendmaster.pojo.vo.FuzzLogTransEntity;
import com.example.fuzzbackendmaster.pojo.vo.TestEntity;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -84,4 +81,25 @@ public interface FuzzIntegrationFileApi { ...@@ -84,4 +81,25 @@ public interface FuzzIntegrationFileApi {
*/ */
@RequestMapping(value = "/mission/getList", method = RequestMethod.GET) @RequestMapping(value = "/mission/getList", method = RequestMethod.GET)
AjaxResult selectMissionInfoList(); AjaxResult selectMissionInfoList();
/**
* 查询测试参数
*/
@RequestMapping(value = "/fuzzParams/list", method = RequestMethod.GET)
AjaxResult getFuzzParamsList();
/**
* 跟据id查参数
* @param missionId
* @return
*/
@RequestMapping(value = "/fuzzParams/getParam/{missionId}", method = RequestMethod.GET)
AjaxResult getFuzzParamById(@PathVariable("missionId")int missionId);
/**
* 编辑参数
* @param fuzzParams
* @return
*/
@RequestMapping(value = "/fuzzParams/editParam", method = RequestMethod.POST)
AjaxResult editFuzzParams(FuzzParams fuzzParams);
} }
...@@ -20,4 +20,4 @@ spring: ...@@ -20,4 +20,4 @@ spring:
server-addr: http://${nacos-docker.ip}:8848 server-addr: http://${nacos-docker.ip}:8848
nacos-docker: nacos-docker:
ip: 192.168.50.247 ip: 192.168.50.251
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