Commit 9cfe5d97 by 钱炳权

24/3/28 生成方法、变异方法接入成功并能成功输出至窗口

parent 287f71df
...@@ -58,7 +58,12 @@ ...@@ -58,7 +58,12 @@
<artifactId>spring-boot-starter-websocket</artifactId> <artifactId>spring-boot-starter-websocket</artifactId>
<version>2.7.2</version> <version>2.7.2</version>
</dependency> </dependency>
<!-- log4j - slf4j 日志依赖 结束-->
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
<version>3.1.5</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
......
...@@ -25,31 +25,11 @@ import org.springframework.stereotype.Component; ...@@ -25,31 +25,11 @@ import org.springframework.stereotype.Component;
public class SpringContextUtil implements ApplicationContextAware { public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext; private static ApplicationContext applicationContext;
/********************************************************************
* 函数名称: SpringContextUtil//函数名称
* 功能描述: SpringContextUtil构造函数//函数功能、性能等的描述
* 输入参数: 无//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: 无//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
public SpringContextUtil() { public SpringContextUtil() {
} }
/********************************************************************
* 函数名称: setApplicationContext//函数名称
* 功能描述: 设置Application上下文//函数功能、性能等的描述
* 输入参数: 无//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: 无//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (SpringContextUtil.applicationContext == null) { if (SpringContextUtil.applicationContext == null) {
...@@ -58,32 +38,12 @@ public class SpringContextUtil implements ApplicationContextAware { ...@@ -58,32 +38,12 @@ public class SpringContextUtil implements ApplicationContextAware {
} }
/********************************************************************
* 函数名称: getBean//函数名称
* 功能描述: 跟据bean名称获取bean//函数功能、性能等的描述
* 输入参数: name是bean名称//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: Object//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
public static Object getBean(String name) { public static Object getBean(String name) {
return applicationContext.getBean(name); return applicationContext.getBean(name);
} }
/********************************************************************
* 函数名称: getBean//函数名称
* 功能描述: 跟据bean类型获取bean//函数功能、性能等的描述
* 输入参数: 无//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: 无//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
public static Object getBean(Class<?> requiredType) { public static Object getBean(Class<?> requiredType) {
return applicationContext.getBean(requiredType); return applicationContext.getBean(requiredType);
} }
......
package com.example.fuzzControll.conf;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component("kittyProperties")
@ConfigurationProperties(prefix = "kitty")
public class kittyProperties {
String path;
String venvPath;
String methodPath;
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getVenvPath() {
return venvPath;
}
public void setVenvPath(String venvPath) {
this.venvPath = venvPath;
}
public String getMethodPath() {
return methodPath;
}
public void setMethodPath(String methodPath) {
this.methodPath = methodPath;
}
}
package com.example.fuzzControll.constents;
public class protocolConstent {
public static final String RAW = "arp_raw.py ";
public static final String BGP = "bgp_tcp.py ";
public static final String DHCP = "dhcp_scapy.py ";
public static final String DNS = "dns_scapy.py ";
public static final String FRP = "frp_udp.py ";
public static final String FTP = "ftp_raw.py ";
public static final String HDLC = "hdlc_raw.py ";
public static final String HTTP_DOS_QUMU = "http_dos_qemu.py ";
//todo 还有一堆协议需要写
}
package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.generateMethodEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import com.example.fuzzControll.service.generateMethodService;
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;
@RestController
@RequestMapping("/generateMethod")
public class generateMethodController {
@Autowired
generateMethodService service;
@RequestMapping(value = "/generate", method = RequestMethod.POST)
public AjaxResult upload(@RequestBody generateMethodEntity generateMethodEntity) {
try {
service.generation(generateMethodEntity);
} catch (Exception e) {
return AjaxResult.error("变异方法使用失败!");
}
return AjaxResult.success("变异方法生成成功!");
}
}
package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import com.example.fuzzControll.service.protocolTemplateService;
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 org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/protocolTemplate")
public class protocolTemplatController {
@Autowired
protocolTemplateService protocolTemplateService;
/**
* seeFileUpload
*/
@RequestMapping(value = "/generation", method = RequestMethod.POST)
public AjaxResult upload(@RequestBody protocolGenerationEntity protocolGeneration) {
try {
protocolTemplateService.generation(protocolGeneration);
} catch (Exception e) {
return AjaxResult.error("模板文件生成失败!");
}
return AjaxResult.success("模板文件生成成功!");
}
}
...@@ -22,6 +22,7 @@ public class testControler { ...@@ -22,6 +22,7 @@ public class testControler {
public AjaxResult list(@RequestBody cmdStartParams cmdStartParams) { public AjaxResult list(@RequestBody cmdStartParams cmdStartParams) {
try { try {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override
public void run() { public void run() {
service.testStart(cmdStartParams); service.testStart(cmdStartParams);
} }
......
package com.example.fuzzControll.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/vulnerabilityType")
public class vulnerabilityTypeController {
}
package com.example.fuzzControll.pojo.vo;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Setter
@Getter
public class generateMethodEntity {
String methodName;
String[] paramJson;
}
package com.example.fuzzControll.pojo.vo;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Getter
@Setter
public class protocolGenerationEntity {
String protocolName;
String[] paramJson;
}
package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.generateMethodEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
public interface generateMethodService {
void generation(generateMethodEntity generateMethodEntity);
}
package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.kittyProperties;
import com.example.fuzzControll.pojo.vo.generateMethodEntity;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import com.example.fuzzControll.service.generateMethodService;
import com.example.fuzzControll.tools.cmdTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class generateMethodServiceImpl implements generateMethodService {
cmdTools cmdTools = new cmdTools();
@Autowired
kittyProperties kitty;
@Override
public void generation(generateMethodEntity generateMethodEntity) {
String cmd = parseParameters(generateMethodEntity);
cmdTools.runProgramCmdAndResultTofile(cmd);
}
public String parseParameters(generateMethodEntity generateMethodEntity) {
switch (generateMethodEntity.getMethodName().toLowerCase()) {
case "foreach":
return foreachCmd(generateMethodEntity);
default:
log.error("未知变异方法![{}]", generateMethodEntity.getMethodName());
return null;
}
}
private String foreachCmd(generateMethodEntity generateMethodEntity) {
String target_host = null;
String target_port = null;
String s1 = null;
String s2 = null;
String s3 = null;
try {
target_host = generateMethodEntity.getParamJson()[0];
target_port = generateMethodEntity.getParamJson()[1];
s1 = generateMethodEntity.getParamJson()[2];
s2 = generateMethodEntity.getParamJson()[3];
s3 = generateMethodEntity.getParamJson()[4];
} catch (Exception e) {
log.error("http_dos_qemu参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getMethodPath() + "generate_method_test.py -f " + s1 + " " + s2 + " " + s3+" --host="+target_host+" --port="+target_port;
}
//todo 还有很多生成方法
}
package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.conf.kittyProperties;
import com.example.fuzzControll.conf.seedProperties;
import com.example.fuzzControll.constents.protocolConstent;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import com.example.fuzzControll.service.protocolTemplateService;
import com.example.fuzzControll.tools.cmdTools;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
public class protocolTemplateImpl implements protocolTemplateService {
cmdTools cmdTools = new cmdTools();
@Autowired
kittyProperties kitty;
@Override
public void generation(protocolGenerationEntity protocolGeneration) {
String cmd = parseParameters(protocolGeneration);
cmdTools.runProgramCmdAndResultTofile(cmd);
}
public String parseParameters(protocolGenerationEntity protocolGeneration) {
switch (protocolGeneration.getProtocolName().toLowerCase()) {
case "arp":
return arpCmd(protocolGeneration);
case "bgp":
return bgpCmd(protocolGeneration);
case "dhcp":
return dhcpCmd(protocolGeneration);
case "dns":
return dnsCmd(protocolGeneration);
case "frp":
return frpCmd(protocolGeneration);
case "ftp":
return ftpCmd(protocolGeneration);
case "hdlc":
return hdlcCmd(protocolGeneration);
case "http_dos_qemu":
return http_dos_qemuCmd(protocolGeneration);
default:
log.error("未知协议![{}]", protocolGeneration.getProtocolName());
return null;
}
}
private String http_dos_qemuCmd(protocolGenerationEntity protocolGeneration) {
String dst_ip = null;
String port = null;
try {
dst_ip = protocolGeneration.getParamJson()[0];
port = protocolGeneration.getParamJson()[1];
} catch (Exception e) {
log.error("http_dos_qemu参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.HTTP_DOS_QUMU + " -d " + dst_ip + " -p " + port;
}
private String hdlcCmd(protocolGenerationEntity protocolGeneration) {
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.HDLC;
}
private String ftpCmd(protocolGenerationEntity protocolGeneration) {
String target_host = null;
String target_port = null;
try {
target_host = protocolGeneration.getParamJson()[0];
target_port = protocolGeneration.getParamJson()[1];
} catch (Exception e) {
log.error("frp参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.FTP + target_host + " " + target_port;
}
private String frpCmd(protocolGenerationEntity protocolGeneration) {
String target_host = null;
String target_port = null;
try {
target_host = protocolGeneration.getParamJson()[0];
target_port = protocolGeneration.getParamJson()[1];
} catch (Exception e) {
log.error("frp参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.FRP + target_host + " " + target_port;
}
private String dnsCmd(protocolGenerationEntity protocolGeneration) {
String dst_ip = null;
String dst_port = null;
try {
dst_ip = protocolGeneration.getParamJson()[0];
dst_port = protocolGeneration.getParamJson()[1];
} catch (Exception e) {
log.error("dns参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.DNS + dst_ip + " " + dst_port;
}
private String dhcpCmd(protocolGenerationEntity protocolGeneration) {
String dst_ip = null;
String dst_port = null;
try {
dst_ip = protocolGeneration.getParamJson()[0];
dst_port = protocolGeneration.getParamJson()[1];
} catch (Exception e) {
log.error("dhcp参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.DHCP + dst_ip + " " + dst_port;
}
private String bgpCmd(protocolGenerationEntity protocolGeneration) {
String src_ip = null;
String src_port = null;
String dst_ip = null;
String dst_port = null;
try {
src_ip = protocolGeneration.getParamJson()[0];
src_port = protocolGeneration.getParamJson()[1];
dst_ip = protocolGeneration.getParamJson()[2];
dst_port = protocolGeneration.getParamJson()[3];
} catch (Exception e) {
log.error("bgp参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.BGP + src_ip + " " + src_port + " " + dst_ip + " " + dst_port;
}
public String arpCmd(protocolGenerationEntity protocolGeneration) {
String dst_mac = null;
String src_mac = null;
try {
dst_mac = protocolGeneration.getParamJson()[0];
src_mac = protocolGeneration.getParamJson()[1];
} catch (Exception e) {
log.error("arp参数解析失败!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + protocolConstent.RAW + dst_mac + " " + src_mac;
}
}
package com.example.fuzzControll.service;
import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.pojo.vo.protocolGenerationEntity;
import org.springframework.web.multipart.MultipartFile;
public interface protocolTemplateService {
void generation(protocolGenerationEntity protocolGeneration);
}
...@@ -16,3 +16,7 @@ logging: ...@@ -16,3 +16,7 @@ logging:
filepath: filepath:
seedPath: "/home/qbq/aflnet/tutorials/live555/in-rtsp" seedPath: "/home/qbq/aflnet/tutorials/live555/in-rtsp"
kitty:
path: "/home/qbq/fuzz50/kitty/renix/" #kitty项目下的各协议生成模板python文件路径
venvPath: "/home/qbq/fuzz50/kitty/venv/bin/python"
methodPath: "/home/qbq/fuzz50/kitty/2020test/"#kitty下变异方法路径
\ No newline at end of file
# Global logging configuration
# 设置日志输出级别以及输出目的地,可以设置多个输出目的地,开发环境下,日志级别要设置成DEBUG或者ERROR
# 前面写日志级别,逗号后面写输出目的地:我自己下面设置的目的地相对应,以逗号分开
# log4j.rootLogger = [level],appenderName1,appenderName2,…
log4j.rootLogger=INFO,CONSOLE,LOGFILE
# log4j.rootLogger=DEBUG,CONSOLE,LOGFILE
#### 控制台输出 ####
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
# 输出到控制台
log4j.appender.CONSOLE.Target = System.out
# 指定控制台输出日志级别
# log4j.appender.CONSOLE.Threshold = DEBUG
# 默认值是 true, 表示是否立即输出
# log4j.appender.CONSOLE.ImmediateFlush = true
# 设置编码方式
log4j.appender.CONSOLE.Encoding = UTF-8
# 日志输出布局
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
# 如果日志输出布局为PatternLayout 自定义级别,需要使用ConversionPattern指定输出格式
log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %5p (%c:%L) >>> %m%n
#### 输出错误信息到文件 ####
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
# 指定输出文件路径
#log4j.appender.LOGFILE.File =F://Intellij idea/logs/error.log
log4j.appender.LOGFILE.File =./logs/error.log
#日志输出到文件,默认为true
log4j.appender.LOGFILE.Append = true
# 指定输出日志级别
# log4j.appender.LOGFILE.Threshold = ERROR
# 是否立即输出,默认值是 true,
# log4j.appender.LOGFILE.ImmediateFlush = true
# 设置编码方式
log4j.appender.LOGFILE.Encoding = UTF-8
# 日志输出布局
log4j.appender.LOGFILE.layout = org.apache.log4j.PatternLayout
# 如果日志输出布局为PatternLayout 自定义级别,需要使用ConversionPattern指定输出格式
log4j.appender.LOGFILE.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
...@@ -9,14 +9,13 @@ ...@@ -9,14 +9,13 @@
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://127.0.0.1:8080/websocket/testResult/" + "web"+100);
ws2 = new WebSocket("ws://127.0.0.1:8080/websocket/testResult/" + "backend"+100);
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) ;
const nameValue = Object.values(received_msg) const nameValue = Object.values(received_msg)
var context = '<div class="sendMsg">' + var context = '<div class="sendMsg">' +
'系统数据:<br/>'+ 'aflnet:<br/>'+
'时钟<h3>'+nameValue+'</h3><br/>'+ 'aflnet<h3>'+nameValue+'</h3><br/>'+
' </div>'; ' </div>';
document.getElementById("sendDiv").innerHTML = context; document.getElementById("sendDiv").innerHTML = context;
}; };
...@@ -25,15 +24,6 @@ ...@@ -25,15 +24,6 @@
// 关闭 websocket // 关闭 websocket
alert("连接已关闭..."); alert("连接已关闭...");
}; };
ws2.onmessage = function (evt) {
var received_msg = evt.data;
console.log("received")
alert("接收到数据:" + received_msg);
};
ws2.onclose = function () {
// 关闭 websocket
alert("连接已关闭...");
};
} }
</script> </script>
<body onload="javascript:myFunction()"> <body onload="javascript:myFunction()">
......
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