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
41472db6
Commit
41472db6
authored
Jun 15, 2024
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ssh至服务器并用websocket返回运行数据
parent
51383361
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
43 deletions
+93
-43
AlfnetController.java
...com/example/fuzzControll/controller/AlfnetController.java
+1
-1
TestServiceImpl.java
...om/example/fuzzControll/service/impl/TestServiceImpl.java
+12
-33
CmdTools.java
...rc/main/java/com/example/fuzzControll/tools/CmdTools.java
+5
-4
LinuxCommandUtil.java
...java/com/example/fuzzControll/tools/LinuxCommandUtil.java
+33
-1
application-dev.yml
fuzzIntegration/src/main/resources/application-dev.yml
+8
-4
result2.html
fuzzIntegration/src/main/resources/result2.html
+34
-0
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/AlfnetController.java
View file @
41472db6
...
...
@@ -46,7 +46,7 @@ public class AlfnetController {
}
/**
* 算法2
无参数型
* 算法2
机器学习的
*/
@RequestMapping
(
value
=
"/algorithmTwoStart"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
algorithmTwoStart
(
@RequestBody
final
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/TestServiceImpl.java
View file @
41472db6
...
...
@@ -29,11 +29,10 @@ public class TestServiceImpl implements TestService {
@Override
public
void
algorithm
One
Start
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
public
void
algorithm
Two
Start
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
TestControlTools
.
setIsRunning
(
true
);
String
aflnetCmd
=
getAlgorithmOneFinalCmd
(
algorithmOneCmdParams
);
String
pythonCmd
=
getAlgorithmOnePythonCmd
(
algorithmOneCmdParams
);
String
recodeCmd
=
getAlgorithmOneResultCmd
(
algorithmOneCmdParams
);
String
aflnetCmd
=
getAlgorithmTwoFinalCmd
(
algorithmOneCmdParams
);
String
pythonCmd
=
getAlgorithmTwoPythonCmd
(
algorithmOneCmdParams
);
if
(
aflnetCmd
==
null
)
{
log
.
error
(
"AlgorithmOne Cmd is null!"
);
throw
new
AflnetException
(
"Cmd Generate error!"
);
...
...
@@ -42,13 +41,9 @@ public class TestServiceImpl implements TestService {
log
.
error
(
"pythonCmd Cmd is null!"
);
throw
new
AflnetException
(
"Cmd Generate error!"
);
}
if
(
recodeCmd
==
null
)
{
log
.
error
(
"recodeCmd Cmd is null!"
);
throw
new
AflnetException
(
"Cmd Generate error!"
);
}
log
.
info
(
"The cmd is [{}]"
,
aflnetCmd
);
try
{
cmdTools
.
runProgramCmd
(
aflnetCmd
,
pythonCmd
,
recodeCmd
);
cmdTools
.
runProgramCmd
(
aflnetCmd
,
pythonCmd
);
}
catch
(
JSchException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IOException
e
)
{
...
...
@@ -57,40 +52,24 @@ public class TestServiceImpl implements TestService {
}
private
String
getAlgorithmOneResultCmd
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
switch
(
algorithmOneCmdParams
.
getProtopcol
().
toLowerCase
())
{
case
"dns"
:
return
"cd /home/lddc/SHENYANLONG/SMGfuzz && python Copy_fuzz_stats.py --SUT dnsmasq --ALG RLGfuzz"
;
case
"sip"
:
return
"cd /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch && python Copy_fuzz_stats.py --SUT kamailio --ALG RLGfuzz"
;
case
"ftp"
:
return
"cd /home/lddc/SHENYANLONG/SMGfuzz && python Copy_fuzz_stats.py --SUT kamailio --ALG RLGfuzz"
;
case
"rtsp"
:
return
"cd /home/lddc/SHENYANLONG/SMGfuzz && python Copy_fuzz_stats.py --SUT live555 --ALG RLGfuzz"
;
default
:
return
null
;
//todo 增加其他协议 的格式
}
}
private
String
getAlgorithm
One
PythonCmd
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
private
String
getAlgorithm
Two
PythonCmd
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
switch
(
algorithmOneCmdParams
.
getProtopcol
().
toLowerCase
())
{
case
"dns"
:
return
"
dnsResultCmd(algorithmOneCmdParams)
"
;
return
"
cd /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch && python main_python.py --SUT dnsmasq
"
;
case
"sip"
:
return
"
sipResultCmd(algorithmOneCmdParams)
"
;
return
"
cd /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch && python main_python.py --SUT kamailio
"
;
case
"ftp"
:
return
"
ftpResultCmd(algorithmOneCmdParams)
"
;
return
"
cd /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch && python main_python.py --SUT kamailio
"
;
case
"rtsp"
:
return
"
rtspResultCmd(algorithmOneCmdParams)
"
;
return
"
cd /home/lddc/SHENYANLONG/SMGfuzz/RL_Pytorch && python main_python.py --SUT live555
"
;
default
:
return
null
;
//todo 增加其他协议 的格式
}
}
private
String
getAlgorithm
One
FinalCmd
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
private
String
getAlgorithm
Two
FinalCmd
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
switch
(
algorithmOneCmdParams
.
getProtopcol
().
toLowerCase
())
{
case
"dns"
:
return
dnsCmd
(
algorithmOneCmdParams
);
...
...
@@ -195,7 +174,7 @@ public class TestServiceImpl implements TestService {
//todo 不同服务不同端口
@Override
public
void
algorithm
Two
Start
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
public
void
algorithm
One
Start
(
AlgorithmOneCmdParams
algorithmOneCmdParams
)
{
TestControlTools
.
setIsRunning
(
true
);
String
cmd
=
cmdTools
.
parse
(
algorithmOneCmdParams
);
Date
date
=
new
Date
();
...
...
@@ -204,7 +183,7 @@ public class TestServiceImpl implements TestService {
String
finalCmd
=
CmdConstent
.
RUN_AFLNET_BEFORE
+
outputFileName
+
CmdConstent
.
RUN_AFLNET_AFTER
+
cmd
+
aflnetProperties
.
getAflnetPath
()
+
"live555/testProgs/testOnDemandRTSPServer 8554"
;
log
.
info
(
"The cmd is [{}]"
,
finalCmd
);
try
{
cmdTools
.
runProgramCmd
(
"source /etc/profile && "
+
finalCmd
,
""
,
""
);
cmdTools
.
runProgramCmd
(
"source /etc/profile && "
+
finalCmd
,
""
);
}
catch
(
JSchException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IOException
e
)
{
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/CmdTools.java
View file @
41472db6
...
...
@@ -18,6 +18,7 @@ public class CmdTools {
Boolean
show
=
true
;
Boolean
send
=
false
;
/**
* 运行不需要后台运行cmd
*/
...
...
@@ -41,18 +42,17 @@ public class CmdTools {
* 运行需要后台运行cmd
* 通过websocket返回数据
*/
public
void
runProgramCmd
(
String
aflnetCmd
,
String
pythonCmd
,
String
recode
Cmd
)
throws
AflnetException
,
JSchException
,
IOException
{
public
void
runProgramCmd
(
String
aflnetCmd
,
String
python
Cmd
)
throws
AflnetException
,
JSchException
,
IOException
{
AflnetSshProperties
aflnetSshProperties
=
GlobalParameters
.
aflnetSshProperties
;
String
host
=
aflnetSshProperties
.
getHost
();
int
port
=
aflnetSshProperties
.
getPort
();
int
port
=
aflnetSshProperties
.
getPort
();
String
user
=
aflnetSshProperties
.
getUser
();
String
password
=
aflnetSshProperties
.
getPassword
();
// 手动创建对象实现连接
LinuxCommandUtil
linuxCommandUtil
=
new
LinuxCommandUtil
();
linuxCommandUtil
.
connect
(
host
,
port
,
user
,
password
);
linuxCommandUtil
.
execCmd
(
aflnetCmd
);
// linuxCommandUtil.execCmdWithoutResults(pythonCmd);
// linuxCommandUtil.execCmdWithoutResults(recodeCmd);
linuxCommandUtil
.
execCmdWithoutResults
(
pythonCmd
);
}
...
...
@@ -130,6 +130,7 @@ public class CmdTools {
}
return
cmd
.
toString
();
}
public
TestReturnEntity
makeReturnEntity
(
String
line
,
TestReturnEntity
returnEntity
)
{
if
(
line
.
contains
(
"All set and ready to roll!"
)
||
line
.
contains
(
"american fuzzy"
)
||
line
.
contains
(
"process timing overall results"
))
{
show
=
false
;
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/LinuxCommandUtil.java
View file @
41472db6
...
...
@@ -82,7 +82,6 @@ public class LinuxCommandUtil {
* 执行指令
*/
public
void
execCmd
(
String
command
)
throws
JSchException
,
IOException
{
List
<
String
>
result
=
new
ArrayList
<>();
InputStream
in
=
channelExec
.
getInputStream
();
InputStream
error
=
channelExec
.
getErrStream
();
new
Thread
(
new
Runnable
()
{
...
...
@@ -105,9 +104,24 @@ public class LinuxCommandUtil {
* 不需要结果执行指令
*/
public
void
execCmdWithoutResults
(
String
command
)
throws
JSchException
,
IOException
{
InputStream
in
=
channelExec
.
getInputStream
();
InputStream
error
=
channelExec
.
getErrStream
();
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
trainOutPutStream
(
in
);
}
}).
start
();
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
errorStream
(
error
);
}
}).
start
();
channelExec
.
setCommand
(
command
);
channelExec
.
connect
();
}
public
void
outPutStream
(
InputStream
in
)
{
Reader
reader
=
new
InputStreamReader
(
in
);
BufferedReader
bf
=
new
BufferedReader
(
reader
);
...
...
@@ -133,6 +147,24 @@ public class LinuxCommandUtil {
}
}
public
void
trainOutPutStream
(
InputStream
in
)
{
Reader
reader
=
new
InputStreamReader
(
in
);
BufferedReader
bf
=
new
BufferedReader
(
reader
);
String
line
=
null
;
try
{
while
((
line
=
bf
.
readLine
())
!=
null
&&
TestControlTools
.
getIsRunning
())
{
System
.
out
.
println
(
line
);
GlobalParameters
.
webSocket
.
appointSending
(
"fuzzMaster"
,
"webTrainResult"
,
line
);
}
//结束就关闭
if
(!
TestControlTools
.
getIsRunning
())
{
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
errorStream
(
InputStream
error
)
{
Reader
reader
=
new
InputStreamReader
(
error
);
BufferedReader
bf
=
new
BufferedReader
(
reader
);
...
...
fuzzIntegration/src/main/resources/application-dev.yml
View file @
41472db6
...
...
@@ -21,12 +21,16 @@ aflnet:
web
:
ip
:
192.168.9.177
#aflnetssh:
# host: 192.168.31.53
# port: 22
# user: lddc
# password: sysulddc
aflnetssh
:
host
:
1
92.168.31.53
host
:
1
72.17.4.151
port
:
22
user
:
lddc
password
:
sysulddc
user
:
root
password
:
123456
#aflnetssh:
# host: 192.168.31.133
# port: 22
...
...
fuzzIntegration/src/main/resources/result2.html
0 → 100644
View file @
41472db6
<!DOCTYPE HTML>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
websocket client
</title>
<script
type=
"text/javascript"
>
var
ws1
=
null
;
var
ws2
=
null
;
function
myFunction
()
{
ws1
=
new
WebSocket
(
"ws://192.168.31.133:8100/websocket/testResult/webTrainResult"
);
ws1
.
onmessage
=
function
(
evt
)
{
console
.
log
(
evt
);
console
.
log
(
evt
.
data
)
var
context
=
'<div class="sendMsg">'
+
'aflnet:<br/>'
+
'aflnet<h3>'
+
evt
.
data
+
'</h3><br/>'
+
' </div>'
;
document
.
getElementById
(
"sendDiv"
).
innerHTML
=
context
;
};
ws1
.
onclose
=
function
()
{
// 关闭 websocket
alert
(
"连接已关闭..."
);
};
}
</script>
<body
onload=
"javascript:myFunction()"
>
<div
id=
"sendDiv"
>
</div>
</body>
</html>
\ No newline at end of file
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