Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. import mysql.connector
  2. import numpy
  3. from datetime import datetime, timedelta
  4.  
  5. import smtplib, ssl
  6. from email.mime.text import MIMEText
  7. from email.mime.multipart import MIMEMultipart
  8.  
  9. mydb = mysql.connector.connect(
  10. host="localhost",
  11. user="brandon",
  12. passwd="nope",
  13. database="securityonion_db"
  14. )
  15.  
  16. #get time THIS IS PST FOR ALL YO PPL WHO WANT DIS EDIT as needed Security onion uses UTC by defualt
  17. CurrentTime = datetime.now() + timedelta(hours=-7)
  18. TimeConvert = datetime.now() + timedelta(hours=-31)
  19. #bullshit that dont work
  20. #print str(TimeConvert)
  21. #'{:%H:%M:%S}'.format(TimeConvert)
  22. #print (time.strftime("%Y-%m-%d %I:%M:%S"))
  23.  
  24.  
  25. mycursor = mydb.cursor()
  26.  
  27. mycursor.execute("SELECT COUNT(*) AS cnt, signature, signature_id FROM event WHERE (priority=1 AND status=0 AND `timestamp` > \'" + str(TimeConvert) + "\') GROUP BY signature ORDER BY cnt DESC LIMIT 100")
  28. myresult = mycursor.fetchall()
  29.  
  30. myarray = numpy.asarray(myresult)
  31. #print (myarray)
  32.  
  33. count = len(myarray)
  34. i = 0
  35. s1 = """<table>
  36. <thead>
  37. <tr>
  38. <th>Count</th>
  39. <th>Alert</th>
  40. <th>Alert ID</th>
  41. </tr>
  42. </thead>
  43. <tbody>"""
  44. s2 = ""
  45. while i < count:
  46. a = myarray[i]
  47. s2 = s2 + """
  48. <tr>
  49. <td>""" + a[0] + """</td>
  50. <td>""" + a[1] + """</td>
  51. <td>""" + a[2] + """</td>
  52. </tr>"""
  53. i = i + 1
  54. s3 = """ </tbody>
  55. </table>"""
  56.  
  57. htmltxt = ("Summary of network attacks against the SakaServer network over the past 24 hours: <p> Logs from: <b>" + str(TimeConvert) + "</b> to <b>" + str(CurrentTime) + "</b> <p>" + s1 + s2 + s3)
  58.  
  59. print (htmltxt)
  60.  
  61.  
  62. # EMAILER
  63.  
  64. sender_email = "nopesender@gmail.com"
  65. receiver_email = "nope@gmail.com"
  66. password = "nope"
  67.  
  68. message = MIMEMultipart("alternative")
  69. message["Subject"] = "[SakaServer] Network Security Daily Report " + str(CurrentTime)
  70. message["From"] = sender_email
  71. message["To"] = receiver_email
  72.  
  73. # Create the plain-text and HTML version of your message
  74. text = """\ """
  75.  
  76. html = str(htmltxt)
  77.  
  78. # Turn these into plain/html MIMEText objects
  79. part1 = MIMEText(text, "plain")
  80. part2 = MIMEText(html, "html")
  81.  
  82. # Add HTML/plain-text parts to MIMEMultipart message
  83. # The email client will try to render the last part first
  84. message.attach(part1)
  85. message.attach(part2)
  86.  
  87. # Create secure connection with server and send email
  88.  
  89. s = smtplib.SMTP('smtp.gmail.com', 587)
  90. # start TLS for security
  91. s.starttls()
  92. # Authentication
  93. s.login(sender_email, password)
  94. # message to be sent
  95. message = message.as_string()
  96. # sending the mail
  97. s.sendmail(sender_email, receiver_email, message)
  98. # terminating the session
  99. s.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement