-
Notifications
You must be signed in to change notification settings - Fork 51
/
ezuri.go
77 lines (65 loc) · 1.56 KB
/
ezuri.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
package main
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"os/exec"
"text/template"
)
const (
stubDir = "stub"
allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%0123456789"
modeIV = iota
modeKey
)
type stubConfig struct {
ProcName string
EncryptionKey string
EncryptionIV string
}
func createStub(stubCfg *stubConfig) []byte {
f, err := os.Create("stub/vars.go")
check(err)
defer f.Close()
tmpl, err := template.New("").Parse(`// Code generated automatically; DO NOT EDIT.
// Generated using data from user input
package main
var (
key = "{{.EncryptionKey}}"
iv = "{{.EncryptionIV}}"
procName = "{{.ProcName}}"
)
`)
check(err)
tmpl.Execute(f, stubCfg)
os.Chdir(stubDir)
cmdOut, err := exec.Command("go", "build", "-ldflags", `-w -s`, ".").CombinedOutput()
if len(cmdOut) > 0 {
fmt.Println("Output: ", string(cmdOut))
}
check(err)
stubBytes, err := ioutil.ReadFile("stub")
check(err)
os.Chdir("..")
return stubBytes
}
func main() {
stubCfg := &stubConfig{}
srcFilePath, dstFilePath := userInput(stubCfg)
srcBytes, err := ioutil.ReadFile(srcFilePath)
check(err)
encryptedBytes := aesEnc(srcBytes, stubCfg.EncryptionKey, stubCfg.EncryptionIV)
fmt.Println("[!] Generating stub...")
stubBytes := createStub(stubCfg)
fmt.Println("[!] Creating final executable...")
file, err := os.Create(dstFilePath)
check(err)
w := bufio.NewWriter(file)
w.Write(stubBytes)
w.Write([]byte(stubCfg.EncryptionKey))
w.Write([]byte(stubCfg.EncryptionIV))
w.Write(encryptedBytes)
w.Flush()
fmt.Println("[!] All done!")
}