Commit e8df61c8 by 钱炳权

测试参数可存入

parent 5148ec7b
......@@ -36,11 +36,11 @@ public class FuzzParamsController {
/**
* 跟据id获取参数
*/
@RequestMapping(value = "/getParam/{id}", method = RequestMethod.GET)
public AjaxResult getById(@PathVariable("id") int id) {
@RequestMapping(value = "/getParam/{missionId}", method = RequestMethod.GET)
public AjaxResult getById(@PathVariable("missionId") int missionId) {
FuzzParams result;
try {
result = fuzzParamsService.getFuzzParamById(id);
result = fuzzParamsService.getFuzzParamById(missionId);
} catch (Exception e) {
log.error("Get params of fuzz with id error:{}", e.getMessage());
return AjaxResult.error();
......
......@@ -30,7 +30,6 @@ public class AlfnetController {
*/
@RequestMapping(value = "/testStart", method = RequestMethod.POST)
public AjaxResult start(@RequestBody final CmdStartParams cmdStartParams) {
//todo 捕获子线程错误
try {
SystemRunningParams.aflnetData.put("missionName", cmdStartParams.getProtopcol());
Thread subThread = new Thread(new Runnable() {
......
......@@ -43,7 +43,7 @@ public class KittyController {
public AjaxResult protocolTemplate(@RequestBody TestEntity testEntity) {
try {
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);
} catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage());
......@@ -58,7 +58,7 @@ public class KittyController {
public AjaxResult generate(@RequestBody TestEntity testEntity) {
try {
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);
} catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage());
......@@ -73,7 +73,7 @@ public class KittyController {
public AjaxResult mutation(@RequestBody TestEntity testEntity) {
try {
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);
} catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage());
......@@ -88,7 +88,7 @@ public class KittyController {
public AjaxResult vulnerability(@RequestBody TestEntity testEntity) {
try {
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);
} catch (CmdException | FuzzException e) {
log.error(e.getDefaultMessage());
......
......@@ -13,8 +13,61 @@ import java.util.Date;
@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 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;
@Mapper
@Component("FuzzParamsMapper")
public interface FuzzParamsMapper {
void saveFuzzParams(FuzzParams fuzzParams);
boolean saveFuzzParams(FuzzParams fuzzParams);
List<FuzzParams> getFuzzParamsList();
FuzzParams getFuzzParamsById(int id);
......
......@@ -8,7 +8,7 @@ import java.util.List;
public interface FuzzParamsService {
List<FuzzParams> getFuzzParamsList();
FuzzParams getFuzzParamById(int id);
FuzzParams getFuzzParamById(int missionId);
//todo 使用切面在运行时插入参数
boolean saveFuzzParams(FuzzParams fuzzParams);
......
......@@ -6,5 +6,5 @@ import java.util.List;
import java.util.Map;
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;
import java.util.Map;
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;
import java.util.Map;
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;
import java.util.Map;
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 {
}
@Override
public FuzzParams getFuzzParamById(int id) {
public FuzzParams getFuzzParamById(int missionId) {
FuzzParams fuzzParams = null;
try {
fuzzParams = fuzzParamsMapper.getFuzzParamsById(id);
fuzzParams = fuzzParamsMapper.getFuzzParamsById(missionId);
} catch (Exception e) {
log.error("FuzzParamsService.getFuzzParamById error:{}",e.getMessage());
throw new RuntimeException(e);
......@@ -43,7 +43,7 @@ public class FuzzParamsServiceImpl implements FuzzParamsService {
@Override
public boolean saveFuzzParams(FuzzParams fuzzParams) {
return false;
return fuzzParamsMapper.saveFuzzParams(fuzzParams);
}
@Override
......
package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore;
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.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
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.TestTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -22,10 +28,18 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
TestCmdTools cmdTools = new TestCmdTools();
@Autowired
KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override
@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);
if (cmd.isEmpty()) {
throw new FuzzException("cmd is null ! The number of parameters does not match!");
......
package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAfter;
import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.conf.KittyProperties;
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.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
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.TestTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -24,11 +30,18 @@ class MutationServiceImpl implements MutationService {
TestCmdTools cmdTools = new TestCmdTools();
@Autowired
KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override
@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);
if (cmd.isEmpty()) {
throw new FuzzException("cmd is null ! The number of parameters does not match!");
......
package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.constents.CmdConstent;
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.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
import com.example.fuzzControll.service.ProtocolTemplateService;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.SingleCmdTools;
......@@ -18,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -28,10 +33,18 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
TestCmdTools testCmdTools = new TestCmdTools();
@Autowired
KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override
@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");
String cmd = parseParameters(testEntity);
......
package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.conf.AflnetProperties;
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.CmdException;
import com.example.fuzzControll.domain.bo.CmdStartParams;
import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.service.FuzzParamsService;
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.TestControlTools;
import com.example.fuzzControll.tools.system.SystemRunningParams;
......@@ -30,10 +35,19 @@ public class TestServiceImpl implements TestService {
@Autowired
AflnetProperties aflnetProperties;
@Autowired
FuzzParamsService fuzzParamsService;
//todo 不同服务不同端口
@Override
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);
String cmd = cmdTools.parse(cmdStartParams);
......
package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson2.JSON;
import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore;
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.FuzzException;
import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.service.FuzzParamsService;
import com.example.fuzzControll.service.VulnerabilityTypeService;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.test.TestCmdTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -21,10 +27,17 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
TestCmdTools cmdTools = new TestCmdTools();
@Autowired
KittyProperties kitty;
@Autowired
FuzzParamsService fuzzParamsService;
@Override
@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);
if (cmd.isEmpty()) {
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:
discovery:
server-addr: http://${nacos-docker.ip}:8848
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
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
......@@ -49,10 +49,11 @@ integrationpath:
webSocketUri: ws://${fuzzmaster-docker.ip}:8101/websocket/testResult/
nacos-docker:
ip: 192.168.50.247
ip: 192.168.50.251
fuzzmaster-docker:
ip: 192.168.50.247
ip: 192.168.50.251
mysql-docker:
ip: 192.168.50.247
\ No newline at end of file
ip: 192.168.50.251
port: 3307
\ No newline at end of file
......@@ -5,6 +5,6 @@ spring:
active: dev #默认为开发环境
server:
port: 8103
port: 8104
......@@ -8,20 +8,21 @@
<result property="id" column="id" />
<result property="params" column="params" />
<result property="editTime" column="editTime" />
<result property="missionId" column="missionId" />
</resultMap>
<sql id="selectFuzzParams">
select id, params,editTime from fuzz_params
select id, params,editTime,missionId from fuzz_params
</sql>
<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>
<update id="editFuzzParams">
update fuzz_params set params = #{params} ,editTime = #{editTime} where missionId = #{missionId}
</update>
<select id="getFuzzParamsById" resultMap="fuzzParams">
<include refid="selectFuzzParams"/>
where id = #{id}
where missionId = #{missionId}
</select>
<select id="getFuzzParamsList" resultMap="fuzzParams">
<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.*;
*/
@Slf4j
@RestController
@RequestMapping("/aflnet")
@RequestMapping("/test")
@CrossOrigin
public class TestController {
@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;
import com.example.fuzzbackendmaster.pojo.vo.AjaxResult;
import com.example.fuzzbackendmaster.pojo.vo.CmdStartParams;
import com.example.fuzzbackendmaster.pojo.vo.FuzzLogTransEntity;
import com.example.fuzzbackendmaster.pojo.vo.TestEntity;
import com.example.fuzzbackendmaster.pojo.vo.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
......@@ -84,4 +81,25 @@ public interface FuzzIntegrationFileApi {
*/
@RequestMapping(value = "/mission/getList", method = RequestMethod.GET)
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:
server-addr: http://${nacos-docker.ip}:8848
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