!88 完成POC交互命令解析功能

Merge pull request !88 from a-alpha/alpha-dev
This commit is contained in:
a-alpha 2022-11-16 11:12:47 +00:00 committed by Gitee
commit 2fa03b68cc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 78 additions and 16 deletions

View File

@ -31,6 +31,10 @@ SiteRequests:
ImMap:
ImplementFirst:
./src/Actuator/CVE-2022-22555/CVE-2021-22555_x86_64
Inter:
- "<.:cout1"
- ">>:2"
- "<?:yes"
Condition: None
ReqCondition: true
Matchers:

View File

@ -32,6 +32,12 @@ SiteRequests:
ImArray:
#- ./src/Actuator/CVE-2022-22555/CVE-2021-22555_x86_64
- "CVE-2021-22555_x86_64"
ExpireTime: 30 #second
Inter:
- ">.:cout1"
- "<<:1\n"
- ">.:cout2\n"
- ">?:yes"
Condition: None
ReqCondition: true
Matchers:

View File

@ -1 +1 @@
script.sh
for_test_inter

View File

@ -53,6 +53,7 @@ type Implement struct {
Condition string
// ImMap map[string]string
ImArray []string
Inter []string
}
// SiteRequests 解析请求中的值

View File

@ -31,8 +31,8 @@
package genmai
import (
"fmt"
"os"
"errors"
// TODO:
// 应该写成相对路径因为genmai应该是编译成库所以包路径不
@ -40,6 +40,19 @@ import (
//
// go 有点拉
sandbox "main/src/genmai/Sandbox"
// TODO:
// 应该写成相对路径因为genmai应该是编译成库所以包路径不
// 是以main开头。
//
// go 有点拉
inter "main/src/genmai/Interpreter"
)
var (
RC_POC_CHECK_SUCCESSFULLY error =
errors.New("Poc Check Successfully!")
RC_POC_CHECK_FAILED error =
errors.New("Poc Check Failed!")
)
type ExplorerConfigKernel struct {
@ -86,25 +99,63 @@ func (ek *ExplorerKernel)SetupSandbox(sb sandbox.SandboxBase) {
ek.isSetup = true
}
func (ek *ExplorerKernel)StartWithPath(fullpath string) error {
interio , err := ek.EkSandbox.Process(fullpath)
func (ek *ExplorerKernel)startWithPath(fullpath string) error {
interio , rc := ek.EkSandbox.Process(fullpath)
/* */
if (nil != err) {
A_DEBUG_ERROR("StartWithPath()->Process() error! rc = ", err)
/* */
return err
}
// TODO: remove this, just for test
str, rc := interio.RecvUntil("\n")
if (nil != rc) {
A_DEBUG_ERROR("StartWithPath()->RecvUntil() error! rc = ", rc)
A_DEBUG_ERROR("startWithPath()->Process() error! rc = ", rc)
/* */
return rc
}
fmt.Println(str)
return err
config, rc1 := ek.GetExplorerConfigKernel()
rc = rc1
if (nil != rc) {
A_DEBUG_ERROR("startWithPath()->GetExplorerConfigKernel() error ! rc = ", rc)
/* */
return rc
} // if (nil != ...
for _, itr := range config.SiteRequests.Implement.Inter {
icmd := itr[ : inter.INTERPRETER_CMD_LEN]
icmd_len := len(icmd)
switch (icmd) {
case inter.INTERPRETER_CMD_SEND:
interio.Send(itr[ icmd_len : ] + "\n")
case inter.INTERPRETER_CMD_RECV:
// TODO
//out, rc_t := interio.Recv( icmd_len )
interio.Recv( len(itr[ icmd_len :]) )
case inter.INTERPRETER_CMD_RECVUNTIL:
interio.RecvUntil( itr[ icmd_len : ] )
//case ">.":
// A_DEBUG_INFO(">.")
//
//case "<?":
// A_DEBUG_INFO("<?")
//
case inter.INTERPRETER_CMD_RECV_POC_CHECK:
ou, _ := interio.Recv( len (itr[icmd_len : ]) )
/* */
if ( ou == itr[ icmd_len : ] ) {
A_DEBUG_INFO("startWithPath():",
"\"" + inter.INTERPRETER_CMD_RECV_POC_CHECK + "\":",
"Check poc successfully!")
/* */
return RC_POC_CHECK_SUCCESSFULLY
} else {
A_DEBUG_INFO("startWithPath():\"<?\":Check poc successfully!")
/* */
return RC_POC_CHECK_FAILED
}
} // switch (inter ...
} // for _ , itr
return rc
}
func (ek *ExplorerKernel)Start() (err error) {
@ -118,7 +169,7 @@ func (ek *ExplorerKernel)Start() (err error) {
}
for _, file := range config.SiteRequests.ImArray {
err = ek.StartWithPath(ek.ExplorerCommon.EcConfigFilePrefix +
err = ek.startWithPath(ek.ExplorerCommon.EcConfigFilePrefix +
string(os.PathSeparator) +
file )
}