Commit df2e1715 by 钱炳权

test

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