Create An Advanced Keylogger in Python Guide
Create An Advanced Keylogger in Python Guide
© Cybercademy 2020
DOCUMENT OVERVIEW
WHY IT’S IMPORTANT TO TRY BEFORE FOLLOWING A COURSE (2)
EMAIL (6)
CLIPBOARD (7)
MICROPHONE (7)
SCREENSHOT (8)
EXECUTABLE (9)
2
© Cybercademy 2020
But being able to apply what you are learning is critical. Therefore, before you walk through a tutorial,
online course, or guide, I highly recommend you try building your own version of the topic… It doesn’t
have to be the same exact implementation as the instructor. It’s more about the thought process that
goes into the idea over the answer. Through time, you will find it easier to solve and create your very
own implementations of a concept you think of.
With all of this being said, I encourage you to build your very own version of the advanced keylogger in
python before watching the online crash course.
Not only will you be able to better understand the functionalities of the keylogger through your own
application and thought processes, but you will also be able to retain what you are learning.
Use this small guide as a way of helping you think through each functionality of the keylogger.
Sometimes it’s nice to have a “launch pad” which helps you get started in the thinking process and once
you consider the process, you will start to come up with ideas of implementation. I hope this helps!
- Grant Collins
3
© Cybercademy 2020
Step Two: Go through the setup wizard and make sure to install pip as well as add python to the path (screenshot
credit: Data to Fish)
Step Four: Open PyCharm once downloaded and select Create New Project (screenshot credit: BeginnersBook).
4
© Cybercademy 2020
Step 5: Now you will download all packages / modules / dependencies for the project. There are multiple methods
to do this, including using the pip tool, or directly importing through PyCharm. We will be directly importing all
packages in Python (because often permission and file paths can get messed up when using the pip tool).
To install a package through PyCharm, navigate to File --> Settings (CTRL + ALT + S).
Under settings, navigate to Project: Project Name, and select Project Interpreter.
When you have clicked on the + icon, a new window will pop open named Available
Packages. We can search for each module / package and install directly into our project. For
example, to install the cryptography module, simply search “cryptography”, click the
package which says cryptography, then click Install Package and wait for it to install.
Once package has been successfully installed, we can move onto the next module to install.
For this project, install all of the following modules (name is exactly the name of the
package)
- pywin32
- pynput
- scipy
- cryptography
- requests
- pillow
- sounddevice
Once you have imported all modules, exit out all of settings windows and wait a few minutes for each package to
install.
You have successfully installed python, PyCharm, and all required modules.
5
© Cybercademy 2020
We will also need 3 addition files for encryption, I simply used the e_file_name syntax for each file.
system_information_e = 'e_system.txt'
clipboard_information_e = 'e_clipboard.txt'
keys_information_e = 'e_keys_logged.txt'
LOGGING KEYS
To log keys using python, we will be using the pynput module.
Module to install:
from pynput.keyboard import Key, Listener
EMAIL
To add an email functionality, we will be using the email module.
Modules to install:
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import smtplib
6
© Cybercademy 2020
COMPUTER INFORMATION
To gather computer information, we will use socket and platform modules.
Modules to install:
import socket
import platform
CLIPBOARD
To get the clipboard information, we will be using the win32clipboard module, which is a submodule of
pywin32
Module to install:
import win32clipboard
• The person may not have any writeable data for the clipboard (could have copied an image), so make sure
to use a try – except block just in case information could not be copied.
• To open clipboard, use the win32clipboard.OpenClipboard()
• To get clipboard information, use the win32clipboard.GetClipboardData()
• To close the clipboard, use the win32clipboard.CloseClipboard()
MICROPHONE
To record with microphone, we will be using the sounddevice module and writing to a .wav file using the
scipy.io.wavefile module.
Module to install:
from scipy.io.wavfile import write
import sounddevice as sd
7
© Cybercademy 2020
SCREENSHOT
To take a screenshot, we will use the ImageGrab from the Pillow Module.
Modules to install:
from multiprocessing import Process, freeze_support
from PIL import ImageGrab
To ensure only one screenshot is taken at a time, add freeze_support(). Use the following code below:
if __name__ == “__main__”:
freeze_support()
Process(target=screenshot).start()
8
© Cybercademy 2020
ENCRYPTION OF FILES
To encrypt files, we will use the cryptography.fernet module.
Module to import:
from cryptography.fernet import Fernet
EXEXCUTABLE
Converting our Python Keylogger to an executable can be a little tricky. Python isn’t very good at
converting scripts and programs into executables because there are often many dependencies
(modules) which have to be downloaded. To turn this keylogger into an executable, I recommend using
one of two programs… I have included some helpful tutorials which can help you convert your Python
programs into executables.
• pyinstaller: https://www.youtube.com/watch?v=lOIJIk_maO4
• Auto PY to EXE: https://www.youtube.com/watch?v=OZSZHmWSOeM