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,40 +25,43 @@ public class GenerateMethodServiceImpl implements GenerateMethodService { ...@@ -25,40 +25,43 @@ 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) {
switch (testEntity.getTestClassName().toLowerCase()) { try {
case "foreach": switch (testEntity.getTestClassName().toLowerCase()) {
return cmd(testEntity, "-f"); case "foreach":
case "repeat": return cmd(testEntity, "-f");
return cmd(testEntity, "-r"); case "repeat":
case "oneof": return cmd(testEntity, "-r");
return cmd(testEntity, "-o"); case "oneof":
case "switch": return cmd(testEntity, "-o");
return cmd(testEntity, "-s"); case "switch":
case "pad": return cmd(testEntity, "-s");
return cmd(testEntity, "-p"); case "pad":
case "template": return cmd(testEntity, "-p");
return cmd(testEntity, "-t"); case "template":
case "meta": return cmd(testEntity, "-t");
return cmd(testEntity, "-m"); case "meta":
case "if": return cmd(testEntity, "-m");
return cmd(testEntity, "-c"); case "if":
case "ifnot": return cmd(testEntity, "-c");
return cmd(testEntity, "-e"); case "ifnot":
case "trunc"://have error return cmd(testEntity, "-e");
return cmd(testEntity, "-u"); case "trunc"://have error
default: return cmd(testEntity, "-u");
log.error("未知变异方法![{}]", testEntity.getTestClassName()); default:
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")) 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,74 +27,77 @@ class MutationServiceImpl implements MutationService { ...@@ -27,74 +27,77 @@ 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) {
switch (testEntity.getTestClassName().toLowerCase()) { try {
case "bit": switch (testEntity.getTestClassName().toLowerCase()) {
return variationGranularityCmd(testEntity, 1); case "bit":
case "byte": return variationGranularityCmd(testEntity, 1);
return variationGranularityCmd(testEntity, 2); case "byte":
case "sqlinjection": return variationGranularityCmd(testEntity, 2);
return distortionLibCmd(testEntity, 2); case "sqlinjection":
case "commandinjection": return distortionLibCmd(testEntity, 2);
return distortionLibCmd(testEntity, 1); case "commandinjection":
case "outofbuffer": return distortionLibCmd(testEntity, 1);
return distortionLibCmd(testEntity, 3); case "outofbuffer":
case "directorytraversal": return distortionLibCmd(testEntity, 3);
return distortionLibCmd(testEntity, 4); case "directorytraversal":
case "8-bitinteger": return distortionLibCmd(testEntity, 4);
return distortionLibCmd(testEntity, 5); case "8-bitinteger":
case "16-bitinteger": return distortionLibCmd(testEntity, 5);
return distortionLibCmd(testEntity, 6); case "16-bitinteger":
case "32-bitinteger": return distortionLibCmd(testEntity, 6);
return distortionLibCmd(testEntity, 7); case "32-bitinteger":
case "bitflip"://noresponse return distortionLibCmd(testEntity, 7);
return distortionLibCmd(testEntity, 8); case "bitflip"://noresponse
case "twobitflip"://noresponse return distortionLibCmd(testEntity, 8);
return distortionLibCmd(testEntity, 9); case "twobitflip"://noresponse
case "fourbitflip"://noresponse return distortionLibCmd(testEntity, 9);
return distortionLibCmd(testEntity, 10); case "fourbitflip"://noresponse
case "byteflip"://noresponse return distortionLibCmd(testEntity, 10);
return distortionLibCmd(testEntity, 11); case "byteflip"://noresponse
case "wordflip"://noresponse return distortionLibCmd(testEntity, 11);
return distortionLibCmd(testEntity, 12); case "wordflip"://noresponse
case "dwordflip"://noresponse return distortionLibCmd(testEntity, 12);
return distortionLibCmd(testEntity, 13); case "dwordflip"://noresponse
case "blockremove"://noresponse return distortionLibCmd(testEntity, 13);
return distortionLibCmd(testEntity, 14); case "blockremove"://noresponse
case "blockduplicate"://noresponse return distortionLibCmd(testEntity, 14);
return distortionLibCmd(testEntity, 15); case "blockduplicate"://noresponse
case "blockset"://noresponse return distortionLibCmd(testEntity, 15);
return distortionLibCmd(testEntity, 16); case "blockset"://noresponse
case "bitflips"://noresponse return distortionLibCmd(testEntity, 16);
return distortionLibCmd(testEntity, 17); case "bitflips"://noresponse
case "byteflips": return distortionLibCmd(testEntity, 17);
return mutationStrategyCmd(testEntity, 1); case "byteflips":
case "interestint8muta": return mutationStrategyCmd(testEntity, 1);
return mutationStrategyCmd(testEntity, 2); case "interestint8muta":
case "interestint16muta": return mutationStrategyCmd(testEntity, 2);
return mutationStrategyCmd(testEntity, 3); case "interestint16muta":
case "interestint32muta": return mutationStrategyCmd(testEntity, 3);
return mutationStrategyCmd(testEntity, 4); case "interestint32muta":
case "onebyterndom": return mutationStrategyCmd(testEntity, 4);
return mutationStrategyCmd(testEntity, 5); case "onebyterndom":
case "mutibytesrandom": return mutationStrategyCmd(testEntity, 5);
return mutationStrategyCmd(testEntity, 6); case "mutibytesrandom":
case "deleteonebyterandom": return mutationStrategyCmd(testEntity, 6);
return mutationStrategyCmd(testEntity, 7); case "deleteonebyterandom":
case "deletemutibytesrandom": return mutationStrategyCmd(testEntity, 7);
return mutationStrategyCmd(testEntity, 8); case "deletemutibytesrandom":
case "shufflebytesrandom": return mutationStrategyCmd(testEntity, 8);
return mutationStrategyCmd(testEntity, 9); case "shufflebytesrandom":
case "swapadjointwobytes": return mutationStrategyCmd(testEntity, 9);
return mutationStrategyCmd(testEntity, 10); case "swapadjointwobytes":
default: return mutationStrategyCmd(testEntity, 10);
log.error("未知变异方法![{}]", testEntity.getTestClassName()); default:
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 { ...@@ -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,45 +24,47 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService { ...@@ -24,45 +24,47 @@ 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) {
switch (testEntity.getTestClassName().toLowerCase()) { try {
case "array_index_out_of_bounds_vulnerabilit"://have error switch (testEntity.getTestClassName().toLowerCase()) {
return cmd(testEntity, 0); case "array_index_out_of_bounds_vulnerabilit"://have error
case "boundary_condition_vulnerability"://have error return cmd(testEntity, 0);
return cmd(testEntity, 1); case "boundary_condition_vulnerability"://have error
case "buffer_overflow_vulnerability"://have error return cmd(testEntity, 1);
return cmd(testEntity, 2); case "buffer_overflow_vulnerability"://have error
case "command_injection_vulnerability"://have error return cmd(testEntity, 2);
return cmd(testEntity, 3); case "command_injection_vulnerability"://have error
case "memory_duplicate_release_vulnerability"://have error return cmd(testEntity, 3);
return cmd(testEntity, 4); case "memory_duplicate_release_vulnerability"://have error
case "format_string_vulnerability"://have error return cmd(testEntity, 4);
return cmd(testEntity, 5); case "format_string_vulnerability"://have error
case "integer_overflow_vulnerability"://have error return cmd(testEntity, 5);
return cmd(testEntity, 6); case "integer_overflow_vulnerability"://have error
case "numeric_error_vulnerabilit"://have error return cmd(testEntity, 6);
return cmd(testEntity, 7); case "numeric_error_vulnerabilit"://have error
case "symbol_extension_vulnerability"://have error return cmd(testEntity, 7);
return cmd(testEntity, 8); case "symbol_extension_vulnerability"://have error
case "uaf_vulnerabilit"://have error return cmd(testEntity, 8);
return cmd(testEntity, 9); case "uaf_vulnerabilit"://have error
case "cross_script_vulnerability"://have error return cmd(testEntity, 9);
return cmd(testEntity, 10); case "cross_script_vulnerability"://have error
case "sql_injection_vulnerabilit"://have error return cmd(testEntity, 10);
return cmd(testEntity, 11); case "sql_injection_vulnerabilit"://have error
default: return cmd(testEntity, 11);
log.error("未知漏洞![{}]", testEntity.getTestClassName()); default:
return null; throw new FuzzException("Unknown method!");
}
} 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