Scripts for notifying a action taken in the honeypots.

notify.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from datetime import datetime
  2. import time
  3. import MySQLdb
  4. import smtplib, ssl
  5. email="josedeception00@gmail.com"
  6. port = 465 # For SSL
  7. password = "honeypot2020"
  8. #
  9. context = ssl.create_default_context()
  10. db = MySQLdb.connect(host='localhost', user = "root",passwd= 'root', db="moodle")
  11. cursor=db.cursor()
  12. notify=cursor.execute("SELECT username FROM mdl_user, mdl_logstore_standard_log where mdl_user.id = mdl_logstore_standard_log.USERID and username='dummy1' ")
  13. user=cursor.fetchone()
  14. cursor.execute("SELECT timecreated FROM mdl_logstore_standard_log WHERE USERID = '3' ORDER BY timecreated DESC LIMIT 1,1 ")
  15. newtime = cursor.fetchone()
  16. newtime=(newtime[0])
  17. f=open("time.txt","r+")
  18. oldtime=f.readline()
  19. oldtime=int(oldtime)
  20. time=datetime.utcfromtimestamp(newtime).strftime('%m-%d-%Y %H-%M-%S')
  21. message=f"""\
  22. Subject:decoy {time}
  23. To:{email}
  24. From:{email}
  25. {user[0]} logged in {time} """
  26. if oldtime < newtime:
  27. with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
  28. server.login(email, password)
  29. server.sendmail(email ,email, message)
  30. print(user[0], " logged in ", time)
  31. f.seek(0)
  32. f.write(str(newtime))
  33. else:
  34. print( False)
  35. cursor.close()
  36. db.close()
  37. f.close()