avoid encrypting ZIP files as pubkey encryption would be better

This commit is contained in:
PC-Admin 2023-08-01 13:20:36 +08:00
parent c1bfa32e2d
commit 21b9653aad
4 changed files with 20 additions and 58 deletions

View File

@ -23,7 +23,6 @@ This script also requires you to install the following PIP packages:
``` ```
pip3 install python-whois pip3 install python-whois
pip3 install requests pip3 install requests
pip3 install pyAesCrypt
pip3 install matrix-nio pip3 install matrix-nio
``` ```

View File

@ -58,11 +58,11 @@ while pass_token == False:
print("20) Shadow ban a user.\t\t\t\t69) Unblock a room.") print("20) Shadow ban a user.\t\t\t\t69) Unblock a room.")
print("\n#### Server Commands ####\t\t\t\t\t#### Report Generation ####") print("\n#### Server Commands ####\t\t\t\t\t#### Report Generation ####")
print("100) Delete and block a specific media.\t\t\t\t150) Generate user report.") print("100) Delete and block a specific media.\t\t\t\t150) Generate user report.")
print("101) Purge remote media repository up to a certain date.\t151) Decrypt user report .zip file.") print("101) Purge remote media repository up to a certain date.\t151) Lookup homeserver admin contact details.")
print("102) Prepare database for copying events of multiple rooms.\t152) Lookup homeserver admin contact details.") print("102) Prepare database for copying events of multiple rooms.\t152) Send a test email (to yourself).")
print("\t\t\t\t\t\t\t\t153) Send a test email (to yourself).") print("\t\t\t\t\t\t\t\t153) Sent a test Matrix message (to yourself).")
print("#### rdlist ####\t\t\t\t\t\t154) Sent a test Matrix message (to yourself).") print("#### rdlist ####\t\t\t\t\t\t154) Send test incident reports (to yourself).")
print("120) Block all rooms with specific rdlist tags.\t\t\t155) Send test incident reports (to yourself).") print("120) Block all rooms with specific rdlist tags.")
print("121) Block all rooms with recommended rdlist tags.") print("121) Block all rooms with recommended rdlist tags.")
print("122) Get rdlist tags for a room.") print("122) Get rdlist tags for a room.")
print("\n#### ipinfo.io ####") print("\n#### ipinfo.io ####")
@ -193,15 +193,13 @@ while pass_token == False:
elif menu_input == "150": elif menu_input == "150":
report_commands.generate_user_report('','') report_commands.generate_user_report('','')
elif menu_input == "151": elif menu_input == "151":
report_commands.decrypt_zip_file()
elif menu_input == "152":
admin_contact_dict, is_whois = report_commands.lookup_homeserver_admin('') admin_contact_dict, is_whois = report_commands.lookup_homeserver_admin('')
print(f"\nAdmin contacts: {json.dumps(admin_contact_dict, indent=4, sort_keys=True)}\nWhois: {str(is_whois)}") print(f"\nAdmin contacts: {json.dumps(admin_contact_dict, indent=4, sort_keys=True)}\nWhois: {str(is_whois)}")
elif menu_input == "153": elif menu_input == "152":
report_commands.test_send_email() report_commands.test_send_email()
elif menu_input == "154": elif menu_input == "153":
bot_commands.test_matrix_message() bot_commands.test_matrix_message()
elif menu_input == "155": elif menu_input == "154":
report_commands.test_send_incident_reports() report_commands.test_send_incident_reports()
elif menu_input == "q" or menu_input == "Q" or menu_input == "e" or menu_input == "E": elif menu_input == "q" or menu_input == "Q" or menu_input == "e" or menu_input == "E":
print("\nExiting...\n") print("\nExiting...\n")

View File

