Commit 4f11b8a8 by 钱炳权

24/4/2 class of testOutput is ok

parent 91c7e11d
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
</dependency> </dependency>
......
...@@ -10,6 +10,43 @@ public class kittyProperties { ...@@ -10,6 +10,43 @@ public class kittyProperties {
String venvPath; String venvPath;
String methodPath; String methodPath;
String vulnerabilityTypePath; String vulnerabilityTypePath;
String templateInfoHttp;
String statsHttp;
String stagesHttp;
String reportHttp;
public String getTemplateInfoHttp() {
return templateInfoHttp;
}
public void setTemplateInfoHttp(String templateInfoHttp) {
this.templateInfoHttp = templateInfoHttp;
}
public String getStatsHttp() {
return statsHttp;
}
public void setStatsHttp(String statsHttp) {
this.statsHttp = statsHttp;
}
public String getStagesHttp() {
return stagesHttp;
}
public void setStagesHttp(String stagesHttp) {
this.stagesHttp = stagesHttp;
}
public String getReportHttp() {
return reportHttp;
}
public void setReportHttp(String reportHttp) {
this.reportHttp = reportHttp;
}
public String getPath() { public String getPath() {
return path; return path;
} }
......
package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.service.getServerMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/kittyServer")
public class kittyServerMessageController {
@Autowired
getServerMessageService getServerMessageService;
/**
* 获取服务器stats信息
*/
@RequestMapping(value = "/stats", method = RequestMethod.GET)
public AjaxResult getStats( ) {
try {
return AjaxResult.success(getServerMessageService.getStats());
} catch (Exception e) {
return AjaxResult.error("stats信息获取失败!");
}
}
/**
* 获取服务器templateInfo信息
*/
@RequestMapping(value = "/templateInfo", method = RequestMethod.GET)
public AjaxResult getTemplateInfo( ) {
try {
return AjaxResult.success(getServerMessageService.getTemplateInfo());
} catch (Exception e) {
return AjaxResult.error("templateInfo信息获取失败!");
}
}
/**
* 获取服务器stages信息
*/
@RequestMapping(value = "/stages", method = RequestMethod.GET)
public AjaxResult getStages( ) {
try {
return AjaxResult.success(getServerMessageService.getStages());
} catch (Exception e) {
return AjaxResult.error("stats信息获取失败!");
}
}
/**
* 获取服务器report信息
*/
@RequestMapping(value = "/report", method = RequestMethod.GET)
public AjaxResult getReport( ) {
try {
return AjaxResult.success(getServerMessageService.getReport());
} catch (Exception e) {
return AjaxResult.error("stats信息获取失败!");
}
}
}
package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.service.getServerMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/mutation")
public class mutationController {
@Autowired
getServerMessageService getServerMessageService;
@RequestMapping(value = "/mutation", method = RequestMethod.POST)
public AjaxResult getStats() {
try {
return AjaxResult.success(getServerMessageService.getStats());
} catch (Exception e) {
return AjaxResult.error("mutationTest失败!");
}
}
}
package com.example.fuzzControll.controller; package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult; import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.service.protocolTemplateService; import com.example.fuzzControll.service.protocolTemplateService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController @RestController
@RequestMapping("/protocolTemplate") @RequestMapping("/protocolTemplate")
...@@ -20,12 +19,11 @@ public class protocolTemplatController { ...@@ -20,12 +19,11 @@ public class protocolTemplatController {
* seeFileUpload * seeFileUpload
*/ */
@RequestMapping(value = "/generation", method = RequestMethod.POST) @RequestMapping(value = "/generation", method = RequestMethod.POST)
public AjaxResult upload(@RequestBody protocolGenerationEntity protocolGeneration) { public AjaxResult upload(@RequestBody testEntity testEntity) {
try { try {
protocolTemplateService.generation(protocolGeneration); return AjaxResult.success(protocolTemplateService.generation(testEntity));
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error("模板文件生成失败!"); return AjaxResult.error("模板文件生成失败!");
} }
return AjaxResult.success("模板文件生成成功!");
} }
} }
package com.example.fuzzControll.controller; package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult; import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.generateMethodEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import com.example.fuzzControll.service.generateMethodService; import com.example.fuzzControll.service.generateMethodService;
import com.example.fuzzControll.service.getServerMessageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -11,18 +11,28 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -11,18 +11,28 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/generateMethod") @RequestMapping("/testClass")
public class generateMethodController { public class testClassController {
@Autowired @Autowired
generateMethodService service; generateMethodService service;
@Autowired
getServerMessageService getServerMessageService;
@RequestMapping(value = "/generate", method = RequestMethod.POST) @RequestMapping(value = "/generate", method = RequestMethod.POST)
public AjaxResult upload(@RequestBody generateMethodEntity generateMethodEntity) { public AjaxResult upload(@RequestBody testEntity testEntity) {
try { try {
return AjaxResult.success(service.generation(generateMethodEntity)); return AjaxResult.success(service.generation(testEntity));
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error("变异方法使用失败!"); return AjaxResult.error("变异方法使用失败!");
} }
} }
@RequestMapping(value = "/mutation", method = RequestMethod.POST)
public AjaxResult getStats() {
try {
return AjaxResult.success(getServerMessageService.getStats());
} catch (Exception e) {
return AjaxResult.error("mutationTest失败!");
}
}
} }
package com.example.fuzzControll.controller; package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult; import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.generateMethodEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.pojo.vo.vulnerabilityTypeEntity;
import com.example.fuzzControll.service.testService;
import com.example.fuzzControll.service.vulnerabilityTypeService; import com.example.fuzzControll.service.vulnerabilityTypeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -18,12 +16,11 @@ public class vulnerabilityTypeController { ...@@ -18,12 +16,11 @@ public class vulnerabilityTypeController {
vulnerabilityTypeService service; vulnerabilityTypeService service;
@RequestMapping(value = "/generate", method = RequestMethod.POST) @RequestMapping(value = "/generate", method = RequestMethod.POST)
public AjaxResult upload(@RequestBody vulnerabilityTypeEntity vulnerabilityTypeEntity) { public AjaxResult upload(@RequestBody testEntity testEntity) {
try { try {
service.generation(vulnerabilityTypeEntity); return AjaxResult.success(service.generation(testEntity));
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error("漏洞类型测试失败!"); return AjaxResult.error("漏洞类型测试失败!");
} }
return AjaxResult.success("漏洞类型测试成功!");
} }
} }
package com.example.fuzzControll.pojo.vo;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Getter
@Setter
public class protocolGenerationEntity {
String protocolName;
String[] paramJson;
}
...@@ -5,9 +5,9 @@ import lombok.Getter; ...@@ -5,9 +5,9 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@Data @Data
@Setter
@Getter @Getter
public class generateMethodEntity { @Setter
String methodName; public class testEntity {
String testClassName;
String[] paramJson; String[] paramJson;
} }
package com.example.fuzzControll.pojo.vo;
import lombok.Data;
@Data
public class vulnerabilityTypeEntity {
String vulnerabilityTypeName;
String[] paramJson;
}
package com.example.fuzzControll.service; package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.generateMethodEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import java.util.List; import java.util.List;
import java.util.Map;
public interface generateMethodService { public interface generateMethodService {
List<String> generation(generateMethodEntity generateMethodEntity); Map<String,List<String>> generation(testEntity testEntity);
} }
package com.example.fuzzControll.service;
import java.util.List;
import java.util.Map;
public interface getServerMessageService {
String getStats();
String getTemplateInfo();
String getStages();
String getReport();
}
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.kittyProperties; import com.example.fuzzControll.conf.kittyProperties;
import com.example.fuzzControll.pojo.vo.generateMethodEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import com.example.fuzzControll.service.generateMethodService; import com.example.fuzzControll.service.generateMethodService;
import com.example.fuzzControll.tools.cmdTools; import com.example.fuzzControll.tools.cmdTools;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -10,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@Slf4j @Slf4j
...@@ -19,33 +19,33 @@ public class generateMethodServiceImpl implements generateMethodService { ...@@ -19,33 +19,33 @@ public class generateMethodServiceImpl implements generateMethodService {
kittyProperties kitty; kittyProperties kitty;
@Override @Override
public List<String> generation(generateMethodEntity generateMethodEntity) { public Map<String,List<String>> generation(testEntity testEntity) {
String cmd = parseParameters(generateMethodEntity); String cmd = parseParameters(testEntity);
return cmdTools.runProgramCmdAndResultTofile(cmd); return cmdTools.runProgramCmdAndResult(cmd);
} }
public String parseParameters(generateMethodEntity generateMethodEntity) { public String parseParameters(testEntity testEntity) {
switch (generateMethodEntity.getMethodName().toLowerCase()) { switch (testEntity.getTestClassName().toLowerCase()) {
case "foreach": case "foreach":
return foreachCmd(generateMethodEntity); return foreachCmd(testEntity);
default: default:
log.error("未知变异方法![{}]", generateMethodEntity.getMethodName()); log.error("未知变异方法![{}]", testEntity.getTestClassName());
return null; return null;
} }
} }
private String foreachCmd(generateMethodEntity generateMethodEntity) { private String foreachCmd(testEntity testEntity) {
String target_host = null; String target_host = null;
String target_port = null; String target_port = null;
String s1 = null; String s1 = null;
String s2 = null; String s2 = null;
String s3 = null; String s3 = null;
try { try {
target_host = generateMethodEntity.getParamJson()[0]; target_host = testEntity.getParamJson()[0];
target_port = generateMethodEntity.getParamJson()[1]; target_port = testEntity.getParamJson()[1];
s1 = generateMethodEntity.getParamJson()[2]; s1 = testEntity.getParamJson()[2];
s2 = generateMethodEntity.getParamJson()[3]; s2 = testEntity.getParamJson()[3];
s3 = generateMethodEntity.getParamJson()[4]; s3 = testEntity.getParamJson()[4];
} catch (Exception e) { } catch (Exception e) {
log.error("http_dos_qemu参数解析失败!"); log.error("http_dos_qemu参数解析失败!");
} }
......
package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.kittyProperties;
import com.example.fuzzControll.service.getServerMessageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service("getServerMessageService")
public class getServerMessageImpl implements getServerMessageService {
@Autowired
kittyProperties kitty;
public String getServerMsg(String messageName) {
switch (messageName) {
case "templateInfo": {
HttpGet httpGetTemplateInfo = new HttpGet(kitty.getTemplateInfoHttp());
try (CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse templateInfoResponse = httpClient.execute(httpGetTemplateInfo);) {
return EntityUtils.toString(templateInfoResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("templateInfo http error!");
}
}
case "stats": {
HttpGet httpGetStats = new HttpGet(kitty.getStatsHttp());
try (CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse statsResponse = httpClient.execute(httpGetStats);) {
return EntityUtils.toString(statsResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("stats http error!");
}
}
case "report": {
HttpGet httpGetStats = new HttpGet(kitty.getReportHttp());
try (CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse reportResponse = httpClient.execute(httpGetStats);) {
return EntityUtils.toString(reportResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("report http error!");
}
}
case "stages": {
HttpGet httpGetStats = new HttpGet(kitty.getStagesHttp());
try (CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse stagesResponse = httpClient.execute(httpGetStats);) {
return EntityUtils.toString(stagesResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("stages http error!");
}
}
default:
return "";
}
}
@Override
public String getStats() {
return getServerMsg("stats");
}
@Override
public String getTemplateInfo() {
return getServerMsg("templateInfo");
}
@Override
public String getStages() {
return getServerMsg("report");
}
@Override
public String getReport() {
return getServerMsg("stages");
}
}
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.conf.kittyProperties; import com.example.fuzzControll.conf.kittyProperties;
import com.example.fuzzControll.conf.seedProperties;
import com.example.fuzzControll.constents.protocolConstent; import com.example.fuzzControll.constents.protocolConstent;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.service.protocolTemplateService; import com.example.fuzzControll.service.protocolTemplateService;
import com.example.fuzzControll.tools.cmdTools; import com.example.fuzzControll.tools.cmdTools;
import com.fasterxml.jackson.databind.ObjectMapper;
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.List; import java.util.List;
import java.util.Map;
@Slf4j @Slf4j
@Service @Service
...@@ -24,13 +21,13 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -24,13 +21,13 @@ public class protocolTemplateImpl implements protocolTemplateService {
kittyProperties kitty; kittyProperties kitty;
@Override @Override
public void generation(protocolGenerationEntity protocolGeneration) { public Map<String,List<String>> generation(testEntity testEntity) {
String cmd = parseParameters(protocolGeneration); String cmd = parseParameters(testEntity);
cmdTools.runProgramCmdAndResultTofile(cmd); return cmdTools.runProgramCmdAndResult(cmd);
} }
public String parseParameters(protocolGenerationEntity protocolGeneration) { public String parseParameters(testEntity protocolGeneration) {
switch (protocolGeneration.getProtocolName().toLowerCase()) { switch (protocolGeneration.getTestClassName().toLowerCase()) {
case "arp": case "arp":
return arpCmd(protocolGeneration); return arpCmd(protocolGeneration);
case "bgp": case "bgp":
...@@ -48,12 +45,12 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -48,12 +45,12 @@ public class protocolTemplateImpl implements protocolTemplateService {
case "http_dos_qemu": case "http_dos_qemu":
return http_dos_qemuCmd(protocolGeneration); return http_dos_qemuCmd(protocolGeneration);
default: default:
log.error("未知协议![{}]", protocolGeneration.getProtocolName()); log.error("未知协议![{}]", protocolGeneration.getTestClassName());
return null; return null;
} }
} }
private String http_dos_qemuCmd(protocolGenerationEntity protocolGeneration) { private String http_dos_qemuCmd(testEntity protocolGeneration) {
String dst_ip = null; String dst_ip = null;
String port = null; String port = null;
try { try {
...@@ -65,11 +62,11 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -65,11 +62,11 @@ public class protocolTemplateImpl implements protocolTemplateService {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.HTTP_DOS_QUMU + " -d " + dst_ip + " -p " + port; return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.HTTP_DOS_QUMU + " -d " + dst_ip + " -p " + port;
} }
private String hdlcCmd(protocolGenerationEntity protocolGeneration) { private String hdlcCmd(testEntity protocolGeneration) {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.HDLC; return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.HDLC;
} }
private String ftpCmd(protocolGenerationEntity protocolGeneration) { private String ftpCmd(testEntity protocolGeneration) {
String target_host = null; String target_host = null;
String target_port = null; String target_port = null;
try { try {
...@@ -81,7 +78,7 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -81,7 +78,7 @@ public class protocolTemplateImpl implements protocolTemplateService {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.FTP + target_host + " " + target_port; return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.FTP + target_host + " " + target_port;
} }
private String frpCmd(protocolGenerationEntity protocolGeneration) { private String frpCmd(testEntity protocolGeneration) {
String target_host = null; String target_host = null;
String target_port = null; String target_port = null;
try { try {
...@@ -93,7 +90,7 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -93,7 +90,7 @@ public class protocolTemplateImpl implements protocolTemplateService {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.FRP + target_host + " " + target_port; return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.FRP + target_host + " " + target_port;
} }
private String dnsCmd(protocolGenerationEntity protocolGeneration) { private String dnsCmd(testEntity protocolGeneration) {
String dst_ip = null; String dst_ip = null;
String dst_port = null; String dst_port = null;
try { try {
...@@ -105,7 +102,7 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -105,7 +102,7 @@ public class protocolTemplateImpl implements protocolTemplateService {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.DNS + dst_ip + " " + dst_port; return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.DNS + dst_ip + " " + dst_port;
} }
private String dhcpCmd(protocolGenerationEntity protocolGeneration) { private String dhcpCmd(testEntity protocolGeneration) {
String dst_ip = null; String dst_ip = null;
String dst_port = null; String dst_port = null;
try { try {
...@@ -117,7 +114,7 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -117,7 +114,7 @@ public class protocolTemplateImpl implements protocolTemplateService {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.DHCP + dst_ip + " " + dst_port; return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.DHCP + dst_ip + " " + dst_port;
} }
private String bgpCmd(protocolGenerationEntity protocolGeneration) { private String bgpCmd(testEntity protocolGeneration) {
String src_ip = null; String src_ip = null;
String src_port = null; String src_port = null;
String dst_ip = null; String dst_ip = null;
...@@ -133,7 +130,7 @@ public class protocolTemplateImpl implements protocolTemplateService { ...@@ -133,7 +130,7 @@ public class protocolTemplateImpl implements protocolTemplateService {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.BGP + src_ip + " " + src_port + " " + dst_ip + " " + dst_port; return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.BGP + src_ip + " " + src_port + " " + dst_ip + " " + dst_port;
} }
public String arpCmd(protocolGenerationEntity protocolGeneration) { public String arpCmd(testEntity protocolGeneration) {
String dst_mac = null; String dst_mac = null;
String src_mac = null; String src_mac = null;
try { try {
......
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.kittyProperties; import com.example.fuzzControll.conf.kittyProperties;
import com.example.fuzzControll.constents.protocolConstent;
import com.example.fuzzControll.constents.vulnerabilityTypeConstent; import com.example.fuzzControll.constents.vulnerabilityTypeConstent;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.pojo.vo.vulnerabilityTypeEntity;
import com.example.fuzzControll.service.vulnerabilityTypeService; import com.example.fuzzControll.service.vulnerabilityTypeService;
import com.example.fuzzControll.tools.cmdTools; import com.example.fuzzControll.tools.cmdTools;
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.List;
import java.util.Map;
@Slf4j @Slf4j
@Service("vulnerabilityTypeService") @Service("vulnerabilityTypeService")
public class vulnerabilityTypeServiceImpl implements vulnerabilityTypeService { public class vulnerabilityTypeServiceImpl implements vulnerabilityTypeService {
...@@ -19,22 +20,22 @@ public class vulnerabilityTypeServiceImpl implements vulnerabilityTypeService { ...@@ -19,22 +20,22 @@ public class vulnerabilityTypeServiceImpl implements vulnerabilityTypeService {
kittyProperties kitty; kittyProperties kitty;
@Override @Override
public void generation(vulnerabilityTypeEntity vulnerabilityTypeEntity) { public Map<String, List<String>> generation(testEntity testEntity) {
String cmd = parseParameters(vulnerabilityTypeEntity); String cmd = parseParameters(testEntity);
cmdTools.runProgramCmdAndResultTofile(cmd); return cmdTools.runProgramCmdAndResult(cmd);
} }
public String parseParameters(vulnerabilityTypeEntity vulnerabilityTypeEntity) { public String parseParameters(testEntity testEntity) {
switch (vulnerabilityTypeEntity.getVulnerabilityTypeName().toLowerCase()) { switch (testEntity.getTestClassName().toLowerCase()) {
case "array_index_out_of_bounds_vulnerabilit": case "array_index_out_of_bounds_vulnerabilit":
return arrayIndexOutOfBoundsVulnerabilitCmd(vulnerabilityTypeEntity); return arrayIndexOutOfBoundsVulnerabilitCmd(testEntity);
default: default:
log.error("未知漏洞![{}]", vulnerabilityTypeEntity.getVulnerabilityTypeName()); log.error("未知漏洞![{}]", testEntity.getTestClassName());
return null; return null;
} }
} }
private String arrayIndexOutOfBoundsVulnerabilitCmd(vulnerabilityTypeEntity vulnerabilityTypeEntity) { private String arrayIndexOutOfBoundsVulnerabilitCmd(testEntity testEntity) {
return kitty.getVenvPath() + " " + kitty.getVulnerabilityTypePath() +"vul_types_test.py "+ vulnerabilityTypeConstent.ARRAY_INDEX_OUT_OF_BOUNDS_VULNERABILIT ; return kitty.getVenvPath() + " " + kitty.getVulnerabilityTypePath() +"vul_types_test.py "+ vulnerabilityTypeConstent.ARRAY_INDEX_OUT_OF_BOUNDS_VULNERABILIT ;
} }
//todo 还有很多类型要写 //todo 还有很多类型要写
......
package com.example.fuzzControll.service; package com.example.fuzzControll.service;
import com.alibaba.fastjson.JSONObject; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import org.springframework.web.multipart.MultipartFile; import java.util.List;
import java.util.Map;
public interface protocolTemplateService { public interface protocolTemplateService {
void generation(protocolGenerationEntity protocolGeneration); Map<String,List<String>> generation(testEntity testEntity);
} }
package com.example.fuzzControll.service; package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity; import com.example.fuzzControll.pojo.vo.testEntity;
import com.example.fuzzControll.pojo.vo.vulnerabilityTypeEntity;
import java.util.List;
import java.util.Map;
public interface vulnerabilityTypeService { public interface vulnerabilityTypeService {
void generation(vulnerabilityTypeEntity vulnerabilityTypeEntity); Map<String, List<String>> generation(testEntity testEntity);
} }
...@@ -8,8 +8,8 @@ import com.example.fuzzControll.pojo.vo.testReturnEntity; ...@@ -8,8 +8,8 @@ import com.example.fuzzControll.pojo.vo.testReturnEntity;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.*;
import java.util.List;
//todo need modify //todo need modify
public class cmdTools { public class cmdTools {
...@@ -54,20 +54,24 @@ public class cmdTools { ...@@ -54,20 +54,24 @@ public class cmdTools {
* 运行需要后台运行cmd * 运行需要后台运行cmd
* 将数据存入文件中 * 将数据存入文件中
*/ */
public List<String> runProgramCmdAndResultTofile(String cmd) { public Map<String, List<String>> runProgramCmdAndResult(String cmd) {
List<String> result = new ArrayList<>(); Map<String, List<String>> result = new HashMap();
List<String> out = Collections.synchronizedList(new ArrayList<>());
List<String> error = Collections.synchronizedList(new ArrayList<>());
try { try {
Process process = Runtime.getRuntime().exec(cmd); Process process = Runtime.getRuntime().exec(cmd);
printMessageToFile(process.getInputStream(), result); printMessageByProgramCmd(process.getInputStream(), out);
printMessageToFile(process.getErrorStream(), new ArrayList<String>()); printMessageByProgramCmd(process.getErrorStream(), error);
process.waitFor(); process.waitFor();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
result.put("out", out);
result.put("error", error);
return result; return result;
} }
private List<String> printMessageToFile(InputStream input, List<String> result) { private List<String> printMessageByProgramCmd(InputStream input, List<String> result) throws InterruptedException {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -108,21 +112,6 @@ public class cmdTools { ...@@ -108,21 +112,6 @@ public class cmdTools {
} }
private void printMessageToWeb(final InputStream input, Process process) throws IOException { private void printMessageToWeb(final InputStream input, Process process) throws IOException {
// try (FileOutputStream outputStream = new FileOutputStream("/home/qbq/1.text");
// BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);) {
//
// byte[] buffer = new byte[1024];
// int bytesRead;
// while ((bytesRead = input.read(buffer)) != -1) {
// bufferedOutputStream.write(buffer, 0, bytesRead);
// }
// if (testControlTools.getIsRunning()) {
// process.destroy();
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
Reader reader = new InputStreamReader(input); Reader reader = new InputStreamReader(input);
BufferedReader bf = new BufferedReader(reader); BufferedReader bf = new BufferedReader(reader);
String line = null; String line = null;
...@@ -265,4 +254,5 @@ public class cmdTools { ...@@ -265,4 +254,5 @@ public class cmdTools {
} }
return cmd.toString(); return cmd.toString();
} }
} }
\ No newline at end of file
...@@ -20,4 +20,8 @@ kitty: ...@@ -20,4 +20,8 @@ kitty:
path: "/home/qbq/fuzz50/kitty/renix/" #kitty项目下的各协议生成模板python文件路径 path: "/home/qbq/fuzz50/kitty/renix/" #kitty项目下的各协议生成模板python文件路径
venvPath: "/home/qbq/fuzz50/kitty/venv/bin/python" venvPath: "/home/qbq/fuzz50/kitty/venv/bin/python"
methodPath: "/home/qbq/fuzz50/kitty/2020test/"#kitty下变异方法路径 methodPath: "/home/qbq/fuzz50/kitty/2020test/"#kitty下变异方法路径
vulnerabilityTypePath: "/home/qbq/fuzz50/kitty/2020test/"#kitty下漏洞类型python路径 vulnerabilityTypePath: "/home/qbq/fuzz50/kitty/2020test/"#kitty下漏洞类型python路径
\ No newline at end of file templateInfoHttp: "http://127.0.0.1:26001/api/template_info.json"#模板信息请求链接
statsHttp: "http://127.0.0.1:26001/api/stats.json"#运行时数据
stagesHttp: "http://127.0.0.1:26001/api/stages.json"#
reportHttp: "http://127.0.0.1:26001/api/report"#
\ No newline at end of file
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