Commit 91c7e11d by 钱炳权

24/4/1 漏洞类型、模板生成、变异方法 控制输出转为字符串输出

parent 3e45851d
...@@ -13,16 +13,16 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -13,16 +13,16 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/generateMethod") @RequestMapping("/generateMethod")
public class generateMethodController { public class generateMethodController {
@Autowired @Autowired
generateMethodService service; generateMethodService service;
@RequestMapping(value = "/generate", method = RequestMethod.POST) @RequestMapping(value = "/generate", method = RequestMethod.POST)
public AjaxResult upload(@RequestBody generateMethodEntity generateMethodEntity) { public AjaxResult upload(@RequestBody generateMethodEntity generateMethodEntity) {
try { try {
service.generation(generateMethodEntity); return AjaxResult.success(service.generation(generateMethodEntity));
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error("变异方法使用失败!"); return AjaxResult.error("变异方法使用失败!");
} }
return AjaxResult.success("变异方法生成成功!");
} }
} }
...@@ -3,6 +3,8 @@ package com.example.fuzzControll.service; ...@@ -3,6 +3,8 @@ package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.generateMethodEntity; import com.example.fuzzControll.pojo.vo.generateMethodEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity; import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import java.util.List;
public interface generateMethodService { public interface generateMethodService {
void generation(generateMethodEntity generateMethodEntity); List<String> generation(generateMethodEntity generateMethodEntity);
} }
...@@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -9,6 +9,8 @@ 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;
@Service @Service
@Slf4j @Slf4j
public class generateMethodServiceImpl implements generateMethodService { public class generateMethodServiceImpl implements generateMethodService {
...@@ -17,9 +19,9 @@ public class generateMethodServiceImpl implements generateMethodService { ...@@ -17,9 +19,9 @@ public class generateMethodServiceImpl implements generateMethodService {
kittyProperties kitty; kittyProperties kitty;
@Override @Override
public void generation(generateMethodEntity generateMethodEntity) { public List<String> generation(generateMethodEntity generateMethodEntity) {
String cmd = parseParameters(generateMethodEntity); String cmd = parseParameters(generateMethodEntity);
cmdTools.runProgramCmdAndResultTofile(cmd); return cmdTools.runProgramCmdAndResultTofile(cmd);
} }
public String parseParameters(generateMethodEntity generateMethodEntity) { public String parseParameters(generateMethodEntity generateMethodEntity) {
......
...@@ -54,18 +54,20 @@ public class cmdTools { ...@@ -54,18 +54,20 @@ public class cmdTools {
* 运行需要后台运行cmd * 运行需要后台运行cmd
* 将数据存入文件中 * 将数据存入文件中
*/ */
public void runProgramCmdAndResultTofile(String cmd) { public List<String> runProgramCmdAndResultTofile(String cmd) {
List<String> result = new ArrayList<>();
try { try {
Process process = Runtime.getRuntime().exec(cmd); Process process = Runtime.getRuntime().exec(cmd);
printMessageToFile(process.getInputStream()); printMessageToFile(process.getInputStream(), result);
printMessageToFile(process.getErrorStream()); printMessageToFile(process.getErrorStream(), new ArrayList<String>());
process.waitFor(); process.waitFor();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return result;
} }
private void printMessageToFile(InputStream input) { private List<String> printMessageToFile(InputStream input, List<String> result) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -74,7 +76,7 @@ public class cmdTools { ...@@ -74,7 +76,7 @@ public class cmdTools {
String line = null; String line = null;
try { try {
while ((line = bf.readLine()) != null) { while ((line = bf.readLine()) != null) {
System.out.println(line); result.add(line);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -82,6 +84,7 @@ public class cmdTools { ...@@ -82,6 +84,7 @@ public class cmdTools {
} }
}).start(); }).start();
return result;
} }
private List<String> printMessage(final InputStream input, List<String> result) { private List<String> printMessage(final InputStream input, List<String> result) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
var ws1 = null; var ws1 = null;
var ws2 = null; var ws2 = null;
function myFunction() { function myFunction() {
ws1 = new WebSocket("ws://127.0.0.1:8080/websocket/testResult/" + "web"+100); ws1 = new WebSocket("ws://192.168.37.149: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) ; var received_msg =JSON.parse(evt.data) ;
......
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