@ -2,8 +2,6 @@
import os import os
import subprocess import subprocess
import json import json
import random
import string
import time import time
import user_commands import user_commands
import room_commands import room_commands
@ -133,9 +131,9 @@ def block_all_rooms_with_rdlist_tags(rdlist_use_recommended,preset_user_ID,prese
all_room_ids = list(all_room_ids) # convert the set to a list all_room_ids = list(all_room_ids) # convert the set to a list
print(f"all_local_users: {all_local_users}") #print(f"all_local_users: {all_local_users}")
print(f"all_remote_users: {all_remote_users}") #print(f"all_remote_users: {all_remote_users}")
print(f"all_room_ids: {all_room_ids}") #print(f"all_room_ids: {all_room_ids}")
# If there's at least 1 local user detected, ask the admin if they want to generate a user report for every user found in rdlist rooms # If there's at least 1 local user detected, ask the admin if they want to generate a user report for every user found in rdlist rooms
if len(all_local_users) > 0: if len(all_local_users) > 0:
@ -143,7 +141,6 @@ def block_all_rooms_with_rdlist_tags(rdlist_use_recommended,preset_user_ID,prese
generate_user_report_confirmation = input("\nDo you want to generate a user report file for each of these users? y/n? ") generate_user_report_confirmation = input("\nDo you want to generate a user report file for each of these users? y/n? ")
if generate_user_report_confirmation.lower() in ['y', 'yes', 'Y', 'Yes']: if generate_user_report_confirmation.lower() in ['y', 'yes', 'Y', 'Yes']:
for user_id in all_local_users: for user_id in all_local_users:
print(f"\nGenerating user report for user: {user_id}")
# Generate report_dict for each user # Generate report_dict for each user
report_content = report_commands.generate_rdlist_report_summary(all_local_users[user_id], user_id) report_content = report_commands.generate_rdlist_report_summary(all_local_users[user_id], user_id)
report_commands.generate_user_report(user_id, report_content) report_commands.generate_user_report(user_id, report_content)

View File

@ -2,11 +2,8 @@
import os import os
import json import json
import whois import whois
import random
import string
import datetime import datetime
import zipfile import zipfile
import pyAesCrypt
import smtplib import smtplib
import requests import requests
import asyncio import asyncio
@ -72,10 +69,7 @@ def get_report_folder():
return report_folder return report_folder
def encrypt_user_folder(user_report_folder, username): def zip_report_folder(user_report_folder, username):
# Generate a strong random password
strong_password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(20))
# Get parent directory of user_report_folder # Get parent directory of user_report_folder
parent_directory = os.path.dirname(os.path.abspath(user_report_folder)) parent_directory = os.path.dirname(os.path.abspath(user_report_folder))
@ -88,22 +82,7 @@ def encrypt_user_folder(user_report_folder, username):
for file in files: for file in files:
zip_file.write(os.path.join(root, file), arcname=os.path.relpath(os.path.join(root, file), user_report_folder)) zip_file.write(os.path.join(root, file), arcname=os.path.relpath(os.path.join(root, file), user_report_folder))
# Buffer size - 64K return zip_file_name
bufferSize = 64 * 1024
# Encrypt the .zip file
pyAesCrypt.encryptFile(zip_file_name, zip_file_name + ".aes", strong_password, bufferSize)
# Delete the original zip file
#os.remove(zip_file_name)
# Write the password to a file
password_file = open(zip_file_name + ".aes" + ".password", "w")
password_file.write(strong_password)
password_file.close()
# You can return the password if you need to use it later, or you can directly print it here
return strong_password, zip_file_name + ".aes"
def generate_user_report(preset_username, report_details): def generate_user_report(preset_username, report_details):
if len(preset_username) == 0: if len(preset_username) == 0:
@ -222,28 +201,17 @@ def generate_user_report(preset_username, report_details):
break break
# Generate a random password, then encrypt the ./report/username/ folder to a timestamped .zip file # Generate a random password, then encrypt the ./report/username/ folder to a timestamped .zip file
strong_password, encrypted_zip_file_name = encrypt_user_folder(user_report_folder, username) zip_file_name = zip_report_folder(user_report_folder, username)
# Measure the size of the encrypted .zip file in MB # Measure the size of the encrypted .zip file in MB
encrypted_zip_file_size = os.path.getsize(encrypted_zip_file_name) / 1000000 zip_file_size = os.path.getsize(zip_file_name) / 1000000
# Print the password and the encrypted .zip file name # Print the password and the encrypted .zip file name
print("Report generated successfully on user: \"" + username + "\"\n\nYou can send this .zip file and password when reporting a user to law enforcement.") print("Report generated successfully on user: \"" + username + "\"\n\nYou can send this .zip file when reporting a user to law enforcement.")
print("\nPassword: " + strong_password) print(".zip file location: " + zip_file_name)
print("Encrypted .zip file location: " + encrypted_zip_file_name) print(".zip file size: " + str(zip_file_size) + " MB\n")
print("Encrypted .zip file size: " + str(encrypted_zip_file_size) + " MB\n")
return encrypted_zip_file_name, strong_password return zip_file_name
def decrypt_zip_file():
# Ask user for the location of the encrypted .zip file
encrypted_zip_file_name = input("\nPlease enter the location of the encrypted .zip file: ")
# Ask user for the password
strong_password = input("Please enter the password: ")
# Decrypt the ZIP file into the same location as the encrypted ZIP file
pyAesCrypt.decryptFile(encrypted_zip_file_name, encrypted_zip_file_name[:-4], strong_password, 64 * 1024)
# Print the location of the decrypted ZIP file
print("\nDecrypted .zip file location: " + encrypted_zip_file_name[:-4] + "\n")
def lookup_homeserver_admin(preset_baseurl): def lookup_homeserver_admin(preset_baseurl):
if hardcoded_variables.testing_mode == True: if hardcoded_variables.testing_mode == True:
@ -338,7 +306,7 @@ def test_send_email():
print("\nFailed to send email.") print("\nFailed to send email.")
def generate_rdlist_report_summary(room_dict, user_id): def generate_rdlist_report_summary(room_dict, user_id):
print(f"user_dict: {room_dict}") #print(f"user_dict: {room_dict}")
report_content = f"""\n~~~User Report~~~\n\nUsername: {user_id}\n""" report_content = f"""\n~~~User Report~~~\n\nUsername: {user_id}\n"""
for room_id, rdlist_tags in room_dict.items(): for room_id, rdlist_tags in room_dict.items():