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