Commit c96a10bd by 钱炳权

exception is chaged

parent 1c41f8b1
......@@ -27,19 +27,20 @@ public class KittyServerMessageController {
try {
return AjaxResult.success(getServerMessageService.getStats());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("stats信息获取失败!");
}
}
/**
* 获取服务器templateInfo信息
*/
//todo first
@RequestMapping(value = "/templateInfo", method = RequestMethod.GET)
public AjaxResult getTemplateInfo( ) {
try {
return AjaxResult.success(getServerMessageService.getTemplateInfo());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("templateInfo信息获取失败!");
}
}
......@@ -51,7 +52,7 @@ public class KittyServerMessageController {
try {
return AjaxResult.success(getServerMessageService.getStages());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("stages信息获取失败!");
}
}
......@@ -63,7 +64,7 @@ public class KittyServerMessageController {
try {
return AjaxResult.success(getServerMessageService.getReport());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("report信息获取失败!");
}
}
......
......@@ -33,7 +33,7 @@ public class SeedFileController {
try {
files = service.getSeedFiles();
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("种子文件获取失败!");
}
return AjaxResult.success(files);
......@@ -47,7 +47,7 @@ public class SeedFileController {
try {
service.delFile(fileName);
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("种子文件删除失败!");
}
return AjaxResult.success("种子文件删除成功!");
......@@ -60,7 +60,7 @@ public class SeedFileController {
try {
service.upload(file);
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("种子文件upload失败!");
}
return AjaxResult.success("种子文件upload成功!");
......
......@@ -6,18 +6,21 @@ import com.example.fuzzControll.service.GenerateMethodService;
import com.example.fuzzControll.service.MutationService;
import com.example.fuzzControll.service.ProtocolTemplateService;
import com.example.fuzzControll.service.VulnerabilityTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 不同类型的测试方法
*/
@Slf4j
@RestController
@RequestMapping("/testClass")
public class TestClassController {
......@@ -38,7 +41,8 @@ public class TestClassController {
Map<String, List<String>> result = protocolTemplateService.generation(testEntity);
return AjaxResult.success(result==null?"模板文件生成未成功运行":result);
} catch (Exception e) {
return AjaxResult.error("模板文件生成失败!");
log.error(e.getMessage());
return AjaxResult.error(e.getMessage());
}
}
......@@ -51,6 +55,7 @@ public class TestClassController {
Map<String, List<String>> result = generateMethodService.generation(testEntity);
return AjaxResult.success(result==null?"生成方法未成功运行":result);
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("生成方法使用失败!");
}
}
......@@ -64,6 +69,7 @@ public class TestClassController {
Map<String, List<String>> result = mutationService.generation(testEntity);
return AjaxResult.success(result==null?"mutationTest未成功运行":result);
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("mutationTest失败!");
}
}
......@@ -77,6 +83,7 @@ public class TestClassController {
Map<String, List<String>> result = vulnerabilityTypeService.generation(testEntity);
return AjaxResult.success(result==null?"漏洞类型未成功运行":result);
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("漏洞类型测试失败!");
}
}
......
......@@ -31,11 +31,12 @@ public class TestControler {
new Thread(new Runnable() {
@Override
public void run() {
log.info("aflnet start!");
service.testStart(cmdStartParams);
}
}).start();
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error(e.getMessage());
return AjaxResult.error("测试启动失败!");
}
return AjaxResult.success("测试启动成功!");
......@@ -49,6 +50,7 @@ public class TestControler {
try {
service.testStop();
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("测试停止失败!");
}
return AjaxResult.success("测试停止成功!");
......
......@@ -94,7 +94,6 @@ public class WebSocket {
public void appointSending(String sender, String name, String message) {
try {
// WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(sender + ":" + message);
WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(message);
......
......@@ -18,7 +18,7 @@ public class GetServerMessageImpl implements GetServerMessageService {
@Autowired
KittyProperties kitty;
public String getServerMsg(String messageName) throws ServerException{
public String getServerMsg(String messageName) {
switch (messageName) {
case "templateInfo": {
HttpGet httpGetTemplateInfo = new HttpGet(kitty.getTemplateInfoHttp());
......@@ -26,7 +26,6 @@ public class GetServerMessageImpl implements GetServerMessageService {
CloseableHttpResponse templateInfoResponse = httpClient.execute(httpGetTemplateInfo);) {
return EntityUtils.toString(templateInfoResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("templateInfo http error!");
throw new ServerException("get server templateInfo error !");
}
}
......@@ -36,7 +35,6 @@ public class GetServerMessageImpl implements GetServerMessageService {
CloseableHttpResponse statsResponse = httpClient.execute(httpGetStats);) {
return EntityUtils.toString(statsResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("stats http error!");
throw new ServerException("get server stats error !");
}
}
......@@ -46,7 +44,6 @@ public class GetServerMessageImpl implements GetServerMessageService {
CloseableHttpResponse reportResponse = httpClient.execute(httpGetStats);) {
return EntityUtils.toString(reportResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("report http error!");
throw new ServerException("get server report error !");
}
......@@ -57,7 +54,6 @@ public class GetServerMessageImpl implements GetServerMessageService {
CloseableHttpResponse stagesResponse = httpClient.execute(httpGetStats);) {
return EntityUtils.toString(stagesResponse.getEntity(), "utf-8");
} catch (Exception e) {
log.error("stages http error!");
throw new ServerException("get server stages error !");
}
}
......@@ -67,7 +63,7 @@ public class GetServerMessageImpl implements GetServerMessageService {
}
@Override
public String getStats() throws ServerException {
public String getStats() {
return getServerMsg("stats");
}
......
......@@ -26,15 +26,16 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
public Map<String, List<String>> generation(TestEntity testEntity) throws FuzzException {
String cmd = parseParameters(testEntity);
if (cmd.isEmpty()) {
return null;
throw new FuzzException("cmd is null!");
}
return cmdTools.runProgramCmdAndResult(cmd);
}
public String parseParameters(TestEntity testEntity) {
if(testEntity==null){
public String parseParameters(TestEntity testEntity) throws FuzzException {
if (testEntity == null) {
throw new FuzzException("testEntity is null!");
}
try {
switch (testEntity.getTestClassName().toLowerCase()) {
case "arp":
return arpCmd(testEntity);
......@@ -127,10 +128,14 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
return null;
//TODO testcase_dos/testcase_rpc/ftp_vuln_reproduce
}
} catch (Exception e) {
throw new FuzzException("Count of params is not match!");
}
}
private String tcpCmd(TestEntity testEntity) {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "tcp")){
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "tcp")) {
return "";
}
String dst_ip = null;
......@@ -141,11 +146,11 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
} catch (Exception e) {
log.error("tcp参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.TCP + " " + dst_ip + " " +src_ip;
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.TCP + " " + dst_ip + " " + src_ip;
}
private String udpCmd(TestEntity testEntity) {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "udp")){
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "udp")) {
return "";
}
String dst_ip = null;
......@@ -156,7 +161,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
} catch (Exception e) {
log.error("udp参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.UDP + " " + dst_ip + " " +src_ip;
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.UDP + " " + dst_ip + " " + src_ip;
}
private String tftpCmd(TestEntity testEntity) {
......@@ -230,7 +235,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
} catch (Exception e) {
log.error("https参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.HTTPS + " " + src_ip + " " + src_port+" " + dst_ip+" " + dst_port;
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.HTTPS + " " + src_ip + " " + src_port + " " + dst_ip + " " + dst_port;
}
private String ipsecCmd(TestEntity testEntity) {
......@@ -246,7 +251,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
} catch (Exception e) {
log.error("ipsec参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.IPSEC + " -s " + src_ip + " -d " + dst_ip+" -b " + bind_ip;
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.IPSEC + " -s " + src_ip + " -d " + dst_ip + " -b " + bind_ip;
}
private String pop3Cmd(TestEntity testEntity) {
......@@ -648,6 +653,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
return "";
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.HDLC;
}
//todo need change
private String ftpCmd(TestEntity testEntity) {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "ftp"))
......@@ -728,7 +734,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.BGP + src_ip + " " + src_port + " " + dst_ip + " " + dst_port;
}
public String arpCmd(TestEntity testEntity) throws FuzzException{
public String arpCmd(TestEntity testEntity) throws FuzzException {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "arp"))
return "";
String dst_mac = null;
......
......@@ -8,6 +8,7 @@ import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.exception.FuzzException;
import com.example.fuzzControll.pojo.vo.CmdStartParams;
import com.example.fuzzControll.pojo.vo.TestReturnEntity;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
......@@ -15,6 +16,7 @@ import java.util.*;
//todo need modify
@Slf4j
public class CmdTools {
Boolean send = false;
WebSocket socket = (WebSocket) SpringContextUtil.getBean("WebSocket");
......@@ -67,6 +69,7 @@ public class CmdTools {
printMessageByProgramCmd(process.getErrorStream(), error);
process.waitFor();
} catch (Exception e) {
log.error("aflnet run error!");
throw new FuzzException("run fuzz error !");
}
result.put("out", out);
......
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