Commit 918202f5 by 钱炳权

aflnet结果读出成功

parent b66e695c
package com.example.fuzzControll.controller.dataController; package com.example.fuzzControll.controller.dataController;
import com.example.fuzzControll.pojo.vo.AflnetDataParams;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.AflnetPersistenceService; import com.example.fuzzControll.service.AflnetPersistenceService;
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.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController @RestController
@RequestMapping("/aflnet") @RequestMapping("/aflnet")
@Slf4j @Slf4j
public class AflnetDataController { public class AflnetDataController {
// @Autowired @Autowired
// AflnetPersistenceService aflnetPersistenceService; AflnetPersistenceService aflnetPersistenceService;
/**
* 读取数据库文件至指定目录
*/
@RequestMapping(value = "/loadFile", method = RequestMethod.GET)
public AjaxResult AflnetResultSelect(@RequestBody AflnetDataParams aflnetDataParams) {
try {
aflnetPersistenceService.loadInFile(aflnetDataParams.getMissionId(),aflnetDataParams.getFilPath());
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("File load failed!");
}
return AjaxResult.success("File loaded successfully!");
}
} }
package com.example.fuzzControll.controller.dataController; package com.example.fuzzControll.controller.dataController;
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.KittyResult; import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.FuzzPersistenceService; import com.example.fuzzControll.service.KittyFuzzPersistenceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -20,7 +16,7 @@ import java.util.List; ...@@ -20,7 +16,7 @@ import java.util.List;
@Slf4j @Slf4j
public class KittyDataController { public class KittyDataController {
@Autowired @Autowired
FuzzPersistenceService fuzzPersistenceService; KittyFuzzPersistenceService fuzzPersistenceService;
/** /**
* 查询kitty结果 * 查询kitty结果
*/ */
......
package com.example.fuzzControll.exception;
public class MysqlException extends BaseException{
private static final long serialVersionUID = 1L;
public MysqlException(String defaultMessage) {
super(defaultMessage, "mysql");
}
}
...@@ -14,8 +14,11 @@ public interface AflnetMapper { ...@@ -14,8 +14,11 @@ public interface AflnetMapper {
* 查询kitty模糊测试结果 * 查询kitty模糊测试结果
*/ */
// List<KittyResult> getKittyResults(); // List<KittyResult> getKittyResults();
/** /**
* 存储alfnet测试结果 * 存储alfnet测试结果
*/ */
int aflnetOutputBackup(AflnetResult aflnetResult); int aflnetOutputBackup(AflnetResult aflnetResult);
AflnetResult selectResultById(int missionId);
} }
...@@ -18,6 +18,7 @@ public interface KittyMapper { ...@@ -18,6 +18,7 @@ public interface KittyMapper {
void kittyResultsBackup(KittyResult kittyResult); void kittyResultsBackup(KittyResult kittyResult);
/** /**
* 查询kitty日志 * 查询kitty日志
*/ */
......
package com.example.fuzzControll.pojo.vo;
import lombok.Data;
@Data
public class AflnetDataParams {
private String filPath;
private int missionId;
public AflnetDataParams() {
}
public AflnetDataParams(String filPath, int missionId) {
this.filPath = filPath;
this.missionId = missionId;
}
}
...@@ -2,4 +2,5 @@ package com.example.fuzzControll.service; ...@@ -2,4 +2,5 @@ package com.example.fuzzControll.service;
public interface AflnetPersistenceService { public interface AflnetPersistenceService {
public int aflnetResultBackup(String filename); public int aflnetResultBackup(String filename);
public void loadInFile(int missionId,String filePath);
} }
...@@ -4,7 +4,8 @@ import com.example.fuzzControll.pojo.vo.KittyResult; ...@@ -4,7 +4,8 @@ import com.example.fuzzControll.pojo.vo.KittyResult;
import java.util.List; import java.util.List;
public interface FuzzPersistenceService { public interface KittyFuzzPersistenceService {
List<KittyResult> getKittyResults(); List<KittyResult> getKittyResults();
// void loadInFile(int missionId);
} }
package com.example.fuzzControll.service.impl; package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.exception.MysqlException;
import com.example.fuzzControll.mapper.AflnetMapper; import com.example.fuzzControll.mapper.AflnetMapper;
import com.example.fuzzControll.pojo.vo.AflnetResult; import com.example.fuzzControll.pojo.vo.AflnetResult;
import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.AflnetPersistenceService; import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.tools.FileTools; import com.example.fuzzControll.tools.FileTools;
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.stereotype.Service; import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service("AflnetPersistenceService") @Service("AflnetPersistenceService")
public class AflnetPersistenceServiceImpl implements AflnetPersistenceService { public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
@Autowired @Autowired
AflnetMapper AflnetMapper; AflnetMapper AflnetMapper;
FileTools fileTools = new FileTools(); FileTools fileTools = new FileTools();
@Override @Override
public int aflnetResultBackup(String filename) { public int aflnetResultBackup(String filename) {
//todo 需要传入任务id //todo 需要传入任务id
AflnetResult result = new AflnetResult(1,fileTools.fileReadAndBackup(filename),filename); AflnetResult result = new AflnetResult(1, fileTools.fileReadAndBackup(filename), filename);
return AflnetMapper.aflnetOutputBackup(result); return AflnetMapper.aflnetOutputBackup(result);
}
@Override
public void loadInFile(int missionId, String filePath) {
AflnetResult aflnetResult = null;
try {
aflnetResult = AflnetMapper.selectResultById(missionId);
} catch (MysqlException e) {
e.printStackTrace();
throw new MysqlException("AflnetMapper.selectResultById() Error!");
}
fileTools.loadFileInLocal(aflnetResult, filePath);
} }
} }
...@@ -2,7 +2,8 @@ package com.example.fuzzControll.service.impl; ...@@ -2,7 +2,8 @@ package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.mapper.KittyMapper; import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.pojo.vo.KittyResult; import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.FuzzPersistenceService; import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.service.KittyFuzzPersistenceService;
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.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -11,11 +12,15 @@ import java.util.List; ...@@ -11,11 +12,15 @@ import java.util.List;
@Service @Service
@Slf4j @Slf4j
public class FuzzPersistenceServiceImpl implements FuzzPersistenceService { public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceService {
@Autowired @Autowired
KittyMapper kittyMapper; KittyMapper kittyMapper;
@Autowired
AflnetPersistenceService aflnetPersistenceService;
@Override @Override
public List<KittyResult> getKittyResults() { public List<KittyResult> getKittyResults() {
return kittyMapper.getKittyResults(); return kittyMapper.getKittyResults();
} }
} }
...@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools; ...@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools;
import com.example.fuzzControll.conf.AflnetProperties; import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.conf.SpringContextUtil; import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.exception.FileException; import com.example.fuzzControll.exception.FileException;
import com.example.fuzzControll.pojo.vo.AflnetResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -32,6 +33,12 @@ public class FileTools { ...@@ -32,6 +33,12 @@ public class FileTools {
} }
/**
* 文件备份至数据库
*
* @param filename
* @return
*/
public byte[] fileReadAndBackup(String filename) { public byte[] fileReadAndBackup(String filename) {
File file = new File(properties.getOutputPath() + "/" + filename); File file = new File(properties.getOutputPath() + "/" + filename);
try ( try (
...@@ -52,4 +59,25 @@ public class FileTools { ...@@ -52,4 +59,25 @@ public class FileTools {
throw new RuntimeException("File is to large " + file.getName()); throw new RuntimeException("File is to large " + file.getName());
} }
} }
/**
* 读取数据库文件至本地
*/
public void loadFileInLocal(AflnetResult aflnetResult, String fileLoadPath) {
File file = new File(fileLoadPath+"/"+aflnetResult.getFileName());
try (FileOutputStream fileOutputStream = new FileOutputStream(file);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(aflnetResult.getFile());
BufferedInputStream bufferedInputStream = new BufferedInputStream(byteArrayInputStream);) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
bufferedOutputStream.write(buffer, 0, bytesRead);
}
} catch (FileNotFoundException e) {
throw new FileException("Cannot find path:" + fileLoadPath+"! Maybe there is no permission for this file!");
} catch (IOException e) {
throw new FileException("Load file failed!");
}
}
} }
\ No newline at end of file
...@@ -31,7 +31,7 @@ kitty: ...@@ -31,7 +31,7 @@ kitty:
vulnerabilityTypePath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/2020test/"#kitty下漏洞类型python路径 vulnerabilityTypePath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/2020test/"#kitty下漏洞类型python路径
mutationPath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/2020test/" mutationPath: "/usr/fuzzenv/fuzzenv/fuzz50/kitty/2020test/"
templateInfoHttp: "http://127.0.0.1:26001/api/template_info.json"#模板信息请求链接 templateInfoHttp: "http://127.0.0.1:26001/api/template_info.json"#模板信息请求链接
statsHttp: "http://127.0.0.1:26001/api/stats.json"#运行时数据 statsHttp: "http://127.0.0.1:26001"#运行时数据
stagesHttp: "http://127.0.0.1:26001/api/stages.json"# stagesHttp: "http://127.0.0.1:26001/api/stages.json"#
reportHttp: "http://127.0.0.1:26001/api/report"# reportHttp: "http://127.0.0.1:26001/api/report"#
spring: spring:
......
...@@ -11,12 +11,15 @@ ...@@ -11,12 +11,15 @@
<result property="fileName" column="fileName" /> <result property="fileName" column="fileName" />
</resultMap> </resultMap>
<sql id="selectKittyResult"> <sql id="selectAlfnetResult">
select id, missionId,file, fileName from kittyResult; select id, missionId,file, fileName from alfnetResult
</sql> </sql>
<insert id="aflnetOutputBackup"> <insert id="aflnetOutputBackup">
insert into alfnetResult(id,missionId, file, fileName) values(#{id}, #{missionId},#{file}, #{fileName}) insert into alfnetResult(id,missionId, file, fileName) values(#{id}, #{missionId},#{file}, #{fileName})
</insert> </insert>
<select id="selectResultById" resultMap="AflnetResult">
<include refid="selectAlfnetResult"/>
where missionId = #{missionId};
</select>
</mapper> </mapper>
\ 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