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
167180d6
Commit
167180d6
authored
9 months ago
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加监控代理接口和pcap文件下载接口
parent
9d5c8d46
qbq-dev
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
273 additions
and
7 deletions
+273
-7
AgentController.java
...zControll/controller/agentController/AgentController.java
+73
-0
AgentOfKittyService.java
...com/example/fuzzControll/service/AgentOfKittyService.java
+10
-0
AgentOfKittyServiceImpl.java
...le/fuzzControll/service/impl/AgentOfKittyServiceImpl.java
+61
-0
FileTools.java
...n/java/com/example/fuzzControll/tools/file/FileTools.java
+1
-1
TestCmdTools.java
...ava/com/example/fuzzControll/tools/test/TestCmdTools.java
+1
-0
application-dev.yml
fuzzIntegration/src/main/resources/application-dev.yml
+4
-3
KittyAgentController.java
...le/fuzzbackendmaster/controller/KittyAgentController.java
+74
-0
FuzzIntegrationFileApi.java
...ple/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
+24
-1
KittyAgentService.java
.../example/fuzzbackendmaster/service/KittyAgentService.java
+7
-0
KittyAgentServiceImpl.java
...fuzzbackendmaster/service/impl/KittyAgentServiceImpl.java
+16
-0
application-dev.yml
fuzzbackendmaster/src/main/resources/application-dev.yml
+1
-1
result.html
fuzzbackendmaster/src/main/resources/result.html
+1
-1
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/agentController/AgentController.java
0 → 100644
View file @
167180d6
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.*
;
@RestController
@RequestMapping
(
"/agent"
)
@Slf4j
public
class
AgentController
{
@Autowired
AgentOfKittyService
agentOfKittyService
;
/**
* 网络代理启动
*/
//todo 启动有问题;代码待检查;给/etc/profile 加进入python虚拟环境
@RequestMapping
(
value
=
"/kittyNetworkAgent"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
startNetworkAgent
(
@RequestParam
String
networkCard
,
@RequestParam
String
monitorName
)
{
try
{
Boolean
flag
=
agentOfKittyService
.
startNetworkAgent
(
networkCard
,
monitorName
);
if
(
flag
)
{
return
AjaxResult
.
success
(
"NetworkAgent run success!"
);
}
else
{
return
AjaxResult
.
error
(
"The agent failed to start!"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
(
"The agent failed to start!"
);
}
}
/**
* ssh代理启动
*/
//todo ssh使用存在问题我的理解是用来监控目标服务器的,通过ssh发送命令来监控
@RequestMapping
(
value
=
"/kittySshAgent"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
startSshAgent
(
@RequestParam
String
MonitorName
,
@RequestParam
String
SshUserName
,
@RequestParam
String
SshPassword
,
@RequestParam
String
SshIp
,
@RequestParam
String
SshPort
,
@RequestParam
String
Command
)
{
try
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
agentOfKittyService
.
startSshAgent
(
MonitorName
,
SshUserName
,
SshPassword
,
SshIp
,
SshPort
,
Command
);
}
}).
start
();
return
AjaxResult
.
success
(
"SshAgent run success!"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
(
"The agent failed to start!"
);
}
}
/**
* ssh网络代理的pcap文件下载接口
*/
//todo ssh使用存在问题我的理解是用来监控目标服务器的,通过ssh发送命令来监控
@RequestMapping
(
value
=
"/getAgentPcap"
,
method
=
RequestMethod
.
GET
)
public
byte
[]
getAgentPcap
()
{
try
{
return
agentOfKittyService
.
readPcapToByte
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/AgentOfKittyService.java
0 → 100644
View file @
167180d6
package
com
.
example
.
fuzzControll
.
service
;
import
java.util.List
;
public
interface
AgentOfKittyService
{
Boolean
startNetworkAgent
(
String
networkCard
,
String
monitorName
);
Boolean
startSshAgent
(
String
monitorName
,
String
sshUserName
,
String
sshPassword
,
String
sshIp
,
String
sshPort
,
String
command
);
byte
[]
readPcapToByte
();
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/AgentOfKittyServiceImpl.java
0 → 100644
View file @
167180d6
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.example.fuzzControll.exception.testException.CmdException
;
import
com.example.fuzzControll.service.AgentOfKittyService
;
import
com.example.fuzzControll.tools.file.FileTools
;
import
com.example.fuzzControll.tools.test.TestCmdTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
@Slf4j
public
class
AgentOfKittyServiceImpl
implements
AgentOfKittyService
{
@Override
public
Boolean
startNetworkAgent
(
String
networkCard
,
String
monitorName
)
{
try
{
String
finalCmd
=
"python /usr/fuzzenv/fuzzenv/fuzz50/katnip/katnip/monitors/network.py "
+
networkCard
+
" "
+
monitorName
;
TestCmdTools
cmdTools
=
new
TestCmdTools
();
List
<
String
>
result
=
cmdTools
.
runCmd
(
finalCmd
,
"startNetworkAgent"
);
List
<
String
>
filter
=
result
.
stream
().
filter
(
s
->
s
.
contains
(
"calling mon.teardown"
)).
collect
(
Collectors
.
toList
());
log
.
info
(
"Network Agent:{}"
,
(
Object
)
StringUtils
.
toStringArray
(
result
));
return
filter
.
size
()
>
0
;
}
catch
(
CmdException
e
)
{
log
.
error
(
"startNetworkAgent run error:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
@Override
public
Boolean
startSshAgent
(
String
monitorName
,
String
sshUserName
,
String
sshPassword
,
String
sshIp
,
String
sshPort
,
String
command
)
{
try
{
String
finalCmd
=
"python /usr/fuzzenv/fuzzenv/fuzz50/katnip/katnip/monitors/ssh.py "
+
monitorName
+
" "
+
sshUserName
+
" "
+
sshPassword
+
" "
+
sshIp
+
" "
+
sshPort
+
" "
+
command
;
TestCmdTools
cmdTools
=
new
TestCmdTools
();
List
<
String
>
result
=
cmdTools
.
runCmd
(
finalCmd
,
"startSshAgent"
);
List
<
String
>
filter
=
result
.
stream
().
filter
(
s
->
s
.
contains
(
"Failed to stop thread"
)).
collect
(
Collectors
.
toList
());
return
!(
filter
.
size
()
>
0
);
}
catch
(
CmdException
e
)
{
log
.
error
(
"startNetworkAgent run error:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
@Override
public
byte
[]
readPcapToByte
()
{
byte
[]
fileByts
=
new
byte
[
0
];
try
{
FileTools
fileTools
=
new
FileTools
();
fileByts
=
fileTools
.
fileReadAndTranstoBytes
(
"/tmp/"
,
"test_1.pcap"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"readPcapToByte error:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
return
fileByts
;
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/file/FileTools.java
View file @
167180d6
...
...
@@ -50,7 +50,7 @@ public class FileTools {
}
int
bytesRead
;
while
((
bytesRead
=
bufferedInputStream
.
read
(
buffer
))
!=
-
1
)
{
System
.
out
.
println
(
buffer
.
length
);
log
.
info
(
"File reading ...."
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/test/TestCmdTools.java
View file @
167180d6
...
...
@@ -37,6 +37,7 @@ public class TestCmdTools {
List
<
String
>
result
=
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
>());
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/resources/application-dev.yml
View file @
167180d6
...
...
@@ -49,11 +49,11 @@ integrationpath:
webSocketUri
:
ws://${fuzzmaster-docker.ip}:8101/websocket/testResult/
nacos-docker
:
ip
:
192.168.
50.251
ip
:
192.168.
2.247
fuzzmaster-docker
:
ip
:
192.168.
50.251
ip
:
192.168.
2.247
mysql-docker
:
ip
:
192.168.
50.251
ip
:
192.168.
2.247
port
:
3307
\ No newline at end of file
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/KittyAgentController.java
0 → 100644
View file @
167180d6
package
com
.
example
.
fuzzbackendmaster
.
controller
;
import
com.example.fuzzbackendmaster.pojo.vo.AjaxResult
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
com.example.fuzzbackendmaster.service.FuzzLogService
;
import
com.example.fuzzbackendmaster.service.KittyAgentService
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.rmi.RemoteException
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.EmptyStackException
;
@RestController
@RequestMapping
(
"/agent"
)
@Slf4j
public
class
KittyAgentController
{
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
@Autowired
KittyAgentService
kittyAgentService
;
/**
* 启动网络代理
*
*/
@RequestMapping
(
value
=
"/kittyNetworkAgent"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
startNetworkAgent
(
@RequestParam
String
networkCard
,
@RequestParam
String
monitorName
)
{
try
{
return
fuzzIntegrationFileApi
.
startNetworkAgent
(
networkCard
,
monitorName
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Start network agent error:{}"
,
e
.
getMessage
());
return
AjaxResult
.
error
();
}
}
/**
* 启动ssh代理
*/
@RequestMapping
(
value
=
"/kittySshAgent"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
startSshAgent
(
@RequestParam
String
MonitorName
,
@RequestParam
String
SshUserName
,
@RequestParam
String
SshPassword
,
@RequestParam
String
SshIp
,
@RequestParam
String
SshPort
,
@RequestParam
String
Command
)
{
try
{
return
fuzzIntegrationFileApi
.
startSshAgent
(
MonitorName
,
SshUserName
,
SshPassword
,
SshIp
,
SshPort
,
Command
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Start network agent error:{}"
,
e
.
getMessage
());
return
AjaxResult
.
error
();
}
}
/**
* 下载对应任务的日志;不同任务返回数据类型不同,需要做个表来区分
*/
@RequestMapping
(
value
=
"/getAgentPcap"
,
method
=
RequestMethod
.
GET
)
public
void
getAgentPcap
(
HttpServletResponse
response
)
throws
IOException
{
try
{
byte
[]
fileBytes
=
fuzzIntegrationFileApi
.
getAgentPcap
();
if
(
fileBytes
==
null
||
fileBytes
.
length
==
0
)
{
throw
new
RemoteException
(
"Pcap file is null!"
);
}
Date
date
=
new
Date
();
DateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd-hh-mm-ss-"
);
kittyAgentService
.
downloadPcap
(
df
.
format
(
date
)
+
"kitty.pcap"
,
fileBytes
,
response
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
response
.
sendError
(
500
,
"Download failed!"
);
}
}
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
View file @
167180d6
...
...
@@ -77,10 +77,12 @@ public interface FuzzIntegrationFileApi {
/**
* 查询任务信息
*
* @return
*/
@RequestMapping
(
value
=
"/mission/getList"
,
method
=
RequestMethod
.
GET
)
AjaxResult
selectMissionInfoList
();
/**
* 查询测试参数
*/
...
...
@@ -89,14 +91,16 @@ public interface FuzzIntegrationFileApi {
/**
* 跟据id查参数
*
* @param missionId
* @return
*/
@RequestMapping
(
value
=
"/fuzzParams/getParam/{missionId}"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getFuzzParamById
(
@PathVariable
(
"missionId"
)
int
missionId
);
AjaxResult
getFuzzParamById
(
@PathVariable
(
"missionId"
)
int
missionId
);
/**
* 编辑参数
*
* @param fuzzParams
* @return
*/
...
...
@@ -108,4 +112,23 @@ public interface FuzzIntegrationFileApi {
*/
@RequestMapping
(
value
=
"/test/testProcessInfo"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getProcessInfo
();
/**
* 开启网络代理
*/
@RequestMapping
(
value
=
"/agent/kittyNetworkAgent"
,
method
=
RequestMethod
.
GET
)
AjaxResult
startNetworkAgent
(
@RequestParam
String
networkCard
,
@RequestParam
String
monitorName
);
/**
* 获取代理生成的pcap文件
*/
@RequestMapping
(
value
=
"/agent/getAgentPcap"
,
method
=
RequestMethod
.
GET
)
byte
[]
getAgentPcap
();
/**
* 开启ssh代理
*/
@RequestMapping
(
value
=
"/agent/kittySshAgent"
,
method
=
RequestMethod
.
GET
)
AjaxResult
startSshAgent
(
@RequestParam
String
MonitorName
,
@RequestParam
String
SshUserName
,
@RequestParam
String
SshPassword
,
@RequestParam
String
SshIp
,
@RequestParam
String
SshPort
,
@RequestParam
String
Command
);
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/KittyAgentService.java
0 → 100644
View file @
167180d6
package
com
.
example
.
fuzzbackendmaster
.
service
;
import
javax.servlet.http.HttpServletResponse
;
public
interface
KittyAgentService
{
void
downloadPcap
(
String
fileName
,
byte
[]
file
,
HttpServletResponse
response
);
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/impl/KittyAgentServiceImpl.java
0 → 100644
View file @
167180d6
package
com
.
example
.
fuzzbackendmaster
.
service
.
impl
;
import
com.example.fuzzbackendmaster.service.KittyAgentService
;
import
com.example.fuzzbackendmaster.utils.FileTools
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletResponse
;
@Service
public
class
KittyAgentServiceImpl
implements
KittyAgentService
{
@Override
public
void
downloadPcap
(
String
fileName
,
byte
[]
file
,
HttpServletResponse
response
)
{
FileTools
fileTools
=
new
FileTools
();
fileTools
.
downloadFile
(
fileName
,
file
,
response
);
}
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/resources/application-dev.yml
View file @
167180d6
...
...
@@ -20,4 +20,4 @@ spring:
server-addr
:
http://${nacos-docker.ip}:8848
nacos-docker
:
ip
:
192.168.
50.251
ip
:
192.168.
2.247
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/resources/result.html
View file @
167180d6
...
...
@@ -8,7 +8,7 @@
var
ws1
=
null
;
var
ws2
=
null
;
function
myFunction
()
{
ws1
=
new
WebSocket
(
"ws://192.168.
50.251
:8101/websocket/testResult/web"
);
ws1
=
new
WebSocket
(
"ws://192.168.
2.247
:8101/websocket/testResult/web"
);
ws1
.
onmessage
=
function
(
evt
)
{
console
.
log
(
evt
);
var
received_msg
=
JSON
.
parse
(
evt
.
data
)
;
...
...
This diff is collapsed.
Click to expand it.
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