Commit 2b6461e2 by 钱炳权

ssh至服务器并成功调用服务

parent 336793c0
package com.example.fuzzControll.constents;
public class AlgorithmOneCmd {
public static final String ALFNET_PATH = "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz ";//aflnet服务启动路径
public static final String ALFNET_INPUT_PATH=" -i /home/lddc/SHENYANLONG";//aflnet种子根路径
public static final String ALFNET_OUTPUT_PATH=" -o /home/lddc/SHENYANLONG";//aflnet种子根路径
}
......@@ -4,9 +4,8 @@ import com.example.fuzzControll.exception.AflnetException;
import com.example.fuzzControll.exception.BaseException;
import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.CmdStartParams;
import com.example.fuzzControll.pojo.vo.AlgorithmOneCmdParams;
import com.example.fuzzControll.service.TestService;
import com.example.fuzzControll.tools.GlobalParameters;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -25,17 +24,16 @@ public class AlfnetController {
TestService service;
/**
* 测试启动
* 算法1 有参数型
*/
@RequestMapping(value = "/testStart", method = RequestMethod.POST)
public AjaxResult start(@RequestBody final CmdStartParams cmdStartParams) {
System.out.println(cmdStartParams);
//todo 捕获子线程错误
@RequestMapping(value = "/algorithmOneStart", method = RequestMethod.POST)
public AjaxResult algorithmOneStart(@RequestBody final AlgorithmOneCmdParams algorithmOneCmdParams) {
System.out.println(algorithmOneCmdParams);
try {
new Thread(new Runnable() {
@Override
public void run() {
service.testStart(cmdStartParams);
service.algorithmOneStart(algorithmOneCmdParams);
}
}).start();
} catch (Exception e) {
......@@ -48,6 +46,28 @@ public class AlfnetController {
}
/**
* 算法2 无参数型
*/
@RequestMapping(value = "/algorithmTwoStart", method = RequestMethod.POST)
public AjaxResult algorithmTwoStart(@RequestBody final AlgorithmOneCmdParams algorithmOneCmdParams) {
System.out.println(algorithmOneCmdParams);
//todo 捕获子线程错误
try {
new Thread(new Runnable() {
@Override
public void run() {
service.algorithmTwoStart(algorithmOneCmdParams);
}
}).start();
} catch (Exception e) {
if (e instanceof AflnetException || e instanceof CmdException) {
log.error(((BaseException) e).getDefaultMessage());
}
return AjaxResult.error("测试启动失败!");
}
return AjaxResult.success("测试已启动!");
}
/**
* 测试停止
*/
@RequestMapping(value = "/testStop", method = RequestMethod.GET)
......
package com.example.fuzzControll.pojo.vo;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Getter
@Setter
public class AlgorithmOneCmdParams {
String netinfo; //netInfo
String protopcol; //protocol
int waiting; //usec
String nsname;//netnsname
Boolean kill;
Boolean awareMode;
Boolean regionMutationOperators;
Boolean falseNegativeMode;
String script;//script
int stateSelectionAlgo;
int seedSelectionAlgo;
String trainedModelInputPath;
@Override
public String toString() {
return "AlgorithmTwoCmdParams{" +
"netinfo='" + netinfo + '\'' +
", protopcol='" + protopcol + '\'' +
", waiting=" + waiting +
", nsname='" + nsname + '\'' +
", kill=" + kill +
", awareMode=" + awareMode +
", regionMutationOperators=" + regionMutationOperators +
", falseNegativeMode=" + falseNegativeMode +
", script='" + script + '\'' +
", stateSelectionAlgo=" + stateSelectionAlgo +
", seedSelectionAlgo=" + seedSelectionAlgo +
", trainedModelInputPath='" + trainedModelInputPath + '\'' +
'}';
}
}
......@@ -7,7 +7,7 @@ import lombok.Setter;
@Data
@Getter
@Setter
public class CmdStartParams {
public class AlgorithmTwoCmdParams {
String netinfo; //netInfo
String protopcol; //protocol
int waiting; //usec
......
package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.CmdStartParams;
import java.util.concurrent.CountDownLatch;
import com.example.fuzzControll.pojo.vo.AlgorithmOneCmdParams;
public interface TestService {
void testStart(CmdStartParams cmdStartParams);
void algorithmOneStart(AlgorithmOneCmdParams algorithmOneCmdParams);
void algorithmTwoStart(AlgorithmOneCmdParams algorithmOneCmdParams);
void testStop();
}
package com.example.fuzzControll.tools;
import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.conf.AflnetSshProperties;
import com.example.fuzzControll.exception.AflnetException;
import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.pojo.vo.*;
import com.jcraft.jsch.JSchException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
//todo need modify
......@@ -88,46 +85,46 @@ public class CmdTools {
}
public String parse(CmdStartParams cmdStartParams) throws AflnetException {
if (cmdStartParams == null) {
public String parse(AlgorithmOneCmdParams algorithmOneCmdParams) throws AflnetException {
if (algorithmOneCmdParams == null) {
throw new AflnetException("CmdStartParams is null !");
}
StringBuilder cmd = new StringBuilder();
if (cmdStartParams.getNetinfo() != "" && cmdStartParams.getNetinfo() != null) {
cmd.append(" -N " + cmdStartParams.getNetinfo());
if (algorithmOneCmdParams.getNetinfo() != "" && algorithmOneCmdParams.getNetinfo() != null) {
cmd.append(" -N " + algorithmOneCmdParams.getNetinfo());
} else {
log.error("There is no netinfo !");
throw new AflnetException("There is no netinfo !");
}
if (cmdStartParams.getProtopcol() != "") {
cmd.append(" -P " + cmdStartParams.getProtopcol());
if (algorithmOneCmdParams.getProtopcol() != "") {
cmd.append(" -P " + algorithmOneCmdParams.getProtopcol());
}
if (cmdStartParams.getWaiting() != 0) {
cmd.append(" -D " + cmdStartParams.getWaiting());
if (algorithmOneCmdParams.getWaiting() != 0) {
cmd.append(" -D " + algorithmOneCmdParams.getWaiting());
}
if (cmdStartParams.getNsname() != "") {
cmd.append(" -e " + cmdStartParams.getNsname());
if (algorithmOneCmdParams.getNsname() != "") {
cmd.append(" -e " + algorithmOneCmdParams.getNsname());
}
if (cmdStartParams.getKill()) {
if (algorithmOneCmdParams.getKill()) {
cmd.append(" -K ");
}
if (cmdStartParams.getAwareMode()) {
if (algorithmOneCmdParams.getAwareMode()) {
cmd.append(" -E ");
}
if (cmdStartParams.getRegionMutationOperators()) {
if (algorithmOneCmdParams.getRegionMutationOperators()) {
cmd.append(" -R ");
}
if (cmdStartParams.getFalseNegativeMode()) {
if (algorithmOneCmdParams.getFalseNegativeMode()) {
cmd.append(" -F ");
}
if (cmdStartParams.getScript() != "") {
cmd.append(" -c " + cmdStartParams.getScript());
if (algorithmOneCmdParams.getScript() != "") {
cmd.append(" -c " + algorithmOneCmdParams.getScript());
}
if (cmdStartParams.getStateSelectionAlgo() != 0) {
cmd.append(" -q " + cmdStartParams.getStateSelectionAlgo());
if (algorithmOneCmdParams.getStateSelectionAlgo() != 0) {
cmd.append(" -q " + algorithmOneCmdParams.getStateSelectionAlgo());
}
if (cmdStartParams.getSeedSelectionAlgo() != 0) {
cmd.append(" -s " + cmdStartParams.getSeedSelectionAlgo() + " ");
if (algorithmOneCmdParams.getSeedSelectionAlgo() != 0) {
cmd.append(" -s " + algorithmOneCmdParams.getSeedSelectionAlgo() + " ");
}
return cmd.toString();
}
......
......@@ -94,14 +94,15 @@ public class LinuxCommandUtil {
TestReturnEntity returnEntity = new TestReturnEntity();
try {
while ((line = bf.readLine()) != null && TestControlTools.getIsRunning()) {
cmdTools.makeReturnEntity(line, returnEntity);
if (cmdTools.send) {
String data = JSONObject.toJSONString(returnEntity);
try {
GlobalParameters.webSocket.appointSending("fuzzMaster", "web", data);
} catch (Exception ignored) {
}
}
System.out.println(line);
// cmdTools.makeReturnEntity(line, returnEntity);
// if (cmdTools.send) {
// String data = JSONObject.toJSONString(returnEntity);
// try {
// GlobalParameters.webSocket.appointSending("fuzzMaster", "web", data);
// } catch (Exception ignored) {
// }
// }
}
//结束就关闭
if(!TestControlTools.getIsRunning()){
......
......@@ -22,7 +22,13 @@ web:
ip: 192.168.9.177
aflnetssh:
host: 192.168.9.177
host: 192.168.31.53
port: 22
user: root
password: 123456
\ No newline at end of file
user: lddc
password: sysulddc
#aflnetssh:
# host: 192.168.31.133
# port: 22
# user: root
# password: 123456
\ 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