This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
executable file
·279 lines (232 loc) · 9.99 KB
/
main.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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/python
# New Arg Parse and Cipher Call
# created by : Fyzz | C0SM0 | Soul
# imports
import argparse
from ast import For
from multiprocessing.context import ForkServerProcess
import mods.bits as b
import importlib
import readline
import sys
import os
from colorama import Fore, Back, Style
# gets list of available ciphers
def get_ciphers():
output_list = []
directory = os.fsencode(b.cipher)
for file in os.listdir(directory):
filename = os.fsdecode(file)
output_list.append(filename[:-3])
return output_list
# updates cryptex
def update():
cmd_prefix = Fore.GREEN + '[~] ' + Fore.RESET
print("\n[*] Checking for updates...")
# get latest version nubmer
os.system("curl https://raw.githubusercontent.com/AlexKollar/Cryptex/master/version.txt | tee ~/.Cryptex/latest.txt")
# save version nubmers to memory
current_version = float(open(f"{b.local_path}/version.txt", "r").read())
latest_version = float(open (f"{b.local_path}/latest.txt", "r").read())
# remove version number file
os.system("rm -rf ~/.Cryptex/latest.txt")
# if new version is available, update
if latest_version > current_version:
print("\n[+] Update found")
print(cmd_prefix + "Update Cryptex? [y/n]\n")
# user input, option
option = input(f"{b.header}")
# update
if option == "y":
os.system(f"sh ~/.Cryptex/resources/update.sh")
# otherwise, run main code
else:
print("\n[+] Cryptex already up to date")
# output function
def output(data, output):
if data:
if data[1] == True and data[1]:
# file
if output:
with open(output, 'w') as f:
f.write(data[0])
print(f'{b.SUCCESS}[✓] File Output Successful{b.END}')
# command line interface
else:
print(f'\n{b.SUCCESS}[✓] Output:{b.END}\n{data[0]}\n')
else:
# exception
print(f'\n{b.FAIL}[✖] Failed:{b.END}\n{data[0]}\n')
# uninstalls cryptex
def remove():
cmd_prefix = Fore.RED + '[~] ' + Fore.RESET
# confirmation
print("\n" + cmd_prefix + "Are you sure you want to remove Cryptex? [y/n]\n")
# user input
option = input(b.header)
# delete Cryptex
if option == "y":
os.system("rm -rf ~/.Cryptex")
# command line interface
def cli(args_exist):
cmd_prefix = Fore.CYAN + '[~] ' + Fore.RESET
# default arguments
if args_exist:
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
print(b.help_menu)
elif sys.argv[1] == '-u' or sys.argv[1] == '--update':
update()
elif sys.argv[1] == '-rm' or sys.argv[1] == '--remove' or sys.argv[1] == '--uninstall':
remove()
# layered encryption
elif '+' in sys.argv:
text = sys.argv[sys.argv.index('-t') + 1]
sys.argv[sys.argv.index('-t') + 1] = f'"{text}"'
args = " ".join(sys.argv[1:])
layers = args.split(' + ')
text = ''
for index, layer in enumerate(layers):
if index == 0:
os.system(f'python3 ~/.Cryptex/main.py {layer} -lay')
elif index != len(layers) - 1:
try:
with open('temp_storage.txt', 'r') as temp:
layerd_storage = temp.read()
except:
pass
else:
os.system(f'python3 ~/.Cryptex/main.py {layer} -t "{layerd_storage}" -lay')
else:
try:
with open('temp_storage.txt', 'r') as temp:
layerd_storage = temp.read()
except:
pass
else:
os.system(f'python3 ~/.Cryptex/main.py {layer} -t "{layerd_storage}"')
os.remove('temp_storage.txt')
# flags for argument parsing
else:
parser = argparse.ArgumentParser(add_help=False, usage="")
parser.add_argument('cipher', type=str)
parser.add_argument('-e', '--encode', dest='encode', action='store_true')
parser.add_argument('-d', '--decode', dest='decode', action='store_true')
parser.add_argument('-b', '--brute', dest='brute', action='store_true')
parser.add_argument('-i', '--inputFile', dest='inputFile', type=str)
parser.add_argument('-o', '--output', dest='output', type=str)
parser.add_argument('-t', '--text', help='String Input\n', dest='text', type=str)
parser.add_argument('-k', '--key', help='Int Key\n', dest='key', type=str)
parser.add_argument('-ex', '--exclude', help='Exclude Character\n', dest='exclude', type=str)
parser.add_argument('-w', '--wordlist', help='Wordlist File\n', dest='wordlist', type=str)
parser.add_argument('-r', '--range', help='Range\n', dest='range', type=str)
# Layerd Encryption
parser.add_argument('-lay', '--layerd', dest='layerd', action='store_true')
# Google Translate
parser.add_argument('-tr', '--translate', dest='translate', action='store_true')
parser.add_argument('-lang', '--languages', dest='lang', action='store_true')
parser.add_argument('-src', '--src', help='Source Language code\n', dest='src', type=str)
parser.add_argument('-dest', '--dest', help='Destination Language code\n', dest='dest', type=str)
# Static Encryption
parser.add_argument('-f', '--file', help="Give a file path\n", dest='file', type=str)
parser.add_argument('-iw', '--image_width', help="Image width used for SE", dest="image_width", type=int)
#parser.add_argument('-m', '--mono', help="Make SE use monocromatic mode", dest="mono", action="store_true")
# cryptographic payloads
parser.add_argument('-g', '--generate', help='Choose Payload Generation Method\n', dest='generate', type=str)
parser.add_argument('-p', '--payload', help='Choose Payload\n', dest='payload', type=str)
parser.add_argument('-wc', '--webcredentials', dest='webcredentials', action='store_true')
args = parser.parse_args()
# reads input files for argument parsing
if args.inputFile:
tmpFileVar = open(args.inputFile, 'r')
args.text = tmpFileVar.read()
tmpFileVar.close()
# reads input file for wordlist
if args.wordlist:
tmpFileVar = open(args.wordlist, 'r')
args.wordlist = tmpFileVar.read().split('\n')
args.wordlist = list(filter(lambda x : len(x) > 0, args.wordlist))
# ^ removes empty lines from the array
tmpFileVar.close()
# execute cryptex libraries
try:
module = importlib.import_module(f'ciphers.{args.cipher}')
# exception handling
except:
print(f"{b.FAIL}\n" + Fore.RED + f"[✖] Cipher May Not Exist\nTry 'cryptex -h' to see all ciphers{b.END}\n" + Fore.RESET)
# executes libraries
else:
func = None
if args.layerd:
if args.encode:
layerd_storage = module.encode(args)[0]
with open('temp_storage.txt', 'w') as temp:
temp.write(layerd_storage)
elif args.decode:
layerd_storage = module.decode(args)[0]
with open('temp_storage.txt', 'w') as temp:
temp.write(layerd_storage)
else:
output(["For now '-tr' or '-b' can only be the final step in layerd encryption", False], False)
try:
os.remove('temp_storage.txt')
except:
pass
elif args.encode:
func = module.encode
elif args.decode:
func = module.decode
elif args.brute:
func = module.brute
elif args.translate:
func = module.translate
elif args.lang:
output(module.languages(), args.output)
# cryptograhic payloads
elif args.payload:
func = module.payload
else:
print(Fore.CYAN + module.help_menu + Fore.RESET)
if func:
output(func(args), args.output)
else:
# display banner
print(b.banner)
print(cmd_prefix + 'Type "help" for help menu :')
# loop code
while True:
# get user input
user_input = input(b.header)
# display help menu
if user_input == 'help':
print(b.help_menu)
# display version number
elif user_input == 'version':
print(b.version)
# exit cryptex
elif user_input == 'exit' or user_input == 'quit':
exit()
break
# update current version
elif user_input == 'update':
update()
# uninstalls cryptex
elif user_input == 'uninstall' or user_input == 'remove':
remove()
# runs unrecogonized commands into bash
elif user_input.split(' ')[0] not in get_ciphers():
os.system(user_input)
# runs crytpex libraries
else:
os.system(f'python3 ~/.Cryptex/main.py {user_input.replace("cryptex", "")}')
# main code
def main():
try:
sys.argv[1]
except IndexError:
args_exist = False
else:
args_exist = True
cli(args_exist)
# executes main code
if __name__ == '__main__':
main()