[ Agent ] [ Executor ] - 增加windows executor部分的代码
This commit is contained in:
@@ -97,7 +97,7 @@ func (op *AgentOsOperator) Exec(baseFuncName string, funcArgs ...string) []strin
|
|||||||
|
|
||||||
// exec the command here
|
// exec the command here
|
||||||
for _, singleLineCommand := range multiLineCommand {
|
for _, singleLineCommand := range multiLineCommand {
|
||||||
singleCommandResult := AllOutputCommandExecutor(singleLineCommand)
|
singleCommandResult, _ := AllOutputCommandExecutor(singleLineCommand)
|
||||||
|
|
||||||
result = append(result, "")
|
result = append(result, "")
|
||||||
result = append(result, singleCommandResult...)
|
result = append(result, singleCommandResult...)
|
||||||
|
|||||||
@@ -76,9 +76,18 @@ func Execute(em *ExecutionMessage) ([]string, error) {
|
|||||||
|
|
||||||
func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
||||||
|
|
||||||
|
var resultSlice []string
|
||||||
var output []byte
|
var output []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
tmp := make([]string, len(pipeLineCommand))
|
||||||
|
for index, pipe := range pipeLineCommand {
|
||||||
|
tmp[index] = strings.Join(pipe, " ")
|
||||||
|
}
|
||||||
|
pipelineCommandString := strings.Join(tmp, " | ")
|
||||||
|
|
||||||
|
resultSlice = append(resultSlice, fmt.Sprintf(" ========= 命令为 ====> %s", pipelineCommandString))
|
||||||
|
|
||||||
for _, pipeCommand := range pipeLineCommand {
|
for _, pipeCommand := range pipeLineCommand {
|
||||||
if len(pipeCommand) == 0 {
|
if len(pipeCommand) == 0 {
|
||||||
continue
|
continue
|
||||||
@@ -89,14 +98,19 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
|||||||
command.Stdin = bytes.NewBuffer(output)
|
command.Stdin = bytes.NewBuffer(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err = command.Output()
|
output, err = command.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("Pipeline Command Exec Error => %v", err.Error())
|
log.ErrorF("Pipeline Command Exec Error => %v", err.Error())
|
||||||
break
|
|
||||||
|
// 收集错误的信息
|
||||||
|
resultSlice = append(resultSlice, "↓↓↓ 命令 错误 如下 ↓↓↓", string(output))
|
||||||
|
return resultSlice, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{string(output)}, err
|
// 正常的输出
|
||||||
|
resultSlice = append(resultSlice, "↓↓↓ 命令 输出 如下 ↓↓↓", string(output))
|
||||||
|
return resultSlice, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func MultiLineCommandExecutor(multiLineCommandExecutor [][]string) ([]string, error) {
|
func MultiLineCommandExecutor(multiLineCommandExecutor [][]string) ([]string, error) {
|
||||||
|
|||||||
49
agent-go/executor/WindowsFunction.go
Normal file
49
agent-go/executor/WindowsFunction.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package executor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
user32DLL = syscall.NewLazyDLL("user32.dll")
|
||||||
|
messageBox = user32DLL.NewProc("MessageBoxW")
|
||||||
|
)
|
||||||
|
|
||||||
|
func FindPublicIpAddress() {
|
||||||
|
|
||||||
|
cmd := exec.Command("curl", "ifconfig.io")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("无法获取公网IP地址:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ip := strings.TrimSpace(string(output))
|
||||||
|
fmt.Println("公网IP地址:", ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CallAgent() {
|
||||||
|
var (
|
||||||
|
hWnd uintptr
|
||||||
|
text = "Hello, World!"
|
||||||
|
caption = "Golang Win32API"
|
||||||
|
flags = uint(0x00000001) // MB_OK
|
||||||
|
)
|
||||||
|
|
||||||
|
ret, _, err := messageBox.Call(
|
||||||
|
hWnd,
|
||||||
|
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))),
|
||||||
|
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(caption))),
|
||||||
|
uintptr(flags),
|
||||||
|
)
|
||||||
|
if ret == 0 {
|
||||||
|
fmt.Println("MessageBox failed:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("MessageBox returned:", ret)
|
||||||
|
}
|
||||||
8
agent-go/executor/WindowsFunction_test.go
Normal file
8
agent-go/executor/WindowsFunction_test.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package executor
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCallAgent(t *testing.T) {
|
||||||
|
|
||||||
|
FindPublicIpAddress()
|
||||||
|
}
|
||||||
@@ -24,6 +24,9 @@
|
|||||||
[
|
[
|
||||||
"grep",
|
"grep",
|
||||||
"root"
|
"root"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"ping"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user