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
99d14daf
Commit
99d14daf
authored
Aug 06, 2024
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常重放数据可获取
parent
167180d6
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
173 additions
and
7 deletions
+173
-7
AgentController.java
...zControll/controller/agentController/AgentController.java
+0
-1
AflnetDataController.java
...troll/controller/dataController/AflnetDataController.java
+42
-1
TestService.java
...in/java/com/example/fuzzControll/service/TestService.java
+5
-0
TestServiceImpl.java
...om/example/fuzzControll/service/impl/TestServiceImpl.java
+58
-3
FileTools.java
...n/java/com/example/fuzzControll/tools/file/FileTools.java
+26
-0
SystemRunningParams.java
...xample/fuzzControll/tools/system/SystemRunningParams.java
+6
-0
TestCmdTools.java
...ava/com/example/fuzzControll/tools/test/TestCmdTools.java
+5
-1
TestController.java
.../example/fuzzbackendmaster/controller/TestController.java
+17
-0
FuzzIntegrationFileApi.java
...ple/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
+14
-1
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/agentController/AgentController.java
View file @
99d14daf
...
...
@@ -3,7 +3,6 @@ package com.example.fuzzControll.controller.agentController;
import
com.example.fuzzControll.domain.bo.AflnetDataParams
;
import
com.example.fuzzControll.domain.vo.AjaxResult
;
import
com.example.fuzzControll.service.AgentOfKittyService
;
import
jdk.internal.agent.resources.agent
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/dataController/AflnetDataController.java
View file @
99d14daf
...
...
@@ -3,16 +3,24 @@ package com.example.fuzzControll.controller.dataController;
import
com.example.fuzzControll.domain.bo.AflnetDataParams
;
import
com.example.fuzzControll.domain.vo.AjaxResult
;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.TestService
;
import
com.example.fuzzControll.tools.test.TestCmdTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/aflnet"
)
@Slf4j
public
class
AflnetDataController
{
@Autowired
AflnetPersistenceService
aflnetPersistenceService
;
@Autowired
TestService
testService
;
TestCmdTools
testCmdTools
=
new
TestCmdTools
();
/**
* 读取数据库文件至指定目录
...
...
@@ -20,7 +28,7 @@ public class AflnetDataController {
@RequestMapping
(
value
=
"/loadFile"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
AflnetResultSelect
(
@RequestBody
AflnetDataParams
aflnetDataParams
)
{
try
{
aflnetPersistenceService
.
loadInFile
(
aflnetDataParams
.
getMissionId
(),
aflnetDataParams
.
getFilPath
());
aflnetPersistenceService
.
loadInFile
(
aflnetDataParams
.
getMissionId
(),
aflnetDataParams
.
getFilPath
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
(
"File load failed!"
);
...
...
@@ -28,4 +36,37 @@ public class AflnetDataController {
return
AjaxResult
.
success
(
"File loaded successfully!"
);
}
/**
* 异常重放(查看堆栈)
*/
@RequestMapping
(
value
=
"/replay"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
replay
(
@RequestParam
String
programPath
)
{
try
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
testService
.
replay
(
programPath
);
}
}).
start
();
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
(
"Replay failed!"
);
}
return
AjaxResult
.
success
(
"Start replay success!"
);
}
/**
* 读取异常定位分析结果
*/
@RequestMapping
(
value
=
"/getreplayresult"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
readReplayResult
()
{
List
<
String
>
result
=
new
ArrayList
<
String
>();
try
{
result
=
testService
.
getReplayResult
();
}
catch
(
Exception
e
)
{
return
AjaxResult
.
error
(
"Get replayResult failed!"
);
}
return
AjaxResult
.
success
(
result
);
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/TestService.java
View file @
99d14daf
...
...
@@ -3,6 +3,7 @@ package com.example.fuzzControll.service;
import
com.example.fuzzControll.domain.bo.CmdStartParams
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.concurrent.ConcurrentHashMap
;
public
interface
TestService
{
...
...
@@ -12,4 +13,8 @@ public interface TestService {
void
testStop
();
LinkedHashMap
<
String
,
String
>
getProcessInfo
();
void
replay
(
String
programPath
);
List
<
String
>
getReplayResult
();
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/TestServiceImpl.java
View file @
99d14daf
...
...
@@ -11,6 +11,7 @@ import com.example.fuzzControll.domain.bo.CmdStartParams;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.FuzzParamsService
;
import
com.example.fuzzControll.service.TestService
;
import
com.example.fuzzControll.tools.file.FileTools
;
import
com.example.fuzzControll.tools.system.GlobalClass
;
import
com.example.fuzzControll.tools.test.JsonUtils
;
import
com.example.fuzzControll.tools.test.TestCmdTools
;
...
...
@@ -22,8 +23,10 @@ import org.springframework.stereotype.Service;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.concurrent.ConcurrentHashMap
;
@Service
(
"testService"
)
...
...
@@ -44,21 +47,32 @@ public class TestServiceImpl implements TestService {
@Override
public
void
testStart
(
CmdStartParams
cmdStartParams
)
throws
AflnetException
,
CmdException
{
/*存入参数*/
System
.
out
.
println
(
JSON
.
toJSONString
(
cmdStartParams
)
);
System
.
out
.
println
(
"1111111111111111111111111111111111111111111111111111111111111111"
);
int
missionId
=
GlobalClass
.
missionInfoMapper
.
selectTopMissionId
()
+
1
;
boolean
flag
=
fuzzParamsService
.
saveFuzzParams
(
new
FuzzParams
(
JSON
.
toJSONString
(
cmdStartParams
),
new
Date
(),
missionId
));
boolean
flag
=
false
;
try
{
flag
=
fuzzParamsService
.
saveFuzzParams
(
new
FuzzParams
(
JSON
.
toJSONString
(
cmdStartParams
),
new
Date
(),
missionId
));
System
.
out
.
println
(
"flag = "
+
flag
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Save fuzz error:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
System
.
out
.
println
(
"2222222222222222222222222222222222222222222222222222222222222222"
);
if
(!
flag
)
{
log
.
error
(
"Save fuzzParams failed!"
);
throw
new
AflnetException
(
"Save params error!"
);
}
/*拼接指令*/
TestControlTools
.
setIsRunning
(
true
);
String
cmd
=
cmdTools
.
parse
(
cmdStartParams
);
System
.
out
.
println
(
"33333333333333333333333333333333333333333333333333333333333333333"
);
Date
date
=
new
Date
();
DateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd-hh-mm-ss-"
);
String
outputFileName
=
df
.
format
(
date
)
+
cmdStartParams
.
getProtopcol
()
+
"-output"
;
String
finalCmd
=
CmdConstent
.
RUN_AFLNET_BEFORE
+
outputFileName
+
CmdConstent
.
RUN_AFLNET_AFTER
+
cmd
+
aflnetProperties
.
getAflnetPath
()
+
"live555/testProgs/"
+
"testOnDemandRTSPServer 8554"
;
SystemRunningParams
.
aflnetData
.
put
(
"aflnetName"
,
outputFileName
);
log
.
info
(
"The cmd is [{}]"
,
finalCmd
);
System
.
out
.
println
(
"444444444444444444444444444444444444444444444444444444444444444444"
);
/*执行指令*/
System
.
out
.
println
(
"testStart"
);
cmdTools
.
runProgramCmd
(
finalCmd
,
outputFileName
+
".zip"
);
...
...
@@ -73,7 +87,48 @@ public class TestServiceImpl implements TestService {
}
@Override
public
LinkedHashMap
<
String
,
String
>
getProcessInfo
()
{
public
LinkedHashMap
<
String
,
String
>
getProcessInfo
()
{
return
SystemRunningParams
.
TestProgressMap
;
}
@Override
public
void
replay
(
String
programPath
)
{
String
cmd
=
"gdb /usr/fuzzenv/fuzzenv/live555/testProgs/"
+
programPath
+
" /usr/fuzzenv/fuzzenv/live555/testProgs/core"
+
" > /usr/dump.txt"
;
log
.
info
(
"Replay cmd is {}"
,
cmd
);
SystemRunningParams
.
ReplayResults
=
new
ArrayList
<>();
try
{
SystemRunningParams
.
ReplayResults
=
cmdTools
.
runCmd
(
cmd
,
"replay"
);
}
catch
(
CmdException
e
)
{
log
.
error
(
"Replay failed:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
@Override
public
List
<
String
>
getReplayResult
()
{
/*停止GDB*/
try
{
cmdTools
.
runCmd
(
"pkill gdb"
,
"getReplayResult-stopGdb"
);
}
catch
(
CmdException
e
)
{
log
.
error
(
"StopGdb failed:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
/*给程序停止并存放数据反应时间*/
try
{
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
/*读取文件内容到响应*/
// FileTools fileTools = new FileTools();
// List<String> result = null;
// try {
// result = fileTools.fileReadAndTranstoStringList("/usr/", "dump.txt");
// } catch (Exception e) {
// log.error("File read failed:{}", e.getMessage());
// throw new RuntimeException(e);
// }
return
SystemRunningParams
.
ReplayResults
;
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/file/FileTools.java
View file @
99d14daf
...
...
@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.List
;
@Slf4j
public
class
FileTools
{
...
...
@@ -78,4 +80,28 @@ public class FileTools {
throw
new
FileException
(
"Load file failed!"
);
}
}
/**
* 读取文件到字符串数组
*/
public
List
<
String
>
fileReadAndTranstoStringList
(
String
path
,
String
filename
)
{
File
file
=
new
File
(
path
+
filename
);
String
line
=
new
String
();
List
<
String
>
result
=
new
ArrayList
<
String
>();
try
(
FileInputStream
inputStream
=
new
FileInputStream
(
file
);
Reader
reader
=
new
InputStreamReader
(
inputStream
);
BufferedReader
bf
=
new
BufferedReader
(
reader
);)
{
if
(
file
.
length
()
>
Integer
.
MAX_VALUE
&&
file
.
length
()
<=
0
)
{
log
.
error
(
"File is too long or has no content!"
);
}
int
bytesRead
;
while
((
line
=
bf
.
readLine
())
!=
null
)
{
result
.
add
(
line
);
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
();
}
return
result
;
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/system/SystemRunningParams.java
View file @
99d14daf
package
com
.
example
.
fuzzControll
.
tools
.
system
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
...
...
@@ -38,6 +40,10 @@ public class SystemRunningParams {
*/
public
static
LinkedHashMap
<
String
,
String
>
TestProgressMap
=
new
LinkedHashMap
<>();
/**
* 异常重放数据
*/
public
static
List
<
String
>
ReplayResults
=
new
ArrayList
<>();
public
static
void
init
()
{
/*初始化aflnet和kitty时间参数*/
testTimeMessage
.
put
(
"aflnet"
,
new
ConcurrentHashMap
<>());
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/test/TestCmdTools.java
View file @
99d14daf
...
...
@@ -35,12 +35,13 @@ public class TestCmdTools {
*/
public
List
<
String
>
runCmd
(
String
cmd
,
String
caller
)
throws
CmdException
{
List
<
String
>
result
=
new
ArrayList
<
String
>();
List
<
String
>
error
=
new
ArrayList
<
String
>();
try
{
log
.
info
(
caller
+
" is running!"
);
log
.
info
(
"Running cmd:[{}]"
,
cmd
);
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
printMessage
(
process
.
getInputStream
(),
result
);
printMessage
(
process
.
getErrorStream
(),
new
ArrayList
<
String
>()
);
printMessage
(
process
.
getErrorStream
(),
error
);
process
.
waitFor
();
log
.
info
(
caller
+
" end!"
);
}
catch
(
Exception
e
)
{
...
...
@@ -318,6 +319,8 @@ public class TestCmdTools {
}
public
String
parse
(
CmdStartParams
cmdStartParams
)
throws
AflnetException
{
System
.
out
.
println
(
"************************1111111111111111111111"
);
System
.
out
.
println
(
"cmd is :"
+
cmdStartParams
);
if
(
cmdStartParams
==
null
)
{
throw
new
AflnetException
(
"CmdStartParams is null !"
);
}
...
...
@@ -358,6 +361,7 @@ public class TestCmdTools {
if
(
cmdStartParams
.
getSeedSelectionAlgo
()
!=
0
)
{
cmd
.
append
(
" -s "
+
cmdStartParams
.
getSeedSelectionAlgo
()
+
" "
);
}
System
.
out
.
println
(
"************************22222222222222222222222"
);
return
cmd
.
toString
();
}
...
...
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/TestController.java
View file @
99d14daf
...
...
@@ -46,4 +46,20 @@ public class TestController {
//停止时就开始关闭
return
fuzzIntegrationFileApi
.
getProcessInfo
();
}
/**
* 异常重放分析
*/
@RequestMapping
(
value
=
"/replay"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
replay
(
@RequestParam
String
programPath
)
{
return
fuzzIntegrationFileApi
.
replay
(
programPath
);
}
/**
* 异常结果获取
*/
@RequestMapping
(
value
=
"/getreplayresult"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getReplayResult
()
{
return
fuzzIntegrationFileApi
.
getReplayResult
(
);
}
}
\ No newline at end of file
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
View file @
99d14daf
...
...
@@ -117,13 +117,14 @@ public interface FuzzIntegrationFileApi {
* 开启网络代理
*/
@RequestMapping
(
value
=
"/agent/kittyNetworkAgent"
,
method
=
RequestMethod
.
GET
)
AjaxResult
startNetworkAgent
(
@RequestParam
String
networkCard
,
@RequestParam
String
monitorName
);
AjaxResult
startNetworkAgent
(
@RequestParam
String
networkCard
,
@RequestParam
String
monitorName
);
/**
* 获取代理生成的pcap文件
*/
@RequestMapping
(
value
=
"/agent/getAgentPcap"
,
method
=
RequestMethod
.
GET
)
byte
[]
getAgentPcap
();
/**
* 开启ssh代理
*/
...
...
@@ -131,4 +132,16 @@ public interface FuzzIntegrationFileApi {
AjaxResult
startSshAgent
(
@RequestParam
String
MonitorName
,
@RequestParam
String
SshUserName
,
@RequestParam
String
SshPassword
,
@RequestParam
String
SshIp
,
@RequestParam
String
SshPort
,
@RequestParam
String
Command
);
/**
* 异常重放分析
*/
@RequestMapping
(
value
=
"/aflnet/replay"
,
method
=
RequestMethod
.
GET
)
AjaxResult
replay
(
@RequestParam
String
programPath
);
/**
* 获取异常分析结果
*/
@RequestMapping
(
value
=
"/aflnet/getreplayresult"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getReplayResult
();
}
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