-
Notifications
You must be signed in to change notification settings - Fork 1
/
filencrypt.py
277 lines (215 loc) · 10.7 KB
/
filencrypt.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
# ,,,,
# ,;) .';;;;',
# ;;,,_,-.-.,;;'_,|I\;;;/),,_
# `';;/:|:);{ ;;;|| \;/ /;;;\__
# L;/-';/ \;;\',/;\/;;;.') \
# .:`''` - \;;'.__/;;;/ . _'-._
# .'/ \ \;;;;;;/.'_7:. '). \_
# .''/ | '._ );}{;//.' '-: '.,L
# .'. / \ ( |;;;/_/ \._./;\ _,
# . / |\ ( /;;/_/ ';;;\,;;_,
# . / )__(/;;/_/ (;;'''''
# / _;:':;;;;:';-._ );
# / / \ `'` --.'-._ \/
# .' '. ,' '-,
# / / r--,..__ '.\
# .' ' .' '--._ ]
# ( :.(;> _ .' '- ;/
# | /:;( ,_.';( __.'
# '- -'"|;:/ (;;;;-'--'
# |;/ ;;(
# '' /;;|
# \;;|
# \/
# Filencrypt Copyright (C) 2022 [email protected]
# License GNU General Public License v3.0
try:
from colorama import Fore, Style
from colorama.initialise import reset_all
from hashlib import sha256
from discord_webhook import DiscordWebhook, DiscordEmbed
from Crypto.Cipher import AES
from Crypto.Util import Padding
from urllib.request import Request
import pyfiglet
import hashlib
import argparse
import urllib.request
import random
import timeit
import string
import time
import sys
import os
import colorama
except:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Missing requirements. Run 'pip install -r requirements.txt' and re-try.")
def banner():
try:
pfbanner = pyfiglet.figlet_format("Filencrypt", font="graffiti")
print(pfbanner)
print(" Made with", Fore.RED, chr(9829), Style.RESET_ALL, "by Déodorant#7144")
print(" https://github.com/deo7/Filencrypt")
except pyfiglet.FontNotFound:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Banner error. Run 'sudo pip3 install --upgrade pyfiglet' and re-try.")
def menu():
print("\n\nMenu")
print("[1] Encrypt")
print("[2] Decrypt")
print("[3] Informations")
print("[4] Contact dev")
def encryption():
def filencrypt(pswd, iv, file):
key = hashlib.sha256(pswd.encode()).digest()
with open("AES_IV.txt", "w") as ivf:
ivf.write(f"Encryption of : {file}\n\n-----BEGIN AES INITIALIZATION VECTOR BLOCK-----\n{iv}\n-----END AES INITIALIZATION VECTOR BLOCK-----".replace("b'", "").replace("'", ""))
with open(file, "rb") as f:
data = f.read()
stime = timeit.default_timer()
cipher = AES.new(key, AES.MODE_CBC, iv)
paddeddata = Padding.pad(data, 16)
encrypteddata = cipher.encrypt(paddeddata)
with open(file, "wb") as ef:
ef.write(encrypteddata)
time = timeit.default_timer() - stime
print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Encryption of the file " + Fore.GREEN + str(file) + Style.RESET_ALL + " complete in " + Fore.GREEN + str(round(time, 3)) + Style.RESET_ALL + " seconds!\n")
print("Don't forget the password you used for the encryption of this file!\nAlso a " + Fore.GREEN + "AES_IV.txt " + Style.RESET_ALL + "file has been created, it contains the initialization vector (IV) of the encryption. " + Fore.RED + "\nYou have to keep this file " + Style.RESET_ALL + "because you will need this IV for decrypt your file.")
file = input(Fore.YELLOW + "\nFile to encrypt : " + Style.RESET_ALL)
if "." in file:
pass
else:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Missing extension")
try:
with open(file, "rb"):
pass
except IOError:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + f" Error - File not found. Make sure your file is in this path : {os.path.realpath(__file__).replace('filencrypt.py', '')}")
if os.path.getsize(file) > 62914560:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - File too large. Max size is 60Mo to avoid crashes or errors.")
else:
pass
pswd = input(Fore.YELLOW + "Choose a strong password : " + Style.RESET_ALL)
def geniv(length):
str = string.ascii_uppercase + string.digits #+ string.punctuation
return "".join(random.choice(str) for i in range(length))
iv = geniv(16)
filencrypt(pswd, iv.encode(), file)
def decryption():
def filedecrypt(pswd, iv, file):
key = hashlib.sha256(pswd.encode()).digest()
with open(file, "rb") as f:
data = f.read()
stime = timeit.default_timer()
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypteddata = cipher.decrypt(data)
unpaddeddata = Padding.unpad(decrypteddata, 16)
with open(file, "wb") as ef:
ef.write(unpaddeddata)
time = timeit.default_timer() - stime
print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Decryption of the file " + Fore.GREEN + str(file) + Style.RESET_ALL + " complete in " + Fore.GREEN + str(round(time, 3)) + Style.RESET_ALL)
file = input(Fore.YELLOW + "\nFile to decrypt : " + Style.RESET_ALL)
if "." in file:
pass
else:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Missing extension")
try:
with open(file, "rb"):
pass
except IOError:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - File not found. Make sure your file is in this path : {os.path.realpath(__file__).replace('filencrypt.py', '')}")
pswd = input(Fore.YELLOW + f"Password used to encrypt {file} : " + Style.RESET_ALL)
iv = input(Fore.YELLOW + f"IV used to encrypt {file} : " + Style.RESET_ALL)
if len(iv) != 16:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + f" Error - Incorrect length of initialization vector : {len(iv)} chars instead of 16.")
filedecrypt(pswd, iv.encode(), file)
def about():
print(Fore.YELLOW + f"\n[>] Running file : {os.path.realpath(__file__)}" + Style.RESET_ALL)
print("\n[>] Presentation\nFilencrypt (currently in version 4.0) is a cryptography project started in 2021 that encrypts and decrypts your files of all types (js, txt, png...) in AES-256. Filencrypt works with a strong password chosen by the user and with a 16 byte initialization vector (IV) generated by the program, you must keep this IV secret and you will need it to decrypt your file. Note that a new IV is created for each encrypted file.")
print("\n[>] Security\nIs Filencrypt a secure project?\nFilencrypt uses AES-256-bit encryption with Cipher Block Chaining (CBC) mode. Although CBC Mode is less secure than XTS or GCM Modes, it is generally suitable for encrypting more or less sensitive files.\nSecurity also depends on the password you use, you should use a strong password with uppercase, lowercase, symbols and numbers.")
print("\nIf you have any other questions or suggestions, contact me by discord (Déodorant#7144), mail ([email protected]) or by running 'python filencrypt.py -c'!")
def contact():
global os
webhook = DiscordWebhook(url="https://discord.com/api/webhooks/908820502343188501/uljt9W1cqtff0PH5ZzAjvZKxTDfPCioFwYwM8WAgRXBPYbLFRCTGdBz5CvAD4_8_Hzcl")
req = Request(
url="https://discord.com/api/webhooks/908820502343188501/uljt9W1cqtff0PH5ZzAjvZKxTDfPCioFwYwM8WAgRXBPYbLFRCTGdBz5CvAD4_8_Hzcl",
headers={"User-Agent": "Mozilla/5.0"}
)
try:
with urllib.request.urlopen(req) as response:
txt = response.read()
except:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Contact system error. Try to contact me by discord (Déodorant#7144) or by mail ([email protected]).")
contactway = input(Fore.YELLOW + "\nEmail or discord to be contacted : " + Style.RESET_ALL)
subject = input(Fore.YELLOW + "Subject : " + Style.RESET_ALL)
message = input(Fore.YELLOW + "Message : " + Style.RESET_ALL)
if contactway == "" or subject == "" or message == "":
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Empty inputs")
img = input(Fore.YELLOW + "Add an image ('y' or 'n') : " + Style.RESET_ALL)
if img == "y":
filepath = input(Fore.YELLOW + "Path of image : " + Style.RESET_ALL)
try:
with open(filepath, 'rb'):
pass
except IOError:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Image not found")
if os.path.getsize(filepath) > 8388608:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - File too large. Max size is 8Mo.")
else:
pass
with open(filepath, "rb") as f:
webhook.add_file(file=f.read(), filename="file.png")
else:
pass
embed = DiscordEmbed(title="Contact Filencrypt", color="03b2f8")
embed.add_embed_field(name="Moyen de contact", value=contactway, inline=False)
embed.add_embed_field(name="Sujet", value=subject, inline=False)
embed.add_embed_field(name="Message", value=message, inline=False)
proxy = {
"http": "14.97.216.232:80"
}
webhook.set_proxies(proxy)
webhook.add_embed(embed)
response = webhook.execute()
print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Message sent with success")
if sys.platform.startswith("linux"):
os.system("clear")
elif sys.platform.startswith("win32"):
os.system("cls")
else:
pass
colorama.init()
parser = argparse.ArgumentParser()
parser.add_argument('-e', help="Encrypt a file", action="store_true")
parser.add_argument('-d', help="Decrypt a file", action="store_true")
parser.add_argument('-i', help="Informations", action="store_true")
parser.add_argument('-c', help="Contact dev", action="store_true")
args = parser.parse_args()
try:
if args.e:
banner()
encryption()
elif args.d:
banner()
decryption()
elif args.i:
banner()
about()
elif args.c:
banner()
contact()
else:
banner()
menu()
choice = input("Choice: ")
if choice == "1":
encryption()
elif choice == "2":
decryption()
elif choice == "3":
about()
elif choice == "4":
contact()
else:
sys.exit(Fore.RED + "\n[-] " + Style.RESET_ALL + "Error - You must reply '1', '2', '3' or '4'")
except KeyboardInterrupt:
sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Filencrypt has been interrupted by user")