Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fuzzBackEnd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钱炳权
fuzzBackEnd
Commits
2adb74cf
Commit
2adb74cf
authored
May 22, 2024
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aflnet日志文件和kitty日志结果文件下载功能完成
parent
7b43576c
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
528 additions
and
43 deletions
+528
-43
TableClassEnum.java
...va/com/example/fuzzControll/constents/TableClassEnum.java
+30
-0
AlfnetController.java
...com/example/fuzzControll/controller/AlfnetController.java
+9
-4
FuzzLogController.java
...Controll/controller/dataController/FuzzLogController.java
+34
-0
MissionInfoController.java
...roll/controller/dataController/MissionInfoController.java
+34
-0
KittyMapper.java
...ain/java/com/example/fuzzControll/mapper/KittyMapper.java
+2
-0
MissionInfoMapper.java
...va/com/example/fuzzControll/mapper/MissionInfoMapper.java
+24
-0
FuzzLogTransEntity.java
.../com/example/fuzzControll/pojo/vo/FuzzLogTransEntity.java
+17
-0
MissionInfo.java
...in/java/com/example/fuzzControll/pojo/vo/MissionInfo.java
+35
-0
AflnetPersistenceService.java
...xample/fuzzControll/service/AflnetPersistenceService.java
+1
-1
FuzzLogService.java
...java/com/example/fuzzControll/service/FuzzLogService.java
+10
-0
AflnetPersistenceServiceImpl.java
...zzControll/service/impl/AflnetPersistenceServiceImpl.java
+19
-5
FuzzLogServiceImpl.java
...example/fuzzControll/service/impl/FuzzLogServiceImpl.java
+58
-0
GenerateMethodServiceImpl.java
.../fuzzControll/service/impl/GenerateMethodServiceImpl.java
+1
-1
MutationServiceImpl.java
...xample/fuzzControll/service/impl/MutationServiceImpl.java
+1
-1
ProtocolTemplateImpl.java
...ample/fuzzControll/service/impl/ProtocolTemplateImpl.java
+2
-2
TestServiceImpl.java
...om/example/fuzzControll/service/impl/TestServiceImpl.java
+1
-1
VulnerabilityTypeServiceImpl.java
...zzControll/service/impl/VulnerabilityTypeServiceImpl.java
+1
-1
CmdTools.java
...rc/main/java/com/example/fuzzControll/tools/CmdTools.java
+36
-21
FileTools.java
...c/main/java/com/example/fuzzControll/tools/FileTools.java
+7
-2
GlobalParameters.java
...java/com/example/fuzzControll/tools/GlobalParameters.java
+2
-1
application.yml
fuzzIntegration/src/main/resources/application.yml
+1
-1
KittyMapper.xml
fuzzIntegration/src/main/resources/mapper/KittyMapper.xml
+6
-1
MissionInfoMapper.xml
...tegration/src/main/resources/mapper/MissionInfoMapper.xml
+33
-0
FuzzLogController.java
...ample/fuzzbackendmaster/controller/FuzzLogController.java
+32
-0
MissionInfoController.java
...e/fuzzbackendmaster/controller/MissionInfoController.java
+25
-0
FuzzLogTransEntity.java
...example/fuzzbackendmaster/pojo/vo/FuzzLogTransEntity.java
+17
-0
FuzzIntegrationFileApi.java
...ple/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
+17
-0
FuzzLogService.java
...com/example/fuzzbackendmaster/service/FuzzLogService.java
+7
-0
FuzzLogServiceImpl.java
...le/fuzzbackendmaster/service/impl/FuzzLogServiceImpl.java
+42
-0
FileTools.java
...n/java/com/example/fuzzbackendmaster/utils/FileTools.java
+23
-0
application.yml
fuzzbackendmaster/src/main/resources/application.yml
+1
-1
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/constents/TableClassEnum.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
constents
;
public
enum
TableClassEnum
{
AFLNET
(
"alfnetResult"
,
1
),
KITTY_PACKAGE
(
"kittyPackageFile"
,
2
),
KITTY_RESULT
(
"kittyResult"
,
3
);
private
String
tableName
;
private
int
tableId
;
private
TableClassEnum
(
String
tableName
,
int
tableId
)
{
this
.
tableName
=
tableName
;
this
.
tableId
=
tableId
;
}
public
String
getTableName
()
{
return
tableName
;
}
public
void
setTableName
(
String
tableName
)
{
this
.
tableName
=
tableName
;
}
public
int
getTableId
()
{
return
tableId
;
}
public
void
setTableId
(
int
tableId
)
{
this
.
tableId
=
tableId
;
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/AlfnetControler.java
→
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/AlfnetControl
l
er.java
View file @
2adb74cf
...
@@ -3,9 +3,11 @@ package com.example.fuzzControll.controller;
...
@@ -3,9 +3,11 @@ package com.example.fuzzControll.controller;
import
com.example.fuzzControll.exception.AflnetException
;
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.exception.MysqlException
;
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.CmdStartParams
;
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
;
...
@@ -19,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -19,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/test"
)
@RequestMapping
(
"/test"
)
public
class
AlfnetControler
{
public
class
AlfnetControl
l
er
{
@Autowired
@Autowired
TestService
service
;
TestService
service
;
...
@@ -30,15 +32,16 @@ public class AlfnetControler {
...
@@ -30,15 +32,16 @@ public class AlfnetControler {
public
AjaxResult
start
(
@RequestBody
final
CmdStartParams
cmdStartParams
)
{
public
AjaxResult
start
(
@RequestBody
final
CmdStartParams
cmdStartParams
)
{
//todo 捕获子线程错误
//todo 捕获子线程错误
try
{
try
{
new
Thread
(
new
Runnable
()
{
GlobalParameters
.
aflnetData
.
put
(
"missionName"
,
cmdStartParams
.
getProtopcol
());
new
Thread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
service
.
testStart
(
cmdStartParams
);
service
.
testStart
(
cmdStartParams
);
}
}
}).
start
();
}).
start
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
e
instanceof
AflnetException
||
e
instanceof
CmdException
)
{
if
(
e
instanceof
AflnetException
||
e
instanceof
CmdException
)
{
log
.
error
(((
BaseException
)
e
).
getDefaultMessage
());
log
.
error
(((
BaseException
)
e
).
getDefaultMessage
());
}
}
return
AjaxResult
.
error
(
"测试启动失败!"
);
return
AjaxResult
.
error
(
"测试启动失败!"
);
}
}
...
@@ -55,6 +58,8 @@ public class AlfnetControler {
...
@@ -55,6 +58,8 @@ public class AlfnetControler {
}
catch
(
AflnetException
e
)
{
}
catch
(
AflnetException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
log
.
error
(
e
.
getDefaultMessage
());
return
AjaxResult
.
error
(
"测试停止失败!"
);
return
AjaxResult
.
error
(
"测试停止失败!"
);
}
catch
(
MysqlException
e
){
log
.
error
(
"File backup error: "
+
e
.
getMessage
());
}
}
return
AjaxResult
.
success
(
"测试停止成功!"
);
return
AjaxResult
.
success
(
"测试停止成功!"
);
}
}
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/dataController/FuzzLogController.java
0 → 100644
View file @
2adb74cf
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.FuzzLogTransEntity
;
import
com.example.fuzzControll.service.FuzzLogService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@RestController
@RequestMapping
(
"/log"
)
@Slf4j
public
class
FuzzLogController
{
@Autowired
FuzzLogService
FuzzLogService
;
/**
* 下载对应任务的日志;不同任务返回数据类型不同,需要做个表来区分
*/
@RequestMapping
(
value
=
"/download/{missionId}"
,
method
=
RequestMethod
.
GET
)
public
FuzzLogTransEntity
getFuzzLog
(
@PathVariable
(
"missionId"
)
int
missionId
)
throws
IOException
{
try
{
return
FuzzLogService
.
getFuzzLog
(
missionId
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/dataController/MissionInfoController.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
controller
.
dataController
;
import
com.example.fuzzControll.mapper.MissionInfoMapper
;
import
com.example.fuzzControll.pojo.vo.AjaxResult
;
import
com.example.fuzzControll.pojo.vo.FuzzLogTransEntity
;
import
lombok.extern.slf4j.Slf4j
;
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.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.IOException
;
@RestController
@RequestMapping
(
"/mission"
)
@Slf4j
public
class
MissionInfoController
{
@Autowired
MissionInfoMapper
missionInfoMapper
;
/**
* 查看任务信息
*/
@RequestMapping
(
value
=
"/getList"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getMissionInfo
()
throws
IOException
{
try
{
return
AjaxResult
.
success
(
missionInfoMapper
.
selectMissionInfoList
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
(
"SelectMissionInfoList error!"
);
}
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/mapper/KittyMapper.java
View file @
2adb74cf
...
@@ -22,6 +22,8 @@ public interface KittyMapper {
...
@@ -22,6 +22,8 @@ public interface KittyMapper {
KittyPackageFile
getKittyPackageFileById
(
int
missionId
);
KittyPackageFile
getKittyPackageFileById
(
int
missionId
);
KittyResult
getKittyResultByMissionId
(
int
missionId
);
/**
/**
* 查询kitty日志
* 查询kitty日志
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/mapper/MissionInfoMapper.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
mapper
;
import
com.example.fuzzControll.pojo.vo.MissionInfo
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
@Mapper
@Component
(
"MissionInfoMapper"
)
public
interface
MissionInfoMapper
{
MissionInfo
selectByMissionId
(
int
missionId
);
/**
* 查询任务信息列表
*/
List
<
MissionInfo
>
selectMissionInfoList
();
/**
* 查询当前任务Id
*/
int
selectTopMissionId
();
void
insertMission
(
MissionInfo
missionInfo
);
}
fuzzIntegration/src/main/java/com/example/fuzzControll/pojo/vo/FuzzLogTransEntity.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
pojo
.
vo
;
import
lombok.Data
;
@Data
public
class
FuzzLogTransEntity
{
private
byte
[]
file
;
private
String
name
;
public
FuzzLogTransEntity
(
byte
[]
file
,
String
name
)
{
this
.
file
=
file
;
this
.
name
=
name
;
}
public
FuzzLogTransEntity
()
{
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/pojo/vo/MissionInfo.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
pojo
.
vo
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
java.util.Date
;
@Data
public
class
MissionInfo
{
@JsonIgnore
private
int
id
;
private
int
missionId
;
@JsonIgnore
private
int
tableId
;
//返回数据忽略字段
private
Date
createTime
;
private
String
missionName
;
public
MissionInfo
()
{
}
public
MissionInfo
(
int
id
,
int
missionId
,
int
tableId
,
Date
createTime
,
String
missionName
)
{
this
.
id
=
id
;
this
.
missionId
=
missionId
;
this
.
tableId
=
tableId
;
this
.
createTime
=
createTime
;
this
.
missionName
=
missionName
;
}
public
MissionInfo
(
int
missionId
,
int
tableId
,
Date
createTime
,
String
missionName
)
{
this
.
missionId
=
missionId
;
this
.
tableId
=
tableId
;
this
.
createTime
=
createTime
;
this
.
missionName
=
missionName
;
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/AflnetPersistenceService.java
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
service
;
package
com
.
example
.
fuzzControll
.
service
;
public
interface
AflnetPersistenceService
{
public
interface
AflnetPersistenceService
{
public
int
aflnetResultBackup
(
String
filename
);
public
int
aflnetResultBackup
(
String
filename
,
String
missionName
);
public
void
loadInFile
(
int
missionId
,
String
filePath
);
public
void
loadInFile
(
int
missionId
,
String
filePath
);
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/FuzzLogService.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
service
;
import
com.example.fuzzControll.pojo.vo.FuzzLogTransEntity
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
public
interface
FuzzLogService
{
FuzzLogTransEntity
getFuzzLog
(
int
missionId
)
throws
IllegalAccessException
;
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/AflnetPersistenceServiceImpl.java
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
service
.
impl
;
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.example.fuzzControll.conf.AflnetProperties
;
import
com.example.fuzzControll.conf.AflnetProperties
;
import
com.example.fuzzControll.constents.TableClassEnum
;
import
com.example.fuzzControll.exception.MysqlException
;
import
com.example.fuzzControll.exception.MysqlException
;
import
com.example.fuzzControll.mapper.AflnetMapper
;
import
com.example.fuzzControll.mapper.AflnetMapper
;
import
com.example.fuzzControll.mapper.MissionInfoMapper
;
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.pojo.vo.KittyResult
;
import
com.example.fuzzControll.pojo.vo.MissionInfo
;
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
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
@Slf4j
@Slf4j
@Service
(
"AflnetPersistenceService"
)
@Service
(
"AflnetPersistenceService"
)
...
@@ -18,13 +24,13 @@ public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
...
@@ -18,13 +24,13 @@ public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
AflnetMapper
aflnetMapper
;
AflnetMapper
aflnetMapper
;
@Autowired
@Autowired
AflnetProperties
aflnetProperties
;
AflnetProperties
aflnetProperties
;
@Autowired
MissionInfoMapper
missionInfoMapper
;
FileTools
fileTools
=
new
FileTools
();
FileTools
fileTools
=
new
FileTools
();
@Override
@Override
public
int
aflnetResultBackup
(
String
filename
)
{
public
int
aflnetResultBackup
(
String
filename
,
String
missionName
)
{
//todo 需要传入任务id
return
mysqlTransaction
(
filename
,
missionName
);
AflnetResult
result
=
new
AflnetResult
(
1
,
fileTools
.
fileReadAndTranstoBytes
(
aflnetProperties
.
getOutputPath
(),
filename
),
filename
);
return
aflnetMapper
.
aflnetOutputBackup
(
result
);
}
}
@Override
@Override
...
@@ -36,7 +42,15 @@ public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
...
@@ -36,7 +42,15 @@ public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
MysqlException
(
"AflnetMapper.selectResultById() Error!"
);
throw
new
MysqlException
(
"AflnetMapper.selectResultById() Error!"
);
}
}
fileTools
.
loadFileInLocal
(
filePath
,
aflnetResult
.
getFileName
(),
aflnetResult
.
getFile
());
fileTools
.
loadFileInLocal
(
filePath
,
aflnetResult
.
getFileName
(),
aflnetResult
.
getFile
());
}
}
@Transactional
(
rollbackFor
=
MysqlException
.
class
)
public
int
mysqlTransaction
(
String
filename
,
String
missionName
)
{
int
topMissionId
=
missionInfoMapper
.
selectTopMissionId
()
+
1
;
//获取最新的missionId
AflnetResult
result
=
new
AflnetResult
(
topMissionId
,
fileTools
.
fileReadAndTranstoBytes
(
aflnetProperties
.
getOutputPath
(),
filename
),
filename
);
aflnetMapper
.
aflnetOutputBackup
(
result
);
//存入日志文件
missionInfoMapper
.
insertMission
(
new
MissionInfo
(
topMissionId
,
TableClassEnum
.
AFLNET
.
getTableId
(),
new
Date
(),
missionName
));
//插入任务信息
return
1
;
}
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/FuzzLogServiceImpl.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.example.fuzzControll.mapper.AflnetMapper
;
import
com.example.fuzzControll.mapper.KittyMapper
;
import
com.example.fuzzControll.mapper.MissionInfoMapper
;
import
com.example.fuzzControll.pojo.vo.AflnetResult
;
import
com.example.fuzzControll.pojo.vo.FuzzLogTransEntity
;
import
com.example.fuzzControll.pojo.vo.KittyResult
;
import
com.example.fuzzControll.pojo.vo.MissionInfo
;
import
com.example.fuzzControll.service.FuzzLogService
;
import
com.example.fuzzControll.tools.FileTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
@Slf4j
@Service
(
"FuzzLogService"
)
public
class
FuzzLogServiceImpl
implements
FuzzLogService
{
@Autowired
MissionInfoMapper
missionInfoMapper
;
@Autowired
AflnetMapper
aflnetMapper
;
@Autowired
KittyMapper
kittyMapper
;
FileTools
fileTools
=
new
FileTools
();
@Override
public
FuzzLogTransEntity
getFuzzLog
(
int
missionId
)
throws
IllegalAccessException
{
MissionInfo
missionInfo
=
missionInfoMapper
.
selectByMissionId
(
missionId
);
if
(
missionInfo
==
null
)
{
return
null
;
}
switch
(
missionInfo
.
getTableId
())
{
case
1
:
return
downloadAflnetFile
(
missionInfo
);
// case 2:return downloadKittyProtocalFile(missionInfo);
case
3
:
return
downloadKittyOtherMethodFile
(
missionInfo
);
default
:
throw
new
IllegalAccessException
(
"Invalid mission!"
);
}
}
private
FuzzLogTransEntity
downloadKittyOtherMethodFile
(
MissionInfo
missionInfo
)
{
KittyResult
kittyResult
=
kittyMapper
.
getKittyResultByMissionId
(
missionInfo
.
getMissionId
());
StringBuffer
buffer
=
new
StringBuffer
();
buffer
.
append
(
kittyResult
.
getResultError
()).
append
(
System
.
lineSeparator
()).
append
(
kittyResult
.
getResultOut
());
return
new
FuzzLogTransEntity
(
buffer
.
toString
().
getBytes
(),
missionInfo
.
getMissionName
()+
".txt"
);
}
private
FuzzLogTransEntity
downloadAflnetFile
(
MissionInfo
missionInfo
)
{
AflnetResult
aflnetResult
=
aflnetMapper
.
selectResultById
(
missionInfo
.
getMissionId
());
return
new
FuzzLogTransEntity
(
aflnetResult
.
getFile
(),
aflnetResult
.
getFileName
());
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/GenerateMethodServiceImpl.java
View file @
2adb74cf
...
@@ -27,7 +27,7 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
...
@@ -27,7 +27,7 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
if
(
cmd
.
isEmpty
())
{
if
(
cmd
.
isEmpty
())
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"generate"
,
missionId
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"generate"
,
"Generate-"
+
testEntity
.
getTestClassName
()
);
}
}
public
String
parseParameters
(
TestEntity
testEntity
)
{
public
String
parseParameters
(
TestEntity
testEntity
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/MutationServiceImpl.java
View file @
2adb74cf
...
@@ -29,7 +29,7 @@ class MutationServiceImpl implements MutationService {
...
@@ -29,7 +29,7 @@ class MutationServiceImpl implements MutationService {
if
(
cmd
.
isEmpty
())
{
if
(
cmd
.
isEmpty
())
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"mutation"
,
missionId
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"mutation"
,
"Mutation-"
+
testEntity
.
getTestClassName
()
);
}
}
public
String
parseParameters
(
TestEntity
testEntity
)
{
public
String
parseParameters
(
TestEntity
testEntity
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/ProtocolTemplateImpl.java
View file @
2adb74cf
...
@@ -28,12 +28,12 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
...
@@ -28,12 +28,12 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
@Override
@Override
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
)
throws
FuzzException
,
CmdException
{
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
)
throws
FuzzException
,
CmdException
{
/*生成日志前先清除日志*/
/*生成日志前先清除日志*/
//
cmdTools.runCmd(CmdConstent.DELETE_FILE + GlobalParameters.kittyProperties.getLogOutPath(),"delete kittyLogs");
cmdTools
.
runCmd
(
CmdConstent
.
DELETE_FILE
+
GlobalParameters
.
kittyProperties
.
getLogOutPath
(),
"delete kittyLogs"
);
String
cmd
=
parseParameters
(
testEntity
);
String
cmd
=
parseParameters
(
testEntity
);
if
(
cmd
==
null
||
cmd
.
equals
(
""
))
{
if
(
cmd
==
null
||
cmd
.
equals
(
""
))
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"protocolTemplate"
,
missionId
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"protocolTemplate"
,
"ProtocolTemplate-"
+
testEntity
.
getTestClassName
()
);
}
}
public
String
parseParameters
(
TestEntity
testEntity
)
throws
FuzzException
{
public
String
parseParameters
(
TestEntity
testEntity
)
throws
FuzzException
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/TestServiceImpl.java
View file @
2adb74cf
...
@@ -63,7 +63,7 @@ public class TestServiceImpl implements TestService {
...
@@ -63,7 +63,7 @@ public class TestServiceImpl implements TestService {
cmdTools
.
runCmd
(
CmdConstent
.
RUN_ZIP_FILE
+
fileZipName
+
" "
+
fileName
,
"zip file in testStart"
);
cmdTools
.
runCmd
(
CmdConstent
.
RUN_ZIP_FILE
+
fileZipName
+
" "
+
fileName
,
"zip file in testStart"
);
List
<
String
>
files
=
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
aflnetProperties
.
getOutputPath
(),
"getSeedFiles"
);
List
<
String
>
files
=
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
aflnetProperties
.
getOutputPath
(),
"getSeedFiles"
);
while
(
files
.
contains
(
fileZipName
)
&&
flag
==
0
)
{
//当前存在压缩包才存入
while
(
files
.
contains
(
fileZipName
)
&&
flag
==
0
)
{
//当前存在压缩包才存入
flag
=
aflnetPersistenceService
.
aflnetResultBackup
(
fileZipName
);
flag
=
aflnetPersistenceService
.
aflnetResultBackup
(
fileZipName
,
GlobalParameters
.
aflnetData
.
get
(
"missionName"
)
);
}
}
/*清除生成的文件*/
/*清除生成的文件*/
try
{
try
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/VulnerabilityTypeServiceImpl.java
View file @
2adb74cf
...
@@ -26,7 +26,7 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
...
@@ -26,7 +26,7 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
if
(
cmd
.
isEmpty
())
{
if
(
cmd
.
isEmpty
())
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"vulnerability"
,
missionId
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"vulnerability"
,
"Vulnerability-"
+
testEntity
.
getTestClassName
()
);
}
}
public
String
parseParameters
(
TestEntity
testEntity
)
{
public
String
parseParameters
(
TestEntity
testEntity
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/CmdTools.java
View file @
2adb74cf
...
@@ -4,20 +4,22 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -4,20 +4,22 @@ import com.alibaba.fastjson.JSONObject;
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.constents.CmdConstent
;
import
com.example.fuzzControll.constents.CmdConstent
;
import
com.example.fuzzControll.constents.TableClassEnum
;
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.exception.MysqlException
;
import
com.example.fuzzControll.mapper.KittyMapper
;
import
com.example.fuzzControll.mapper.KittyMapper
;
import
com.example.fuzzControll.pojo.vo.CmdStartParams
;
import
com.example.fuzzControll.pojo.vo.*
;
import
com.example.fuzzControll.pojo.vo.KittyResult
;
import
com.example.fuzzControll.pojo.vo.TestReturnEntity
;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.impl.websocketClientServiceImpl
;
import
com.example.fuzzControll.service.impl.websocketClientServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.swing.*
;
import
javax.swing.*
;
import
java.io.*
;
import
java.io.*
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
//todo need modify
//todo need modify
...
@@ -67,39 +69,31 @@ public class CmdTools {
...
@@ -67,39 +69,31 @@ public class CmdTools {
* 运行需要后台运行cmd
* 运行需要后台运行cmd
* 将数据存入文件中
* 将数据存入文件中
*/
*/
public
Map
<
String
,
List
<
String
>>
runProgramCmdAndResult
(
String
cmd
,
String
caller
,
int
missionId
)
throws
CmdException
{
public
Map
<
String
,
List
<
String
>>
runProgramCmdAndResult
(
String
cmd
,
String
caller
,
String
missionName
)
throws
CmdException
{
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
();
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
();
List
<
String
>
out
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
List
<
String
>
out
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
List
<
String
>
error
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
List
<
String
>
error
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
try
{
try
{
//
Process process = Runtime.getRuntime().exec(cmd);
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
//
printMessageByProgramCmd(process.getInputStream(), out);
printMessageByProgramCmd
(
process
.
getInputStream
(),
out
);
//
printMessageByProgramCmd(process.getErrorStream(), error);
printMessageByProgramCmd
(
process
.
getErrorStream
(),
error
);
//
process.waitFor();
process
.
waitFor
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
CmdException
(
"run fuzz error !"
);
throw
new
CmdException
(
"run fuzz error !"
);
}
}
out
=
out
.
stream
().
map
(
s
->
s
+
System
.
lineSeparator
()).
collect
(
Collectors
.
toList
());
error
=
error
.
stream
().
map
(
s
->
s
+
System
.
lineSeparator
()).
collect
(
Collectors
.
toList
());
result
.
put
(
"out"
,
out
);
result
.
put
(
"out"
,
out
);
result
.
put
(
"error"
,
error
);
result
.
put
(
"error"
,
error
);
//todo 对于无法运行和数据较长的还需要观察
//todo 对于无法运行和数据较长的还需要观察
/*新开一个线程存入数据*/
/*新开一个线程存入数据*/
List
<
String
>
finalOut
=
out
;
List
<
String
>
finalError
=
error
;
new
Thread
(
new
Runnable
()
{
new
Thread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
dataBackUpTransaction
(
caller
,
finalOut
,
finalError
,
missionName
);
/*kitty结果存入数据库*/
KittyResult
kittyResult
=
new
KittyResult
(
missionId
,
out
.
toString
(),
error
.
toString
());
GlobalParameters
.
kittyMapper
.
kittyResultsBackup
(
kittyResult
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"kitty backup error!"
);
}
/*kitty的协议模板方法的日志和数据包文件存入数据库*/
if
(
caller
.
equals
(
"protocolTemplate"
))
{
GlobalParameters
.
kittyFuzzPersistenceService
.
KittyPackagesBackup
(
missionId
);
}
}
}
}).
start
();
}).
start
();
//todo 需要传入任务参数,后期再开发
//todo 需要传入任务参数,后期再开发
...
@@ -306,4 +300,24 @@ public class CmdTools {
...
@@ -306,4 +300,24 @@ public class CmdTools {
return
cmd
.
toString
();
return
cmd
.
toString
();
}
}
@Transactional
(
rollbackFor
=
MysqlException
.
class
)
public
void
dataBackUpTransaction
(
String
caller
,
List
<
String
>
out
,
List
<
String
>
error
,
String
missionName
)
{
int
missionId
=
GlobalParameters
.
missionInfoMapper
.
selectTopMissionId
()
+
1
;
try
{
/*kitty结果存入数据库*/
KittyResult
kittyResult
=
new
KittyResult
(
missionId
,
out
.
toString
(),
error
.
toString
());
GlobalParameters
.
kittyMapper
.
kittyResultsBackup
(
kittyResult
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"kitty backup error!"
);
}
/*kitty的协议模板方法的日志和数据包文件存入数据库*/
if
(
caller
.
equals
(
"protocolTemplate"
))
{
GlobalParameters
.
kittyFuzzPersistenceService
.
KittyPackagesBackup
(
missionId
);
GlobalParameters
.
missionInfoMapper
.
insertMission
(
new
MissionInfo
(
missionId
,
2
,
new
Date
(),
missionName
));
}
else
{
/*存入missionInfo信息*/
GlobalParameters
.
missionInfoMapper
.
insertMission
(
new
MissionInfo
(
missionId
,
3
,
new
Date
(),
missionName
));
}
}
}
}
\ No newline at end of file
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/FileTools.java
View file @
2adb74cf
...
@@ -4,8 +4,12 @@ import com.example.fuzzControll.conf.AflnetProperties;
...
@@ -4,8 +4,12 @@ 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
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.io.*
;
@Slf4j
@Slf4j
...
@@ -81,4 +85,6 @@ public class FileTools {
...
@@ -81,4 +85,6 @@ public class FileTools {
throw
new
FileException
(
"Load file failed!"
);
throw
new
FileException
(
"Load file failed!"
);
}
}
}
}
}
\ No newline at end of file
}
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/GlobalParameters.java
View file @
2adb74cf
...
@@ -4,6 +4,7 @@ import com.example.fuzzControll.conf.AflnetProperties;
...
@@ -4,6 +4,7 @@ import com.example.fuzzControll.conf.AflnetProperties;
import
com.example.fuzzControll.conf.KittyProperties
;
import
com.example.fuzzControll.conf.KittyProperties
;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.mapper.KittyMapper
;
import
com.example.fuzzControll.mapper.KittyMapper
;
import
com.example.fuzzControll.mapper.MissionInfoMapper
;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.KittyFuzzPersistenceService
;
import
com.example.fuzzControll.service.KittyFuzzPersistenceService
;
...
@@ -16,5 +17,5 @@ public class GlobalParameters {
...
@@ -16,5 +17,5 @@ public class GlobalParameters {
public
static
KittyFuzzPersistenceService
kittyFuzzPersistenceService
=(
KittyFuzzPersistenceService
)
SpringContextUtil
.
getBean
(
"KittyFuzzPersistenceService"
);
public
static
KittyFuzzPersistenceService
kittyFuzzPersistenceService
=(
KittyFuzzPersistenceService
)
SpringContextUtil
.
getBean
(
"KittyFuzzPersistenceService"
);
public
static
AflnetProperties
aflnetProperties
=
(
AflnetProperties
)
SpringContextUtil
.
getBean
(
"AflnetProperties"
);
public
static
AflnetProperties
aflnetProperties
=
(
AflnetProperties
)
SpringContextUtil
.
getBean
(
"AflnetProperties"
);
public
static
AflnetPersistenceService
aflnetPersistenceService
=
(
AflnetPersistenceService
)
SpringContextUtil
.
getBean
(
"AflnetPersistenceService"
);
public
static
AflnetPersistenceService
aflnetPersistenceService
=
(
AflnetPersistenceService
)
SpringContextUtil
.
getBean
(
"AflnetPersistenceService"
);
public
static
MissionInfoMapper
missionInfoMapper
=
(
MissionInfoMapper
)
SpringContextUtil
.
getBean
(
"MissionInfoMapper"
);
}
}
fuzzIntegration/src/main/resources/application.yml
View file @
2adb74cf
...
@@ -5,6 +5,6 @@ spring:
...
@@ -5,6 +5,6 @@ spring:
active
:
dev
#默认为开发环境
active
:
dev
#默认为开发环境
server
:
server
:
port
:
810
3
port
:
810
4
fuzzIntegration/src/main/resources/mapper/KittyMapper.xml
View file @
2adb74cf
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
</resultMap>
</resultMap>
<sql
id=
"selectKittyResult"
>
<sql
id=
"selectKittyResult"
>
select id, missionId,resultOut, resultError from kittyResult
;
select id, missionId,resultOut, resultError from kittyResult
</sql>
</sql>
<sql
id=
"selectKittyPackageFile"
>
<sql
id=
"selectKittyPackageFile"
>
select id,missionId, kittyRecvFile, kittySendFile,kittyRecvFileName,kittySendFileName from kittyPackageFile;
select id,missionId, kittyRecvFile, kittySendFile,kittyRecvFileName,kittySendFileName from kittyPackageFile;
...
@@ -39,5 +39,9 @@
...
@@ -39,5 +39,9 @@
<include
refid=
"selectKittyPackageFile"
/>
<include
refid=
"selectKittyPackageFile"
/>
where missionId=#{missionId}
where missionId=#{missionId}
</select>
</select>
<select
id=
"getKittyResultByMissionId"
resultType=
"com.example.fuzzControll.pojo.vo.KittyResult"
>
<include
refid=
"selectKittyResult"
/>
where missionId = #{missionId}
</select>
</mapper>
</mapper>
\ No newline at end of file
fuzzIntegration/src/main/resources/mapper/MissionInfoMapper.xml
0 → 100644
View file @
2adb74cf
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.example.fuzzControll.mapper.MissionInfoMapper"
>
<resultMap
type=
"com.example.fuzzControll.pojo.vo.MissionInfo"
id=
"MissionInfo"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"missionId"
column=
"missionId"
/>
<result
property=
"tableId"
column=
"tableId"
/>
<result
property=
"createTime"
column=
"createTime"
/>
<result
property=
"missionName"
column=
"missionName"
/>
</resultMap>
<sql
id=
"selectMissionInfo"
>
select id, missionId,tableId, createTime,missionName from missionIdInfo
</sql>
<insert
id=
"insertMission"
>
insert into missionIdInfo(missionId,tableId, createTime,missionName) values(#{missionId}, #{tableId},#{createTime}, #{missionName})
</insert>
<select
id=
"selectByMissionId"
resultMap=
"MissionInfo"
>
<include
refid=
"selectMissionInfo"
/>
where missionId = #{missionId}
</select>
<select
id=
"selectMissionInfoList"
resultType=
"com.example.fuzzControll.pojo.vo.MissionInfo"
>
<include
refid=
"selectMissionInfo"
/>
</select>
<select
id=
"selectTopMissionId"
resultType=
"java.lang.Integer"
>
select IFNULL((select missionId from missionIdInfo order by missionId desc limit 1),0) as missionId;
</select>
</mapper>
\ No newline at end of file
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/FuzzLogController.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzbackendmaster
.
controller
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
com.example.fuzzbackendmaster.service.FuzzLogService
;
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.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@RestController
@RequestMapping
(
"/log"
)
public
class
FuzzLogController
{
@Autowired
FuzzLogService
fuzzLogService
;
/**
* 下载对应任务的日志;不同任务返回数据类型不同,需要做个表来区分
*/
@RequestMapping
(
value
=
"/download/{missionId}"
,
method
=
RequestMethod
.
GET
)
public
void
getFuzzLog
(
@PathVariable
(
"missionId"
)
int
missionId
,
HttpServletResponse
response
)
throws
IOException
{
try
{
fuzzLogService
.
getFuzzLog
(
missionId
,
response
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
response
.
sendError
(
500
,
"Download failed!"
);
}
}
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/MissionInfoController.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzbackendmaster
.
controller
;
import
com.example.fuzzbackendmaster.pojo.vo.AjaxResult
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.IOException
;
@RestController
@RequestMapping
(
"/log"
)
public
class
MissionInfoController
{
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
/**
* 查看任务信息
*/
@RequestMapping
(
value
=
"/getList"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getMissionInfo
()
throws
IOException
{
return
fuzzIntegrationFileApi
.
selectMissionInfoList
();
}
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/pojo/vo/FuzzLogTransEntity.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzbackendmaster
.
pojo
.
vo
;
import
lombok.Data
;
@Data
public
class
FuzzLogTransEntity
{
private
byte
[]
file
;
private
String
name
;
public
FuzzLogTransEntity
(
byte
[]
file
,
String
name
)
{
this
.
file
=
file
;
this
.
name
=
name
;
}
public
FuzzLogTransEntity
()
{
}
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
View file @
2adb74cf
...
@@ -2,6 +2,7 @@ package com.example.fuzzbackendmaster.service;
...
@@ -2,6 +2,7 @@ package com.example.fuzzbackendmaster.service;
import
com.example.fuzzbackendmaster.pojo.vo.AjaxResult
;
import
com.example.fuzzbackendmaster.pojo.vo.AjaxResult
;
import
com.example.fuzzbackendmaster.pojo.vo.CmdStartParams
;
import
com.example.fuzzbackendmaster.pojo.vo.CmdStartParams
;
import
com.example.fuzzbackendmaster.pojo.vo.FuzzLogTransEntity
;
import
com.example.fuzzbackendmaster.pojo.vo.TestEntity
;
import
com.example.fuzzbackendmaster.pojo.vo.TestEntity
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
...
@@ -10,6 +11,8 @@ import org.springframework.stereotype.Service;
...
@@ -10,6 +11,8 @@ import org.springframework.stereotype.Service;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
import
java.util.List
;
...
@@ -56,15 +59,29 @@ public interface FuzzIntegrationFileApi {
...
@@ -56,15 +59,29 @@ public interface FuzzIntegrationFileApi {
@RequestMapping
(
value
=
"/kittyServer/templateInfo"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/kittyServer/templateInfo"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getTemplateInfo
();
AjaxResult
getTemplateInfo
();
@RequestMapping
(
value
=
"/kittyServer/stages"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/kittyServer/stages"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getStages
();
AjaxResult
getStages
();
@RequestMapping
(
value
=
"/kittyServer/report"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/kittyServer/report"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getReport
();
AjaxResult
getReport
();
/**
/**
* websocket
* websocket
*/
*/
@RequestMapping
(
value
=
"/websocket/connect"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/websocket/connect"
,
method
=
RequestMethod
.
GET
)
void
connect
();
void
connect
();
@RequestMapping
(
value
=
"/websocket/disConnect"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/websocket/disConnect"
,
method
=
RequestMethod
.
GET
)
void
disconnect
();
void
disconnect
();
@RequestMapping
(
value
=
"/log/download/{missionId}"
,
method
=
RequestMethod
.
GET
)
FuzzLogTransEntity
getFuzzLog
(
@PathVariable
(
"missionId"
)
int
missionId
);
/**
* 查询任务信息
* @return
*/
@RequestMapping
(
value
=
"/mission/getList"
,
method
=
RequestMethod
.
GET
)
AjaxResult
selectMissionInfoList
();
}
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzLogService.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzbackendmaster
.
service
;
import
javax.servlet.http.HttpServletResponse
;
public
interface
FuzzLogService
{
void
getFuzzLog
(
int
missionId
,
HttpServletResponse
response
)
throws
IllegalAccessException
;
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/impl/FuzzLogServiceImpl.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzbackendmaster
.
service
.
impl
;
import
com.example.fuzzbackendmaster.pojo.vo.FuzzLogTransEntity
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
com.example.fuzzbackendmaster.service.FuzzLogService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.OutputStream
;
@Service
(
"FuzzLogService"
)
public
class
FuzzLogServiceImpl
implements
FuzzLogService
{
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
@Override
public
void
getFuzzLog
(
int
missionId
,
HttpServletResponse
response
)
throws
IllegalAccessException
{
FuzzLogTransEntity
fuzzLogTransEntity
=
fuzzIntegrationFileApi
.
getFuzzLog
(
missionId
);
if
(
fuzzLogTransEntity
==
null
&&
fuzzLogTransEntity
.
getFile
()
==
null
)
{
throw
new
IllegalStateException
();
}
downloadFile
(
fuzzLogTransEntity
.
getName
(),
fuzzLogTransEntity
.
getFile
(),
response
);
}
/**
* 浏览器前端下载后台文件,文件为二进制格式
*/
public
void
downloadFile
(
String
fileName
,
byte
[]
file
,
HttpServletResponse
response
)
{
if
(
fileName
!=
null
&&
!
""
.
equals
(
fileName
))
{
if
(
file
!=
null
&&
file
.
length
!=
0
)
{
response
.
setContentType
(
"application/force-download"
);
// 设置强制下载不打开
response
.
addHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
fileName
);
// 设置文件名
try
(
OutputStream
os
=
response
.
getOutputStream
();)
{
os
.
write
(
file
,
0
,
file
.
length
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/utils/FileTools.java
0 → 100644
View file @
2adb74cf
package
com
.
example
.
fuzzbackendmaster
.
utils
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.OutputStream
;
public
class
FileTools
{
/**
* 浏览器前端下载后台文件,文件为二进制格式
*/
public
void
downloadFile
(
String
fileName
,
byte
[]
file
,
HttpServletResponse
response
)
{
if
(
fileName
!=
null
&&
!
fileName
.
equals
(
""
))
{
if
(
file
!=
null
&&
file
.
length
!=
0
)
{
response
.
setContentType
(
"application/force-download"
);
// 设置强制下载不打开
response
.
addHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
fileName
);
// 设置文件名
try
(
OutputStream
os
=
response
.
getOutputStream
();)
{
os
.
write
(
file
,
0
,
file
.
length
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
fuzzbackendmaster/src/main/resources/application.yml
View file @
2adb74cf
...
@@ -5,6 +5,6 @@ spring:
...
@@ -5,6 +5,6 @@ spring:
active
:
dev
#默认为开发环境
active
:
dev
#默认为开发环境
server
:
server
:
port
:
810
4
port
:
810
3
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment