visit
⚠️This post is for educational purposes only⚠️
A keylogger is probably one of the last things you want on your computer. Unfortunately, this type of program is usually well hidden and often go completely undetected by the victim. At its core, a keylogger is a device or program that logs everything you type on your computer. Meaning that every password, every private message you send, and every search you type can be recorded and read by a malicious party. There are two primary categories of keyloggers, hardware loggers and software loggers. Hardware loggers are usually easier to detect. They are often characterized as a small device that physically sits between a . With the advent of Bluetooth keyboards this type of logger is less common now, however . Software loggers are often much better concealed and are a common feature to be included in rootkits. Rootkits are a particularly nasty class of malware that live at a very low level of the computer, often below where the operating system or anti-virus programs are able to detect. Rootkits typically run with such high privileges such that nothing is outside of their visibility. More advanced rootkits may also have capabilities beyond recording simple keystrokes, including taking screenshots and even covertly recording video and sounds using a computer’s camera and microphone.In this post I’ll demonstrate how you can set up a simple keylogger on macOS using python. Apple’s security for macOS is generally held to a fairly high standard and therefore to get a program like this to run we’ll need to deliberately weaken macOS’ security for this purpose.
An actual malicious keylogger would likely exploit some kind of vulnerability in order to get past Apple’s security controls and an advanced logger may make use of other hiding mechanisms to conceal the process itself and communicate the collected keystroke data with a remote command and control server.csrutil disable
and press enter.reboot
and press enter.Important: For your own security, remember to re-enable this feature after you’re done testing by following the steps above but entering
csrutil enable
in step 5.
Next we’ll create our Writer class. This class is responsible for creating a log file and logging all collected keystrokes.
Finally we’ll look at our AppDelegate class which will actually collect the keydown events as well as our handler which will interpret the keydown events and send the results to the Writer class “write_to_log” method.
Finding the logged file
As you may have noticed in the python code, I’m attempting to write my data to /Library/Caches/com.apple.pkl
. The idea here is to try to write the data somewhere inconspicuous, such as where system caches are located. Most users will never visit this location, much less know to look for anything suspicious.
Killing the script
Assuming the script runs successfully, it should simply be a python process running in the background. If you named the python file “pkl.py” as I did you can kill it by running: kill -9 $(ps aux | grep pkl.py | awk ‘{print $2}'
.
Cleaning up the Assistive Devices Whitelist
I like to do this by modifying the sqlite database that houses these permissions, but it can also easily be done within System Preferences.