Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import sys
  2. import os
  3. import time
  4. import subprocess
  5.  
  6. class pythonSnortLogWatcher:
  7.  
  8. def __init__(self,path):
  9. self.f = open(path)
  10. self.f.read()
  11. self.priorityTwoColorBegin = "<span color='#FF6600'>"
  12. self.priorityOneColorBegin = "<span color='#FF0000'>"
  13. self.colorEnd = "</span>"
  14. self.welcomeMessage()
  15.  
  16. def welcomeMessage(self):
  17. subprocess.call(['notify-send','-t','5000',
  18. 'Intrusion Detection System Activated'])
  19.  
  20. def run(self):
  21. while True:
  22. line = self.f.read()
  23. if len(line) != 0:
  24. self.processLine(line)
  25. time.sleep(0.2)
  26.  
  27. def processLine(self,line):
  28. newLine = self.parseLine(line)
  29. if len(newLine) != 0:
  30. subprocess.call(['notify-send','-t','5000',newLine.strip()])
  31.  
  32. def parseLine(self,line):
  33. if line.rfind('BLEEDING-EDGE SCAN') != -1:
  34. return self.parseScanLine(line)
  35. elif line.rfind('http_inspect') != -1:
  36. return self.parseHttpInspectLine(line)
  37. elif line.rfind('TCP Timestamp') != -1:
  38. return ""
  39. else:
  40. return self.parseDefaultLine(line)
  41.  
  42. def parseScanLine(self,line):
  43. sliceOfString = line.split('BLEEDING-EDGE')[1]
  44. newString = sliceOfString.replace('[**]','')
  45. newString = newString.replace('[Classification: Attempted Information Leak]','')
  46. newString = newString.replace('[Priority: 2]','')
  47. return self.checkPriority(line,newString)
  48.  
  49. def parseHttpInspectLine(self,line):
  50. sliceOfString = line.split('(')[1]
  51. newString = sliceOfString.replace(')','')
  52. newString = newString.replace('[Priority: 3]','')
  53. newString = newString.replace('[**]','')
  54. return self.checkPriority(line,newString)
  55.  
  56. def parseDefaultLine(self,line):
  57. return self.checkPriority(line,line)
  58.  
  59. def checkPriority(self,originalLine,newLine):
  60. if originalLine.rfind("Priority: 3") != -1:
  61. return newLine
  62.  
  63. if originalLine.rfind("Priority: 2") != -1:
  64. return self.priorityTwoColorBegin + newLine + self.colorEnd
  65.  
  66. if originalLine.rfind("Priority: 1") != -1:
  67. return self.priorityOneColorBegin + newLine + self.colorEnd
  68.  
  69.  
  70. #-- [ Main ] --------------------------------------------------#
  71.  
  72. if __name__ == '__main__':
  73. logger = pythonSnortLogWatcher('/var/log/snort/alert')
  74. logger.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement