Commit 51383361 by 钱炳权

实验室环境成功返回websocket数据

parent 2b6461e2
...@@ -31,14 +31,24 @@ public class TestServiceImpl implements TestService { ...@@ -31,14 +31,24 @@ public class TestServiceImpl implements TestService {
@Override @Override
public void algorithmOneStart(AlgorithmOneCmdParams algorithmOneCmdParams) { public void algorithmOneStart(AlgorithmOneCmdParams algorithmOneCmdParams) {
TestControlTools.setIsRunning(true); TestControlTools.setIsRunning(true);
String finalCmd = getAlgorithmOneFinalCmd(algorithmOneCmdParams); String aflnetCmd = getAlgorithmOneFinalCmd(algorithmOneCmdParams);
if (finalCmd == null) { String pythonCmd = getAlgorithmOnePythonCmd(algorithmOneCmdParams);
String recodeCmd = getAlgorithmOneResultCmd(algorithmOneCmdParams);
if (aflnetCmd == null) {
log.error("AlgorithmOne Cmd is null!"); log.error("AlgorithmOne Cmd is null!");
throw new AflnetException("Cmd Generate error!"); throw new AflnetException("Cmd Generate error!");
} }
log.info("The cmd is [{}]", finalCmd); if (pythonCmd == null) {
log.error("pythonCmd Cmd is null!");
throw new AflnetException("Cmd Generate error!");
}
if (recodeCmd == null) {
log.error("recodeCmd Cmd is null!");
throw new AflnetException("Cmd Generate error!");
}
log.info("The cmd is [{}]", aflnetCmd);
try { try {
cmdTools.runProgramCmd(finalCmd); cmdTools.runProgramCmd(aflnetCmd,pythonCmd,recodeCmd);
} catch (JSchException e) { } catch (JSchException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
...@@ -47,6 +57,39 @@ public class TestServiceImpl implements TestService { ...@@ -47,6 +57,39 @@ public class TestServiceImpl implements TestService {
} }
private String getAlgorithmOneResultCmd(AlgorithmOneCmdParams algorithmOneCmdParams) {
switch (algorithmOneCmdParams.getProtopcol().toLowerCase()) {
case "dns":
return "cd /home/lddc/SHENYANLONG/SMGfuzz && python Copy_fuzz_stats.py --SUT dnsmasq --ALG RLGfuzz";
case "sip":
return "cd /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch && python Copy_fuzz_stats.py --SUT kamailio --ALG RLGfuzz";
case "ftp":
return "cd /home/lddc/SHENYANLONG/SMGfuzz && python Copy_fuzz_stats.py --SUT kamailio --ALG RLGfuzz";
case "rtsp":
return "cd /home/lddc/SHENYANLONG/SMGfuzz && python Copy_fuzz_stats.py --SUT live555 --ALG RLGfuzz";
default:
return null;
//todo 增加其他协议 的格式
}
}
private String getAlgorithmOnePythonCmd(AlgorithmOneCmdParams algorithmOneCmdParams) {
switch (algorithmOneCmdParams.getProtopcol().toLowerCase()) {
case "dns":
return "dnsResultCmd(algorithmOneCmdParams)";
case "sip":
return "sipResultCmd(algorithmOneCmdParams)";
case "ftp":
return "ftpResultCmd(algorithmOneCmdParams)";
case "rtsp":
return "rtspResultCmd(algorithmOneCmdParams)";
default:
return null;
//todo 增加其他协议 的格式
}
}
private String getAlgorithmOneFinalCmd(AlgorithmOneCmdParams algorithmOneCmdParams) { private String getAlgorithmOneFinalCmd(AlgorithmOneCmdParams algorithmOneCmdParams) {
switch (algorithmOneCmdParams.getProtopcol().toLowerCase()) { switch (algorithmOneCmdParams.getProtopcol().toLowerCase()) {
case "dns": case "dns":
...@@ -64,92 +107,90 @@ public class TestServiceImpl implements TestService { ...@@ -64,92 +107,90 @@ public class TestServiceImpl implements TestService {
} }
private String dnsCmd(AlgorithmOneCmdParams algorithmOneCmdParams) { private String dnsCmd(AlgorithmOneCmdParams algorithmOneCmdParams) {
// String before = AlgorithmOneCmd.ALFNET_PATH + " -d " + AlgorithmOneCmd.ALFNET_INPUT_PATH + "/dnsmasq/in-dns " String before = AlgorithmOneCmd.ALFNET_PATH + " -d " + AlgorithmOneCmd.ALFNET_INPUT_PATH + "/dnsmasq/in-dns "
// +AlgorithmOneCmd.ALFNET_OUTPUT_PATH+"/dnsmasq/src/output_dnsmasq_RLGfuzz"+" -z "+algorithmOneCmdParams.getTrainedModelInputPath() + AlgorithmOneCmd.ALFNET_OUTPUT_PATH + "/dnsmasq/src/output_dnsmasq_RLGfuzz";
// +" -N "+algorithmOneCmdParams.getNetinfo()+" -m none "+" -P "+algorithmOneCmdParams.getProtopcol()+" -D " if (!"".equals(algorithmOneCmdParams.getTrainedModelInputPath())) {
// +algorithmOneCmdParams.getWaiting(); before = before + " -z " + algorithmOneCmdParams.getTrainedModelInputPath();
// String after = " -q "+algorithmOneCmdParams.getStateSelectionAlgo()+" -s "+algorithmOneCmdParams.getSeedSelectionAlgo()+" -r '4' /home/lddc/SHENYANLONG/dnsmasq/src/dnsmasq"; }
// String finalCmd = before; before = before + " -N " + algorithmOneCmdParams.getNetinfo() + " -m none " + " -P " + algorithmOneCmdParams.getProtopcol() + " -D "
// if(algorithmOneCmdParams.getKill()){ + algorithmOneCmdParams.getWaiting();
// finalCmd = finalCmd+" -K "; String after = " -q " + algorithmOneCmdParams.getStateSelectionAlgo() + " -s " + algorithmOneCmdParams.getSeedSelectionAlgo() + " -r '4' /home/lddc/SHENYANLONG/dnsmasq/src/dnsmasq";
// } String finalCmd = before;
// if(algorithmOneCmdParams.getAwareMode()) if (algorithmOneCmdParams.getKill()) {
// finalCmd = finalCmd+" -E "; finalCmd = finalCmd + " -K ";
// if(algorithmOneCmdParams.getRegionMutationOperators()) }
// finalCmd = finalCmd+" -R "; if (algorithmOneCmdParams.getAwareMode())
// if(!"".equals(algorithmOneCmdParams.getScript())) finalCmd = finalCmd + " -E ";
// finalCmd = finalCmd+" -c "+algorithmOneCmdParams.getScript(); if (algorithmOneCmdParams.getRegionMutationOperators())
// if(!"".equals(algorithmOneCmdParams.getTrainedModelInputPath())) finalCmd = finalCmd + " -R ";
// finalCmd = finalCmd+" -c "+algorithmOneCmdParams.getScript(); if (!"".equals(algorithmOneCmdParams.getScript()))
// finalCmd = finalCmd+after; finalCmd = finalCmd + " -c " + algorithmOneCmdParams.getScript();
// return finalCmd; finalCmd = finalCmd + after;
return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -d -i /home/lddc/SHENYANLONG/dnsmasq/in-dns -o /home/lddc/SHENYANLONG/dnsmasq/src/output_dnsmasq_RLGfuzz -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/dnsmasq/RL_Result -N udp://127.0.0.1/5353 -m none -P DNS -D 10000 -K -E -R -q 4 -s 4 -r '4' /home/lddc/SHENYANLONG/dnsmasq/src/dnsmasq"; return finalCmd;
// return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -d -i /home/lddc/SHENYANLONG/dnsmasq/in-dns -o /home/lddc/SHENYANLONG/dnsmasq/src/output_dnsmasq_RLGfuzz -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/dnsmasq/RL_Result -N udp://127.0.0.1/5353 -m none -P DNS -D 10000 -K -E -R -q 4 -s 4 -r '4' /home/lddc/SHENYANLONG/dnsmasq/src/dnsmasq";
} }
private String sipCmd(AlgorithmOneCmdParams algorithmOneCmdParams) { private String sipCmd(AlgorithmOneCmdParams algorithmOneCmdParams) {
// String before = AlgorithmOneCmd.ALFNET_PATH + AlgorithmOneCmd.ALFNET_INPUT_PATH + "/kamailio/in-sip " String before = AlgorithmOneCmd.ALFNET_PATH + AlgorithmOneCmd.ALFNET_INPUT_PATH + "/kamailio/in-sip "
// +AlgorithmOneCmd.ALFNET_OUTPUT_PATH+"/kamailio/output_kamailio_RLGfuzz"+" -z "+algorithmOneCmdParams.getTrainedModelInputPath() + AlgorithmOneCmd.ALFNET_OUTPUT_PATH + "/kamailio/output_kamailio_RLGfuzz";
// +" -N "+algorithmOneCmdParams.getNetinfo()+" -m none -t 3000+ "+" -P "+algorithmOneCmdParams.getProtopcol()+" -l 5061 "+" -D " if (!"".equals(algorithmOneCmdParams.getTrainedModelInputPath()))
// +algorithmOneCmdParams.getWaiting()+" -d "; before = before + " -z " + algorithmOneCmdParams.getTrainedModelInputPath();
// String after = " -q "+algorithmOneCmdParams.getStateSelectionAlgo()+" -s "+algorithmOneCmdParams.getSeedSelectionAlgo() before = before + " -N " + algorithmOneCmdParams.getNetinfo() + " -m none -t 3000+ " + " -P " + algorithmOneCmdParams.getProtopcol() + " -l 5061 " + " -D "
// +" /home/lddc/SHENYANLONG/kamailio/src/kamailio -f /home/lddc/SHENYANLONG/kamailio/kamailio-basic.cfg -L /home/lddc/SHENYANLONG/kamailio/src/modules -n 1 -Y /home/lddc/SHENYANLONG/kamailio/runtime_dir"; + algorithmOneCmdParams.getWaiting()+" -q " + algorithmOneCmdParams.getStateSelectionAlgo() + " -s " + algorithmOneCmdParams.getSeedSelectionAlgo();
// String finalCmd = before; if (algorithmOneCmdParams.getKill()) {
// if(algorithmOneCmdParams.getKill()){ before = before + " -K ";
// finalCmd = finalCmd+" -K "; }
// } if (algorithmOneCmdParams.getAwareMode())
// if(algorithmOneCmdParams.getAwareMode()) before = before + " -E ";
// finalCmd = finalCmd+" -E "; if (algorithmOneCmdParams.getRegionMutationOperators())
// if(algorithmOneCmdParams.getRegionMutationOperators()) before = before + " -R ";
// finalCmd = finalCmd+" -R "; if (!"".equals(algorithmOneCmdParams.getScript()))
// if(!"".equals(algorithmOneCmdParams.getScript())) before = before + " -c " + algorithmOneCmdParams.getScript();
// finalCmd = finalCmd+" -c "+algorithmOneCmdParams.getScript(); String after = " -d /home/lddc/SHENYANLONG/kamailio/src/kamailio -f /home/lddc/SHENYANLONG/kamailio/kamailio-basic.cfg -L /home/lddc/SHENYANLONG/kamailio/src/modules -n 1 -Y /home/lddc/SHENYANLONG/kamailio/runtime_dir";
// finalCmd = finalCmd+after; before = before + after;
// return finalCmd; return before;
return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -i /home/lddc/SHENYANLONG/kamailio/in-sip -o /home/lddc/SHENYANLONG/kamailio/output_kamailio_RLGfuzz -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/kamailio/RL_Result -N udp://127.0.0.1/5060 -m none -t 3000+ -P SIP -l 5061 -D 50000 -q 4 -s 4 -E -K -R -d -c /home/lddc/SHENYANLONG/kamailio/run_pjsip.sh /home/lddc/SHENYANLONG/kamailio/src/kamailio -f /home/lddc/SHENYANLONG/kamailio/kamailio-basic.cfg -L /home/lddc/SHENYANLONG/kamailio/src/modules -n 1 -Y /home/lddc/SHENYANLONG/kamailio/runtime_dir"; // return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -i /home/lddc/SHENYANLONG/kamailio/in-sip -o /home/lddc/SHENYANLONG/kamailio/output_kamailio_RLGfuzz -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/kamailio/RL_Result -N udp://127.0.0.1/5060 -m none -t 3000+ -P SIP -l 5061 -D 50000 -q 4 -s 4 -E -K -R -d -c /home/lddc/SHENYANLONG/kamailio/run_pjsip.sh /home/lddc/SHENYANLONG/kamailio/src/kamailio -f /home/lddc/SHENYANLONG/kamailio/kamailio-basic.cfg -L /home/lddc/SHENYANLONG/kamailio/src/modules -n 1 -Y /home/lddc/SHENYANLONG/kamailio/runtime_dir";
} }
private String ftpCmd(AlgorithmOneCmdParams algorithmOneCmdParams) { private String ftpCmd(AlgorithmOneCmdParams algorithmOneCmdParams) {
// String before = AlgorithmOneCmd.ALFNET_PATH + AlgorithmOneCmd.ALFNET_INPUT_PATH + "/SMGfuzz/tutorials/lightftp/in-ftp " String before = AlgorithmOneCmd.ALFNET_PATH +" -m none "+ AlgorithmOneCmd.ALFNET_INPUT_PATH + "/SMGfuzz/tutorials/lightftp/in-ftp "
// +AlgorithmOneCmd.ALFNET_OUTPUT_PATH+"/LightFTP/Source/Release/output_lightftp_RLGfuzz"+" -z "+algorithmOneCmdParams.getTrainedModelInputPath() +AlgorithmOneCmd.ALFNET_OUTPUT_PATH+"/LightFTP/Source/Release/output_lightftp_RLGfuzz"+" -z "+algorithmOneCmdParams.getTrainedModelInputPath()
// +" -N "+algorithmOneCmdParams.getNetinfo()+" -m none "+" -P "+algorithmOneCmdParams.getProtopcol()+" -l 5061 "+" -D " +" -x /home/lddc/SHENYANLONG/SMGfuzz/tutorials/lightftp/ftp.dict"
// +algorithmOneCmdParams.getWaiting()+" -d "; +" -N "+algorithmOneCmdParams.getNetinfo()+" -P "+algorithmOneCmdParams.getProtopcol()+" -D "
// String after = " -q "+algorithmOneCmdParams.getStateSelectionAlgo()+" -s "+algorithmOneCmdParams.getSeedSelectionAlgo() +algorithmOneCmdParams.getWaiting()+" -d "+" -q "+algorithmOneCmdParams.getStateSelectionAlgo()+" -s "+algorithmOneCmdParams.getSeedSelectionAlgo();
// +" /home/lddc/SHENYANLONG/kamailio/src/kamailio -f /home/lddc/SHENYANLONG/kamailio/kamailio-basic.cfg -L /home/lddc/SHENYANLONG/kamailio/src/modules -n 1 -Y /home/lddc/SHENYANLONG/kamailio/runtime_dir"; if(algorithmOneCmdParams.getKill()){
// String finalCmd = before; before = before+" -K ";
// if(algorithmOneCmdParams.getKill()){ }
// finalCmd = finalCmd+" -K "; if(algorithmOneCmdParams.getAwareMode())
// } before = before+" -E ";
// if(algorithmOneCmdParams.getAwareMode()) if(algorithmOneCmdParams.getRegionMutationOperators())
// finalCmd = finalCmd+" -E "; before = before+" -R ";
// if(algorithmOneCmdParams.getRegionMutationOperators()) if(!"".equals(algorithmOneCmdParams.getScript()))
// finalCmd = finalCmd+" -R "; before = before+" -c "+algorithmOneCmdParams.getScript();
// if(!"".equals(algorithmOneCmdParams.getScript())) before = before+ " /home/lddc/SHENYANLONG/LightFTP/Source/Release/fftp /home/lddc/SHENYANLONG/LightFTP/Source/Release/fftp.conf 2200";;
// finalCmd = finalCmd+" -c "+algorithmOneCmdParams.getScript(); return before;
// finalCmd = finalCmd+after; // return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -m none -i /home/lddc/SHENYANLONG/SMGfuzz/tutorials/lightftp/in-ftp -o /home/lddc/SHENYANLONG/LightFTP/Source/Release/output_lightftp_RLGfuzz -N tcp://127.0.0.1/2200 -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/lightftp/RL_Result -x /home/lddc/SHENYANLONG/SMGfuzz/tutorials/lightftp/ftp.dict -P FTP -D 10000 -q 4 -s 4 -E -K -R -d -c /home/lddc/SHENYANLONG/LightFTP/Source/Release/ftpclean.sh /home/lddc/SHENYANLONG/LightFTP/Source/Release/fftp /home/lddc/SHENYANLONG/LightFTP/Source/Release/fftp.conf 2200";
// return finalCmd;
return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -m none -i /home/lddc/SHENYANLONG/SMGfuzz/tutorials/lightftp/in-ftp -o /home/lddc/SHENYANLONG/LightFTP/Source/Release/output_lightftp_RLGfuzz -N tcp://127.0.0.1/2200 -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/lightftp/RL_Result -x /home/lddc/SHENYANLONG/SMGfuzz/tutorials/lightftp/ftp.dict -P FTP -D 10000 -q 4 -s 4 -E -K -R -d -c /home/lddc/SHENYANLONG/LightFTP/Source/Release/ftpclean.sh /home/lddc/SHENYANLONG/LightFTP/Source/Release/fftp /home/lddc/SHENYANLONG/LightFTP/Source/Release/fftp.conf 2200";
} }
private String rtspCmd(AlgorithmOneCmdParams algorithmOneCmdParams) { private String rtspCmd(AlgorithmOneCmdParams algorithmOneCmdParams) {
// String before = AlgorithmOneCmd.ALFNET_PATH + AlgorithmOneCmd.ALFNET_INPUT_PATH + "/kamailio/in-sip " String before = AlgorithmOneCmd.ALFNET_PATH + AlgorithmOneCmd.ALFNET_INPUT_PATH + "/SMGfuzz/tutorials/live555/in-rtsp "
// +AlgorithmOneCmd.ALFNET_OUTPUT_PATH+"/kamailio/output_kamailio_RLGfuzz"+" -z "+algorithmOneCmdParams.getTrainedModelInputPath() +AlgorithmOneCmd.ALFNET_OUTPUT_PATH+"/live555/testProgs/output_live555_RLGfuzz"+" -z "+algorithmOneCmdParams.getTrainedModelInputPath()
// +" -N "+algorithmOneCmdParams.getNetinfo()+" -m none -t 3000+ "+" -P "+algorithmOneCmdParams.getProtopcol()+" -l 5061 "+" -D " +" -N "+algorithmOneCmdParams.getNetinfo()+" -x /home/lddc/SHENYANLONG/SMGfuzz/tutorials/live555/rtsp.dict "+" -P "+algorithmOneCmdParams.getProtopcol()+" -m none "+" -D "
// +algorithmOneCmdParams.getWaiting()+" -d "; +algorithmOneCmdParams.getWaiting()+" -d -r 400";
// String after = " -q "+algorithmOneCmdParams.getStateSelectionAlgo()+" -s "+algorithmOneCmdParams.getSeedSelectionAlgo() String after = " -q "+algorithmOneCmdParams.getStateSelectionAlgo()+" -s "+algorithmOneCmdParams.getSeedSelectionAlgo()
// +" /home/lddc/SHENYANLONG/kamailio/src/kamailio -f /home/lddc/SHENYANLONG/kamailio/kamailio-basic.cfg -L /home/lddc/SHENYANLONG/kamailio/src/modules -n 1 -Y /home/lddc/SHENYANLONG/kamailio/runtime_dir"; +" /home/lddc/SHENYANLONG/live555/testProgs/testOnDemandRTSPServer 8554";
// String finalCmd = before; if(algorithmOneCmdParams.getKill()){
// if(algorithmOneCmdParams.getKill()){ before = before+" -K ";
// finalCmd = finalCmd+" -K "; }
// } if(algorithmOneCmdParams.getAwareMode())
// if(algorithmOneCmdParams.getAwareMode()) before = before+" -E ";
// finalCmd = finalCmd+" -E "; if(algorithmOneCmdParams.getRegionMutationOperators())
// if(algorithmOneCmdParams.getRegionMutationOperators()) before = before+" -R ";
// finalCmd = finalCmd+" -R "; if(!"".equals(algorithmOneCmdParams.getScript()))
// if(!"".equals(algorithmOneCmdParams.getScript())) before = before+" -c "+algorithmOneCmdParams.getScript();
// finalCmd = finalCmd+" -c "+algorithmOneCmdParams.getScript(); before = before+after;
// finalCmd = finalCmd+after; return before;
// return finalCmd; // return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -i /home/lddc/SHENYANLONG/SMGfuzz/tutorials/live555/in-rtsp -o /home/lddc/SHENYANLONG/live555/testProgs/output_live555_RLGfuzz -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/live555/RL_Result -N tcp://127.0.0.1/8554 -x /home/lddc/SHENYANLONG/SMGfuzz/tutorials/live555/rtsp.dict -m none -D 10000 -K -E -R -q 4 -s 4 -d /home/lddc/SHENYANLONG/live555/testProgs/testOnDemandRTSPServer 85540";
return "/home/lddc/SHENYANLONG/SMGfuzz/afl-fuzz -i /home/lddc/SHENYANLONG/SMGfuzz/tutorials/live555/in-rtsp -o /home/lddc/SHENYANLONG/live555/testProgs/output_live555_RLGfuzz -z /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch/Train_Result/live555/RL_Result -N tcp://127.0.0.1/8554 -x /home/lddc/SHENYANLONG/SMGfuzz/tutorials/live555/rtsp.dict -m none -D 10000 -K -E -R -q 4 -s 4 -d /home/lddc/SHENYANLONG/live555/testProgs/testOnDemandRTSPServer 85540";
} }
//todo 不同服务不同端口 //todo 不同服务不同端口
...@@ -163,7 +204,7 @@ public class TestServiceImpl implements TestService { ...@@ -163,7 +204,7 @@ public class TestServiceImpl implements TestService {
String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputFileName + CmdConstent.RUN_AFLNET_AFTER + cmd + aflnetProperties.getAflnetPath() + "live555/testProgs/testOnDemandRTSPServer 8554"; String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputFileName + CmdConstent.RUN_AFLNET_AFTER + cmd + aflnetProperties.getAflnetPath() + "live555/testProgs/testOnDemandRTSPServer 8554";
log.info("The cmd is [{}]", finalCmd); log.info("The cmd is [{}]", finalCmd);
try { try {
cmdTools.runProgramCmd("source /etc/profile && " + finalCmd); cmdTools.runProgramCmd("source /etc/profile && " + finalCmd,"","");
} catch (JSchException e) { } catch (JSchException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
......
...@@ -41,7 +41,7 @@ public class CmdTools { ...@@ -41,7 +41,7 @@ public class CmdTools {
* 运行需要后台运行cmd * 运行需要后台运行cmd
* 通过websocket返回数据 * 通过websocket返回数据
*/ */
public void runProgramCmd(String cmd) throws AflnetException, JSchException, IOException { public void runProgramCmd(String aflnetCmd,String pythonCmd,String recodeCmd) throws AflnetException, JSchException, IOException {
AflnetSshProperties aflnetSshProperties = GlobalParameters.aflnetSshProperties; AflnetSshProperties aflnetSshProperties = GlobalParameters.aflnetSshProperties;
String host = aflnetSshProperties.getHost(); String host = aflnetSshProperties.getHost();
int port =aflnetSshProperties.getPort(); int port =aflnetSshProperties.getPort();
...@@ -50,7 +50,9 @@ public class CmdTools { ...@@ -50,7 +50,9 @@ public class CmdTools {
// 手动创建对象实现连接 // 手动创建对象实现连接
LinuxCommandUtil linuxCommandUtil = new LinuxCommandUtil(); LinuxCommandUtil linuxCommandUtil = new LinuxCommandUtil();
linuxCommandUtil.connect(host, port, user, password); linuxCommandUtil.connect(host, port, user, password);
linuxCommandUtil.execCmd(cmd); linuxCommandUtil.execCmd(aflnetCmd);
// linuxCommandUtil.execCmdWithoutResults(pythonCmd);
// linuxCommandUtil.execCmdWithoutResults(recodeCmd);
} }
......
...@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools; ...@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.pojo.vo.TestReturnEntity; import com.example.fuzzControll.pojo.vo.TestReturnEntity;
...@@ -11,6 +12,7 @@ import com.jcraft.jsch.ChannelExec; ...@@ -11,6 +12,7 @@ import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import org.apache.tomcat.util.buf.Utf8Decoder;
public class LinuxCommandUtil { public class LinuxCommandUtil {
...@@ -82,30 +84,66 @@ public class LinuxCommandUtil { ...@@ -82,30 +84,66 @@ public class LinuxCommandUtil {
public void execCmd(String command) throws JSchException, IOException { public void execCmd(String command) throws JSchException, IOException {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
InputStream in = channelExec.getInputStream(); InputStream in = channelExec.getInputStream();
InputStream error = channelExec.getErrStream();
new Thread(new Runnable() {
@Override
public void run() {
outPutStream(in);
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
errorStream(error);
}
}).start();
channelExec.setCommand(command); channelExec.setCommand(command);
channelExec.setErrStream(System.err);
channelExec.connect(); channelExec.connect();
}
/**
* 不需要结果执行指令
*/
public void execCmdWithoutResults(String command) throws JSchException, IOException {
channelExec.setCommand(command);
channelExec.connect();
}
public void outPutStream(InputStream in) {
Reader reader = new InputStreamReader(in); Reader reader = new InputStreamReader(in);
BufferedReader bf = new BufferedReader(reader); BufferedReader bf = new BufferedReader(reader);
CmdTools cmdTools = new CmdTools();
String line = null; String line = null;
TestReturnEntity returnEntity = new TestReturnEntity(); List<String> list = null;
try {
while ((line = bf.readLine()) != null && TestControlTools.getIsRunning()) {
System.out.println(line);
if (line.contains("american fuzzy")) {
list = new ArrayList<>();
}
if (list != null)
list.add(line + "\n");
if (line.contains("cpu"))
GlobalParameters.webSocket.appointSending("fuzzMaster", "web", list.toString());
}
//结束就关闭
if (!TestControlTools.getIsRunning()) {
close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void errorStream(InputStream error) {
Reader reader = new InputStreamReader(error);
BufferedReader bf = new BufferedReader(reader);
String line = null;
List<String> list = null;
try { try {
while ((line = bf.readLine()) != null && TestControlTools.getIsRunning()) { while ((line = bf.readLine()) != null && TestControlTools.getIsRunning()) {
System.out.println(line); 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()){ if (!TestControlTools.getIsRunning()) {
close(); close();
} }
} catch (IOException e) { } catch (IOException e) {
......
...@@ -8,19 +8,17 @@ ...@@ -8,19 +8,17 @@
var ws1 = null; var ws1 = null;
var ws2 = null; var ws2 = null;
function myFunction() { function myFunction() {
ws1 = new WebSocket("ws://192.168.9.177:8100/websocket/testResult/web"); ws1 = new WebSocket("ws://192.168.31.133:8100/websocket/testResult/web");
ws1.onmessage = function (evt) { ws1.onmessage = function (evt) {
console.log(evt); console.log(evt);
var received_msg =JSON.parse(evt.data) ; console.log(evt.data)
const nameValue = Object.values(received_msg)
var context = '<div class="sendMsg">' + var context = '<div class="sendMsg">' +
'aflnet:<br/>'+ 'aflnet:<br/>'+
'aflnet<h3>'+nameValue+'</h3><br/>'+ 'aflnet<h3>'+evt.data+'</h3><br/>'+
' </div>'; ' </div>';
document.getElementById("sendDiv").innerHTML = context; document.getElementById("sendDiv").innerHTML = context;
}; };
ws1.onclose = function () { ws1.onclose = function () {
// 关闭 websocket // 关闭 websocket
alert("连接已关闭..."); alert("连接已关闭...");
}; };
......
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