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
7b43576c
Commit
7b43576c
authored
May 16, 2024
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kitty数据报文件存入数据库成功
parent
918202f5
Show whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
276 additions
and
61 deletions
+276
-61
KittyProperties.java
...n/java/com/example/fuzzControll/conf/KittyProperties.java
+7
-1
KittyController.java
.../com/example/fuzzControll/controller/KittyController.java
+6
-5
KittyDataController.java
...ntroll/controller/dataController/KittyDataController.java
+18
-1
KittyMapper.java
...ain/java/com/example/fuzzControll/mapper/KittyMapper.java
+6
-2
KittyDataParams.java
...ava/com/example/fuzzControll/pojo/vo/KittyDataParams.java
+17
-0
KittyPackageFile.java
...va/com/example/fuzzControll/pojo/vo/KittyPackageFile.java
+81
-0
GenerateMethodService.java
...m/example/fuzzControll/service/GenerateMethodService.java
+1
-1
KittyFuzzPersistenceService.java
...ple/fuzzControll/service/KittyFuzzPersistenceService.java
+4
-1
MutationService.java
...ava/com/example/fuzzControll/service/MutationService.java
+1
-1
ProtocolTemplateService.java
...example/fuzzControll/service/ProtocolTemplateService.java
+1
-1
VulnerabilityTypeService.java
...xample/fuzzControll/service/VulnerabilityTypeService.java
+1
-1
AflnetPersistenceServiceImpl.java
...zzControll/service/impl/AflnetPersistenceServiceImpl.java
+8
-5
GenerateMethodServiceImpl.java
.../fuzzControll/service/impl/GenerateMethodServiceImpl.java
+2
-2
KittyFuzzPersistenceServiceImpl.java
...ontroll/service/impl/KittyFuzzPersistenceServiceImpl.java
+48
-3
MutationServiceImpl.java
...xample/fuzzControll/service/impl/MutationServiceImpl.java
+2
-2
ProtocolTemplateImpl.java
...ample/fuzzControll/service/impl/ProtocolTemplateImpl.java
+6
-2
VulnerabilityTypeServiceImpl.java
...zzControll/service/impl/VulnerabilityTypeServiceImpl.java
+2
-2
CmdTools.java
...rc/main/java/com/example/fuzzControll/tools/CmdTools.java
+24
-13
FileTools.java
...c/main/java/com/example/fuzzControll/tools/FileTools.java
+17
-16
GlobalParameters.java
...java/com/example/fuzzControll/tools/GlobalParameters.java
+2
-0
application-dev.yml
fuzzIntegration/src/main/resources/application-dev.yml
+2
-1
KittyMapper.xml
fuzzIntegration/src/main/resources/mapper/KittyMapper.xml
+19
-0
application.yml
fuzzbackendmaster/src/main/resources/application.yml
+1
-1
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/conf/KittyProperties.java
View file @
7b43576c
...
...
@@ -6,6 +6,7 @@ import org.springframework.stereotype.Component;
@Component
(
"kittyProperties"
)
@ConfigurationProperties
(
prefix
=
"kitty"
)
public
class
KittyProperties
{
String
logOutPath
;
String
path
;
String
venvPath
;
String
methodPath
;
...
...
@@ -16,8 +17,13 @@ public class KittyProperties {
String
reportHttp
;
String
mutationPath
;
public
String
getLogOutPath
()
{
return
logOutPath
;
}
public
void
setLogOutPath
(
String
logOutPath
)
{
this
.
logOutPath
=
logOutPath
;
}
public
String
getMutationPath
()
{
return
mutationPath
;
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/KittyController.java
View file @
7b43576c
...
...
@@ -39,8 +39,8 @@ public class KittyController {
*/
@RequestMapping
(
value
=
"/protocolTemplate"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
protocolTemplate
(
@RequestBody
TestEntity
testEntity
)
{
try
{
Map
<
String
,
List
<
String
>>
result
=
protocolTemplateService
.
generation
(
testEntity
);
try
{
//todo missionId
Map
<
String
,
List
<
String
>>
result
=
protocolTemplateService
.
generation
(
testEntity
,
1
);
return
AjaxResult
.
success
(
result
==
null
?
"模板文件生成未成功运行!第三方接口可能存在问题。"
:
result
);
}
catch
(
CmdException
|
FuzzException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
...
...
@@ -54,7 +54,8 @@ public class KittyController {
@RequestMapping
(
value
=
"/generate"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
generate
(
@RequestBody
TestEntity
testEntity
)
{
try
{
Map
<
String
,
List
<
String
>>
result
=
generateMethodService
.
generation
(
testEntity
);
//todo 需要传入missionId
Map
<
String
,
List
<
String
>>
result
=
generateMethodService
.
generation
(
testEntity
,
1
);
return
AjaxResult
.
success
(
result
==
null
?
"生成方法未成功运行!第三方接口可能存在问题。"
:
result
);
}
catch
(
CmdException
|
FuzzException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
...
...
@@ -68,7 +69,7 @@ public class KittyController {
@RequestMapping
(
value
=
"/mutation"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
mutation
(
@RequestBody
TestEntity
testEntity
)
{
try
{
Map
<
String
,
List
<
String
>>
result
=
mutationService
.
generation
(
testEntity
);
Map
<
String
,
List
<
String
>>
result
=
mutationService
.
generation
(
testEntity
,
1
);
return
AjaxResult
.
success
(
result
==
null
?
"mutationTest未成功运行!第三方接口可能存在问题。"
:
result
);
}
catch
(
CmdException
|
FuzzException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
...
...
@@ -82,7 +83,7 @@ public class KittyController {
@RequestMapping
(
value
=
"/vulnerabilityType"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
vulnerability
(
@RequestBody
TestEntity
testEntity
)
{
try
{
Map
<
String
,
List
<
String
>>
result
=
vulnerabilityTypeService
.
generation
(
testEntity
);
Map
<
String
,
List
<
String
>>
result
=
vulnerabilityTypeService
.
generation
(
testEntity
,
1
);
return
AjaxResult
.
success
(
result
==
null
?
"漏洞类型未成功运行!第三方接口可能存在问题。"
:
result
);
}
catch
(
CmdException
|
FuzzException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/dataController/KittyDataController.java
View file @
7b43576c
package
com
.
example
.
fuzzControll
.
controller
.
dataController
;
import
com.example.fuzzControll.pojo.vo.AjaxResult
;
import
com.example.fuzzControll.pojo.vo.KittyDataParams
;
import
com.example.fuzzControll.pojo.vo.KittyResult
;
import
com.example.fuzzControll.service.KittyFuzzPersistenceService
;
import
lombok.extern.slf4j.Slf4j
;
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
;
...
...
@@ -17,11 +19,12 @@ import java.util.List;
public
class
KittyDataController
{
@Autowired
KittyFuzzPersistenceService
fuzzPersistenceService
;
/**
* 查询kitty结果
*/
@RequestMapping
(
value
=
"/KittyResultSelect"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
KittyResultSelect
(
)
{
public
AjaxResult
KittyResultSelect
(
)
{
List
<
KittyResult
>
results
;
try
{
results
=
fuzzPersistenceService
.
getKittyResults
();
...
...
@@ -31,4 +34,18 @@ public class KittyDataController {
}
return
AjaxResult
.
success
(
results
);
}
/**
* 查询kittyPackage
*/
@RequestMapping
(
value
=
"/kittyPackageFileLoad"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
kittyPackageFileLoad
(
@RequestBody
KittyDataParams
kittyDataParams
)
{
try
{
fuzzPersistenceService
.
loadKittyLogFileInLocal
(
kittyDataParams
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
();
}
return
AjaxResult
.
success
(
"load success!"
);
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/mapper/KittyMapper.java
View file @
7b43576c
package
com
.
example
.
fuzzControll
.
mapper
;
import
com.example.fuzzControll.pojo.vo.KittyLog
;
import
com.example.fuzzControll.pojo.vo.KittyResult
;
import
com.example.fuzzControll.pojo.vo.KittyPackageFile
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Component
;
...
...
@@ -16,7 +16,11 @@ public interface KittyMapper {
*/
List
<
KittyResult
>
getKittyResults
();
void
kittyResultsBackup
(
KittyResult
kittyResult
);
int
kittyResultsBackup
(
KittyResult
kittyResult
);
int
kittyPackagesBackup
(
KittyPackageFile
kittyPackageFile
);
KittyPackageFile
getKittyPackageFileById
(
int
missionId
);
/**
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/pojo/vo/KittyDataParams.java
0 → 100644
View file @
7b43576c
package
com
.
example
.
fuzzControll
.
pojo
.
vo
;
import
lombok.Data
;
@Data
public
class
KittyDataParams
{
private
String
filPath
;
private
int
missionId
;
public
KittyDataParams
()
{
}
public
KittyDataParams
(
String
filPath
,
int
missionId
)
{
this
.
filPath
=
filPath
;
this
.
missionId
=
missionId
;
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/pojo/vo/KittyPackageFile.java
0 → 100644
View file @
7b43576c
package
com
.
example
.
fuzzControll
.
pojo
.
vo
;
import
lombok.Data
;
@Data
public
class
KittyPackageFile
{
private
int
id
;
private
int
missionId
;
private
String
kittyRecvFileName
;
private
String
kittySendFileName
;
private
byte
[]
kittyRecvFile
;
private
byte
[]
kittySendFile
;
public
KittyPackageFile
(
int
missionId
,
String
kittyRecvFileName
,
String
kittySendFileName
,
byte
[]
kittyRecvFile
,
byte
[]
kittySendFile
)
{
this
.
missionId
=
missionId
;
this
.
kittyRecvFileName
=
kittyRecvFileName
;
this
.
kittySendFileName
=
kittySendFileName
;
this
.
kittyRecvFile
=
kittyRecvFile
;
this
.
kittySendFile
=
kittySendFile
;
}
@Override
public
String
toString
()
{
return
"kittyPackageFile{"
+
"id="
+
id
+
", missionId="
+
missionId
+
", kittyRecvFileName='"
+
kittyRecvFileName
+
'\''
+
", kittySendFileName='"
+
kittySendFileName
+
'\''
+
", kittyRecvFile="
+
kittyRecvFile
.
length
+
", kittySendFile="
+
kittySendFile
.
length
+
'}'
;
}
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
int
getMissionId
()
{
return
missionId
;
}
public
void
setMissionId
(
int
missionId
)
{
this
.
missionId
=
missionId
;
}
public
String
getKittyRecvFileName
()
{
return
kittyRecvFileName
;
}
public
void
setKittyRecvFileName
(
String
kittyRecvFileName
)
{
this
.
kittyRecvFileName
=
kittyRecvFileName
;
}
public
String
getKittySendFileName
()
{
return
kittySendFileName
;
}
public
void
setKittySendFileName
(
String
kittySendFileName
)
{
this
.
kittySendFileName
=
kittySendFileName
;
}
public
byte
[]
getKittyRecvFile
()
{
return
kittyRecvFile
;
}
public
void
setKittyRecvFile
(
byte
[]
kittyRecvFile
)
{
this
.
kittyRecvFile
=
kittyRecvFile
;
}
public
byte
[]
getKittySendFile
()
{
return
kittySendFile
;
}
public
void
setKittySendFile
(
byte
[]
kittySendFile
)
{
this
.
kittySendFile
=
kittySendFile
;
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/GenerateMethodService.java
View file @
7b43576c
...
...
@@ -6,5 +6,5 @@ import java.util.List;
import
java.util.Map
;
public
interface
GenerateMethodService
{
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
);
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
);
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/KittyFuzzPersistenceService.java
View file @
7b43576c
package
com
.
example
.
fuzzControll
.
service
;
import
com.example.fuzzControll.pojo.vo.KittyDataParams
;
import
com.example.fuzzControll.pojo.vo.KittyResult
;
import
java.util.List
;
public
interface
KittyFuzzPersistenceService
{
List
<
KittyResult
>
getKittyResults
();
// void loadInFile(int missionId);
public
int
KittyPackagesBackup
(
int
missionId
);
public
int
kittyResultsBackup
(
KittyResult
kittyResult
);
void
loadKittyLogFileInLocal
(
KittyDataParams
kittyDataParams
);
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/MutationService.java
View file @
7b43576c
...
...
@@ -6,5 +6,5 @@ import java.util.List;
import
java.util.Map
;
public
interface
MutationService
{
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
);
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
);
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/ProtocolTemplateService.java
View file @
7b43576c
...
...
@@ -6,6 +6,6 @@ import java.util.List;
import
java.util.Map
;
public
interface
ProtocolTemplateService
{
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
);
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
);
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/VulnerabilityTypeService.java
View file @
7b43576c
...
...
@@ -6,5 +6,5 @@ import java.util.List;
import
java.util.Map
;
public
interface
VulnerabilityTypeService
{
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
);
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
);
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/AflnetPersistenceServiceImpl.java
View file @
7b43576c
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.example.fuzzControll.conf.AflnetProperties
;
import
com.example.fuzzControll.exception.MysqlException
;
import
com.example.fuzzControll.mapper.AflnetMapper
;
import
com.example.fuzzControll.pojo.vo.AflnetResult
;
...
...
@@ -14,26 +15,28 @@ import org.springframework.stereotype.Service;
@Service
(
"AflnetPersistenceService"
)
public
class
AflnetPersistenceServiceImpl
implements
AflnetPersistenceService
{
@Autowired
AflnetMapper
AflnetMapper
;
AflnetMapper
aflnetMapper
;
@Autowired
AflnetProperties
aflnetProperties
;
FileTools
fileTools
=
new
FileTools
();
@Override
public
int
aflnetResultBackup
(
String
filename
)
{
//todo 需要传入任务id
AflnetResult
result
=
new
AflnetResult
(
1
,
fileTools
.
fileReadAnd
Backup
(
filename
),
filename
);
return
A
flnetMapper
.
aflnetOutputBackup
(
result
);
AflnetResult
result
=
new
AflnetResult
(
1
,
fileTools
.
fileReadAnd
TranstoBytes
(
aflnetProperties
.
getOutputPath
(),
filename
),
filename
);
return
a
flnetMapper
.
aflnetOutputBackup
(
result
);
}
@Override
public
void
loadInFile
(
int
missionId
,
String
filePath
)
{
AflnetResult
aflnetResult
=
null
;
try
{
aflnetResult
=
A
flnetMapper
.
selectResultById
(
missionId
);
aflnetResult
=
a
flnetMapper
.
selectResultById
(
missionId
);
}
catch
(
MysqlException
e
)
{
e
.
printStackTrace
();
throw
new
MysqlException
(
"AflnetMapper.selectResultById() Error!"
);
}
fileTools
.
loadFileInLocal
(
aflnetResult
,
filePath
);
fileTools
.
loadFileInLocal
(
filePath
,
aflnetResult
.
getFileName
(),
aflnetResult
.
getFile
()
);
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/GenerateMethodServiceImpl.java
View file @
7b43576c
...
...
@@ -22,12 +22,12 @@ public class GenerateMethodServiceImpl implements GenerateMethodService {
KittyProperties
kitty
;
@Override
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
)
throws
FuzzException
,
CmdException
{
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
)
throws
FuzzException
,
CmdException
{
String
cmd
=
parseParameters
(
testEntity
);
if
(
cmd
.
isEmpty
())
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"generate"
,
missionId
);
}
public
String
parseParameters
(
TestEntity
testEntity
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/KittyFuzzPersistenceServiceImpl.java
View file @
7b43576c
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.example.fuzzControll.conf.KittyProperties
;
import
com.example.fuzzControll.constents.CmdConstent
;
import
com.example.fuzzControll.exception.MysqlException
;
import
com.example.fuzzControll.mapper.KittyMapper
;
import
com.example.fuzzControll.pojo.vo.KittyDataParams
;
import
com.example.fuzzControll.pojo.vo.KittyResult
;
import
com.example.fuzzControll.
service.AflnetPersistenceServic
e
;
import
com.example.fuzzControll.
pojo.vo.KittyPackageFil
e
;
import
com.example.fuzzControll.service.KittyFuzzPersistenceService
;
import
com.example.fuzzControll.tools.CmdTools
;
import
com.example.fuzzControll.tools.FileTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
@Service
(
"KittyFuzzPersistenceService"
)
@Slf4j
public
class
KittyFuzzPersistenceServiceImpl
implements
KittyFuzzPersistenceService
{
@Autowired
KittyMapper
kittyMapper
;
FileTools
fileTools
=
new
FileTools
();
CmdTools
cmdTools
=
new
CmdTools
();
@Autowired
AflnetPersistenceService
aflnetPersistenceService
;
KittyProperties
kittyProperties
;
@Override
public
List
<
KittyResult
>
getKittyResults
()
{
return
kittyMapper
.
getKittyResults
();
}
@Override
public
int
KittyPackagesBackup
(
int
missionId
)
{
List
<
String
>
files
=
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
kittyProperties
.
getLogOutPath
(),
"getKittyLogFiles"
);
if
(
files
.
size
()
>
3
)
{
log
.
error
(
"kittyLogs backup failed!"
);
}
System
.
out
.
println
(
"1"
);
List
<
String
>
logFiles
=
files
.
stream
().
filter
(
file
->
file
.
contains
(
"pcap"
)).
collect
(
Collectors
.
toList
());
logFiles
.
forEach
(
System
.
out
::
println
);
//todo 需要传入任务id
KittyPackageFile
kittyPackageFile
=
new
KittyPackageFile
(
1
,
logFiles
.
get
(
0
),
logFiles
.
get
(
1
),
fileTools
.
fileReadAndTranstoBytes
(
kittyProperties
.
getLogOutPath
(),
logFiles
.
get
(
0
)),
fileTools
.
fileReadAndTranstoBytes
(
kittyProperties
.
getLogOutPath
(),
logFiles
.
get
(
1
)));
System
.
out
.
println
(
kittyPackageFile
);
System
.
out
.
println
(
"2"
);
return
kittyMapper
.
kittyPackagesBackup
(
kittyPackageFile
);
}
@Override
public
int
kittyResultsBackup
(
KittyResult
kittyResult
)
{
return
kittyMapper
.
kittyResultsBackup
(
kittyResult
);
}
@Override
public
void
loadKittyLogFileInLocal
(
KittyDataParams
kittyDataParams
)
{
KittyPackageFile
kittyPackageFile
=
null
;
try
{
kittyPackageFile
=
kittyMapper
.
getKittyPackageFileById
(
kittyDataParams
.
getMissionId
());
}
catch
(
MysqlException
e
)
{
e
.
printStackTrace
();
throw
new
MysqlException
(
"KittyMapper.getKittyPackageFileById Error!"
);
}
fileTools
.
loadFileInLocal
(
kittyDataParams
.
getFilPath
(),
kittyPackageFile
.
getKittyRecvFileName
(),
kittyPackageFile
.
getKittyRecvFile
());
fileTools
.
loadFileInLocal
(
kittyDataParams
.
getFilPath
(),
kittyPackageFile
.
getKittySendFileName
(),
kittyPackageFile
.
getKittySendFile
());
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/MutationServiceImpl.java
View file @
7b43576c
...
...
@@ -24,12 +24,12 @@ class MutationServiceImpl implements MutationService {
@Override
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
)
throws
FuzzException
,
CmdException
{
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
)
throws
FuzzException
,
CmdException
{
String
cmd
=
parseParameters
(
testEntity
);
if
(
cmd
.
isEmpty
())
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"mutation"
,
missionId
);
}
public
String
parseParameters
(
TestEntity
testEntity
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/ProtocolTemplateImpl.java
View file @
7b43576c
...
...
@@ -2,12 +2,14 @@ package com.example.fuzzControll.service.impl;
import
com.example.fuzzControll.conf.KittyProperties
;
import
com.example.fuzzControll.constents.CmdConstent
;
import
com.example.fuzzControll.constents.ProtocolConstent
;
import
com.example.fuzzControll.exception.CmdException
;
import
com.example.fuzzControll.exception.FuzzException
;
import
com.example.fuzzControll.pojo.vo.TestEntity
;
import
com.example.fuzzControll.service.ProtocolTemplateService
;
import
com.example.fuzzControll.tools.CmdTools
;
import
com.example.fuzzControll.tools.GlobalParameters
;
import
com.example.fuzzControll.tools.TestTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -24,12 +26,14 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
KittyProperties
kitty
;
@Override
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
)
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");
String
cmd
=
parseParameters
(
testEntity
);
if
(
cmd
==
null
||
cmd
.
equals
(
""
))
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"protocolTemplate"
,
missionId
);
}
public
String
parseParameters
(
TestEntity
testEntity
)
throws
FuzzException
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/VulnerabilityTypeServiceImpl.java
View file @
7b43576c
...
...
@@ -21,12 +21,12 @@ public class VulnerabilityTypeServiceImpl implements VulnerabilityTypeService {
KittyProperties
kitty
;
@Override
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
)
throws
FuzzException
,
CmdException
{
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
,
int
missionId
)
throws
FuzzException
,
CmdException
{
String
cmd
=
parseParameters
(
testEntity
);
if
(
cmd
.
isEmpty
())
{
throw
new
FuzzException
(
"cmd is null ! The number of parameters does not match!"
);
}
return
cmdTools
.
runProgramCmdAndResult
(
cmd
);
return
cmdTools
.
runProgramCmdAndResult
(
cmd
,
"vulnerability"
,
missionId
);
}
public
String
parseParameters
(
TestEntity
testEntity
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/CmdTools.java
View file @
7b43576c
...
...
@@ -50,7 +50,7 @@ public class CmdTools {
* 运行需要后台运行cmd
* 通过websocket返回数据
*/
public
void
runProgramCmd
(
String
cmd
,
String
outputFileName
)
throws
AflnetException
{
public
void
runProgramCmd
(
String
cmd
,
String
outputFileName
)
throws
AflnetException
{
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
printMessageToWeb
(
process
.
getInputStream
());
...
...
@@ -67,31 +67,42 @@ public class CmdTools {
* 运行需要后台运行cmd
* 将数据存入文件中
*/
public
Map
<
String
,
List
<
String
>>
runProgramCmdAndResult
(
String
cmd
)
throws
CmdException
{
public
Map
<
String
,
List
<
String
>>
runProgramCmdAndResult
(
String
cmd
,
String
caller
,
int
missionId
)
throws
CmdException
{
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
();
List
<
String
>
out
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
List
<
String
>
error
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
printMessageByProgramCmd
(
process
.
getInputStream
(),
out
);
printMessageByProgramCmd
(
process
.
getErrorStream
(),
error
);
process
.
waitFor
();
// Process process = Runtime.getRuntime().exec(cmd);
// printMessageByProgramCmd(process.getInputStream(), out);
// printMessageByProgramCmd(process.getErrorStream(), error);
// process.waitFor();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
CmdException
(
"run fuzz error !"
);
}
result
.
put
(
"out"
,
out
);
result
.
put
(
"error"
,
error
);
//todo 对于无法运行和数据较长的还需要观察
/*新开一个线程存入数据*/
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
KittyResult
kittyResult
=
new
KittyResult
(
1
,
out
.
toString
(),
error
.
toString
());
/*kitty结果存入数据库*/
KittyResult
kittyResult
=
new
KittyResult
(
missionId
,
out
.
toString
(),
error
.
toString
());
GlobalParameters
.
kittyMapper
.
kittyResultsBackup
(
kittyResult
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"kitty backup error!"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
CmdException
(
"run fuzz error !"
);
/*kitty的协议模板方法的日志和数据包文件存入数据库*/
if
(
caller
.
equals
(
"protocolTemplate"
))
{
GlobalParameters
.
kittyFuzzPersistenceService
.
KittyPackagesBackup
(
missionId
);
}
result
.
put
(
"out"
,
out
);
result
.
put
(
"error"
,
error
);
}
}).
start
(
);
//todo 需要传入任务参数,后期再开发
return
result
;
}
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/FileTools.java
View file @
7b43576c
...
...
@@ -3,7 +3,6 @@ package com.example.fuzzControll.tools;
import
com.example.fuzzControll.conf.AflnetProperties
;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.exception.FileException
;
import
com.example.fuzzControll.pojo.vo.AflnetResult
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -39,35 +38,37 @@ public class FileTools {
* @param filename
* @return
*/
public
byte
[]
fileReadAndBackup
(
String
filename
)
{
File
file
=
new
File
(
properties
.
getOutputPath
()
+
"/"
+
filename
);
public
byte
[]
fileReadAndTranstoBytes
(
String
path
,
String
filename
)
{
File
file
=
new
File
(
path
+
filename
);
byte
[]
buffer
=
new
byte
[(
int
)
file
.
length
()];
try
(
FileInputStream
inputStream
=
new
FileInputStream
(
file
);
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
inputStream
);)
{
if
(
file
.
length
()
>
Integer
.
MAX_VALUE
)
{
throw
new
IOException
();
System
.
out
.
println
(
"1-2"
);
if
(
file
.
length
()
>
Integer
.
MAX_VALUE
&&
file
.
length
()
<=
0
)
{
log
.
error
(
"KittyLogFile is too long or has no content!"
);
}
byte
[]
buffer
=
new
byte
[(
int
)
file
.
length
()]
;
System
.
out
.
println
(
"1-3"
)
;
int
bytesRead
;
while
((
bytesRead
=
bufferedInputStream
.
read
(
buffer
))
!=
-
1
)
{
bufferedInputStream
.
read
(
buffer
,
0
,
bytesRead
);
System
.
out
.
println
(
buffer
.
length
);
}
return
buffer
;
}
catch
(
FileNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"File is to large "
+
file
.
getName
());
System
.
out
.
println
(
"1-5"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
buffer
;
}
/**
* 读取数据库文件至本地
*/
public
void
loadFileInLocal
(
AflnetResult
aflnetResult
,
String
fileLoadPath
)
{
File
file
=
new
File
(
fileLoadPath
+
"/"
+
aflnetResult
.
getFileName
()
);
public
void
loadFileInLocal
(
String
fileLoadPath
,
String
fileName
,
byte
[]
fileBytes
)
{
File
file
=
new
File
(
fileLoadPath
+
"/"
+
fileName
);
try
(
FileOutputStream
fileOutputStream
=
new
FileOutputStream
(
file
);
BufferedOutputStream
bufferedOutputStream
=
new
BufferedOutputStream
(
fileOutputStream
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
aflnetResult
.
getFile
()
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
fileBytes
);
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
byteArrayInputStream
);)
{
byte
[]
buffer
=
new
byte
[
1024
];
int
bytesRead
;
...
...
@@ -75,7 +76,7 @@ public class FileTools {
bufferedOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
}
catch
(
FileNotFoundException
e
)
{
throw
new
FileException
(
"Cannot find path:"
+
fileLoadPath
+
"! Maybe there is no permission for this file!"
);
throw
new
FileException
(
"Cannot find path:"
+
fileLoadPath
+
"! Maybe there is no permission for this file!"
);
}
catch
(
IOException
e
)
{
throw
new
FileException
(
"Load file failed!"
);
}
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/GlobalParameters.java
View file @
7b43576c
...
...
@@ -5,6 +5,7 @@ import com.example.fuzzControll.conf.KittyProperties;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.mapper.KittyMapper
;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.KittyFuzzPersistenceService
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -12,6 +13,7 @@ public class GlobalParameters {
public
static
ConcurrentHashMap
<
String
,
String
>
aflnetData
=
new
ConcurrentHashMap
<>();
//当前aflnet任务的数据
public
static
KittyMapper
kittyMapper
=
(
KittyMapper
)
SpringContextUtil
.
getBean
(
"KittyMapper"
);
public
static
KittyProperties
kittyProperties
=
(
KittyProperties
)
SpringContextUtil
.
getBean
(
"kittyProperties"
);
public
static
KittyFuzzPersistenceService
kittyFuzzPersistenceService
=(
KittyFuzzPersistenceService
)
SpringContextUtil
.
getBean
(
"KittyFuzzPersistenceService"
);
public
static
AflnetProperties
aflnetProperties
=
(
AflnetProperties
)
SpringContextUtil
.
getBean
(
"AflnetProperties"
);
public
static
AflnetPersistenceService
aflnetPersistenceService
=
(
AflnetPersistenceService
)
SpringContextUtil
.
getBean
(
"AflnetPersistenceService"
);
...
...
fuzzIntegration/src/main/resources/application-dev.yml
View file @
7b43576c
...
...
@@ -20,11 +20,12 @@ logging:
max-file-size
:
10MB
aflnet
:
seedPath
:
"
/usr/fuzzenv/fuzzenv/aflnet/tutorials/live555/in-rtsp"
seedPath
:
"
/usr/fuzzenv/fuzzenv/aflnet/tutorials/live555/in-rtsp"
#aflnet日志
outputPath
:
"
/home/"
#D:/code/companyProjects/files/
aflnetPath
:
"
/usr/fuzzenv/fuzzenv/"
#alfnet路径
kitty
:
logOutPath
:
"
/home/kittylogs/"
#kitty协议模板日志生成路径
path
:
"
/usr/fuzzenv/fuzzenv/fuzz50/kitty/renix/"
#kitty项目下的各协议生成模板python文件路径
venvPath
:
"
/usr/fuzzenv/fuzzenv/fuzz50/kitty/venv/bin/python"
methodPath
:
"
/usr/fuzzenv/fuzzenv/fuzz50/kitty/2020test/"
#kitty下变异方法路径
...
...
fuzzIntegration/src/main/resources/mapper/KittyMapper.xml
View file @
7b43576c
...
...
@@ -10,16 +10,34 @@
<result
property=
"resultOut"
column=
"resultOut"
/>
<result
property=
"resultError"
column=
"resultError"
/>
</resultMap>
<resultMap
type=
"com.example.fuzzControll.pojo.vo.KittyPackageFile"
id=
"kittyPackageFile"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"missionId"
column=
"missionId"
/>
<result
property=
"kittyRecvFile"
column=
"kittyRecvFile"
/>
<result
property=
"kittySendFile"
column=
"kittySendFile"
/>
<result
property=
"kittyRecvFileName"
column=
"kittyRecvFileName"
/>
<result
property=
"kittySendFileName"
column=
"kittySendFileName"
/>
</resultMap>
<sql
id=
"selectKittyResult"
>
select id, missionId,resultOut, resultError from kittyResult;
</sql>
<sql
id=
"selectKittyPackageFile"
>
select id,missionId, kittyRecvFile, kittySendFile,kittyRecvFileName,kittySendFileName from kittyPackageFile;
</sql>
<insert
id=
"kittyResultsBackup"
>
insert into kittyResult(id,missionId, resultOut, resultError) values(#{id}, #{missionId},#{resultOut}, #{resultError})
</insert>
<insert
id=
"kittyPackagesBackup"
>
insert into kittyPackageFile(id,missionId, kittyRecvFile, kittySendFile,kittyRecvFileName,kittySendFileName) values(#{id}, #{missionId},#{kittyRecvFile}, #{kittySendFile}, #{kittyRecvFileName}, #{kittySendFileName})
</insert>
<select
id=
"getKittyResults"
resultMap=
"KittyResult"
>
<include
refid=
"selectKittyResult"
/>
</select>
<select
id=
"getKittyPackageFileById"
resultType=
"com.example.fuzzControll.pojo.vo.KittyPackageFile"
>
<include
refid=
"selectKittyPackageFile"
/>
where missionId=#{missionId}
</select>
</mapper>
\ No newline at end of file
fuzzbackendmaster/src/main/resources/application.yml
View file @
7b43576c
...
...
@@ -5,6 +5,6 @@ spring:
active
:
dev
#默认为开发环境
server
:
port
:
810
1
port
:
810
4
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