-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path3DESEncryptor.go
84 lines (61 loc) · 1.6 KB
/
3DESEncryptor.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
/*
Project Augustus Loader
VERSION: 1.0
AUTHOR: @tunnelgre - https://twitter.com/tunnelgre
*/
package main
import (
"bytes"
"crypto/cipher"
"crypto/des"
"crypto/rand"
"encoding/hex"
"fmt"
)
func main() {
key := generateRandomBytes(24)
iv := generateRandomBytes(des.BlockSize)
fmt.Printf("Key: %s\n", formatShellcode(key))
fmt.Printf("IV: %s\n", formatShellcode(iv))
shellcode := []byte("")
encryptedShellcode, err := encryptDES3(shellcode, key, iv)
if err != nil {
fmt.Println("Error 3DES:", err)
return
}
fmt.Printf("Shellcode encrypted: %s\n", formatShellcode(encryptedShellcode))
}
func generateRandomBytes(size int) []byte {
randomBytes := make([]byte, size)
_, err := rand.Read(randomBytes)
if err != nil {
panic(fmt.Sprintf("Failed to generate random bytes: %v", err))
}
return randomBytes
}
func encryptDES3(plaintext, key, iv []byte) ([]byte, error) {
block, err := des.NewTripleDESCipher(key)
if err != nil {
return nil, err
}
plaintext = pad(plaintext, block.BlockSize())
ciphertext := make([]byte, len(plaintext))
mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(ciphertext, plaintext)
return ciphertext, nil
}
func pad(data []byte, blockSize int) []byte {
padding := blockSize - len(data)%blockSize
padText := bytes.Repeat([]byte{byte(padding)}, padding)
return append(data, padText...)
}
func shellcodeToHex(data []byte) string {
return hex.EncodeToString(data)
}
func formatShellcode(data []byte) string {
output := ""
for _, b := range data {
output += fmt.Sprintf("\\x%02x", b)
}
return output
}