Commit df2e1715 by 钱炳权

test

parent 35399eb8
......@@ -31,7 +31,6 @@ public class TestControler {
new Thread(new Runnable() {
@Override
public void run() {
log.info("aflnet start!");
service.testStart(cmdStartParams);
}
}).start();
......@@ -50,7 +49,6 @@ public class TestControler {
try {
service.testStop();
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("测试停止失败!");
}
return AjaxResult.success("测试停止成功!");
......
......@@ -25,12 +25,13 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
String cmd = parseParameters(testEntity);
if (cmd.isEmpty()) {
throw new FuzzException("cmd is null!");
throw new FuzzException("cmd is null ! The number of parameters does not match!");
}
return cmdTools.runProgramCmdAndResult(cmd);
}
public String parseParameters(TestEntity testEntity) {
try {
switch (testEntity.getTestClassName().toLowerCase()) {
case "foreach":
return cmd(testEntity, "-f");
......@@ -53,12 +54,14 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
case "trunc"://have error
return cmd(testEntity, "-u");
default:
log.error("未知变异方法![{}]", testEntity.getTestClassName());
return null;
throw new FuzzException("Unknown method !");
}
} catch (FuzzException e) {
throw new FuzzException("Unknown method !");
}
}
private String cmd(TestEntity testEntity, String cmd) {
private String cmd(TestEntity testEntity, String cmd) throws FuzzException {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 5, "generationMethod"))
return "";
String target_host = null;
......@@ -73,7 +76,7 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
s2 = testEntity.getParamJson()[3];
s3 = testEntity.getParamJson()[4];
} catch (Exception e) {
log.error("生成方法参数解析失败!");
throw new FuzzException("Parameter parsing failed !");
}
return kitty.getVenvPath() + " " + kitty.getMethodPath() + "generate_method_test.py " + cmd + " " + s1 + " " + s2 + " " + s3 + " --host=" + target_host + " --port=" + target_port;
}
......
......@@ -27,12 +27,13 @@ class MutationServiceImpl implements MutationService {
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
String cmd = parseParameters(testEntity);
if (cmd.isEmpty()) {
throw new FuzzException("cmd is null!");
throw new FuzzException("cmd is null ! The number of parameters does not match!");
}
return cmdTools.runProgramCmdAndResult(cmd);
}
public String parseParameters(TestEntity testEntity) {
try {
switch (testEntity.getTestClassName().toLowerCase()) {
case "bit":
return variationGranularityCmd(testEntity, 1);
......@@ -93,8 +94,10 @@ class MutationServiceImpl implements MutationService {
case "swapadjointwobytes":
return mutationStrategyCmd(testEntity, 10);
default:
log.error("未知变异方法![{}]", testEntity.getTestClassName());
return null;
throw new FuzzException("Unknown method!");
}
} catch (FuzzException e) {
throw new FuzzException("Count of params is not match or unknown protocol!");
}
}
......@@ -113,7 +116,7 @@ class MutationServiceImpl implements MutationService {
}
private String variationGranularityCmd(TestEntity testEntity, int methodNum) {
private String variationGranularityCmd(TestEntity testEntity, int methodNum) throws FuzzException {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "variationGranularity" + methodNum))
return "";
String dst_ip = null;
......@@ -122,10 +125,11 @@ class MutationServiceImpl implements MutationService {
dst_ip = testEntity.getParamJson()[0];
dst_port = testEntity.getParamJson()[1];
} catch (Exception e) {
log.error("variationGranularity [{}] 参数解析失败!", methodNum);
throw new FuzzException("Parameter parsing failed !");
}
return kitty.getVenvPath() + " " + kitty.getMutationPath() + MutationConstent.TEST_GRANULARITY_BIT_BYTE + " -g " + methodNum + " -d " + dst_ip + " -p " + dst_port;
}
private String mutationStrategyCmd(TestEntity testEntity, int methodNum) {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "mutationStrategy" + methodNum))
return "";
......
......@@ -27,7 +27,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
String cmd = parseParameters(testEntity);
if (cmd == null || cmd.equals("")) {
throw new FuzzException("cmd is null!");
throw new FuzzException("cmd is null ! The number of parameters does not match!");
}
return cmdTools.runProgramCmdAndResult(cmd);
}
......
......@@ -24,12 +24,13 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException, CmdException {
String cmd = parseParameters(testEntity);
if (cmd.isEmpty()) {
throw new FuzzException("cmd is null!");
throw new FuzzException("cmd is null ! The number of parameters does not match!");
}
return cmdTools.runProgramCmdAndResult(cmd);
}
public String parseParameters(TestEntity testEntity) {
try {
switch (testEntity.getTestClassName().toLowerCase()) {
case "array_index_out_of_bounds_vulnerabilit"://have error
return cmd(testEntity, 0);
......@@ -56,13 +57,14 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
case "sql_injection_vulnerabilit"://have error
return cmd(testEntity, 11);
default:
log.error("未知漏洞![{}]", testEntity.getTestClassName());
return null;
throw new FuzzException("Unknown method!");
}
} catch (FuzzException e) {
throw new FuzzException("Unknown class!");
}
}
private String cmd(TestEntity testEntity, int kindNum) {
return kitty.getVenvPath() + " " + kitty.getVulnerabilityTypePath() + "vul_types_test.py " + kindNum;
}
//todo 还有很多类型要写
}
......@@ -4,11 +4,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TestTools {
public static boolean paramsLenghtTest(int paramsLen,int needParamsLen,String name){
Boolean isOk = paramsLen==needParamsLen;
if(!isOk){
log.error("[{}]所需参数与获取参数不符!",name);
}
return isOk==true?true:false;
public static boolean paramsLenghtTest(int paramsLen, int needParamsLen, String name) {
Boolean isOk = paramsLen == needParamsLen;
return isOk == true ? true : false;
}
}
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