This script is a simple keylogger that captures keystrokes and saves them to a file named keylog.txt. Additionally, it sends the log file via email when the Esc key is pressed. Below is a detailed description of the script's functionality:
-
Keystroke Logging:
- The script uses the
pynputlibrary to listen for keyboard events. - Keystrokes are recorded and appended to a file named
keylog.txt.
- The script uses the
-
Email Notification:
- When the
Esckey is pressed, the script stops logging and sends thekeylog.txtfile as an email attachment. - The email is sent using the
smtpliblibrary, with the email content and attachment handled by theemail.mimemodules.
- When the
-
Logging Keystrokes:
- The
on_pressfunction captures each key press and writes it tokeylog.txt. - The
on_releasefunction checks if theEsckey is pressed. If so, it triggers thesend_emailfunction and stops the listener.
- The
-
Sending Email:
- The
send_emailfunction constructs an email with thekeylog.txtfile attached. - It uses SMTP to send the email from a specified sender address to a recipient address.
- The
-
Dependencies:
- Ensure you have the
pynputandsmtpliblibraries installed. You can installpynputusing pip:pip install pynput pip install smtplib
- Ensure you have the
-
Configuration:
- Update the
fromaddr,toaddr, and SMTP server details in thesend_emailfunction with your own email credentials and server information.
- Update the
-
Running the Script:
- Run the script in your Python environment. It will start logging keystrokes immediately.
- Press the
Esckey to stop logging and send the email with the log file attached.
- Ethical Use: This script should only be used for ethical purposes, such as monitoring your own devices or for educational purposes. Unauthorized use of keyloggers is illegal and unethical.
- Security: Ensure that your email credentials are stored securely and not hard-coded in the script for production use.
By following the above instructions, you can use this keylogger script to capture keystrokes and send the log file via email.