Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. require 'yaml'
  2. require 'ostruct'
  3. require 'time'
  4. require 'date'
  5.  
  6. db = []
  7. log = File.new("selinux-avc.txt", "r")
  8.  
  9. selinux_avc_types = {}
  10.  
  11. selinux_avc_types[/audit\((.+?)\): avc: denied \{ (.+?) \} for pid=(.+?) comm="(.+?)" name="(.+?)" dev=(.+?) ino=(.+?) scontext=(.+?) tcontext=(.+?) tclass=(.*)/] =
  12. [:timestamp, :permision, :pid, :comm, :name, :device, :inode, :scontext, :tcontext, :tclass]
  13.  
  14. selinux_avc_types[/audit\((.+?)\): avc: denied \{ (.+?) \} for pid=(.+?) comm="(.+?)" capability=(.+?) scontext=(.+?) tcontext=(.+?) tclass=(.*)/] =
  15. [:timestamp, :permision, :pid, :comm, :capability, :scontext, :tcontext, :tclass]
  16.  
  17. selinux_avc_types[/audit\((.+?)\): avc: denied \{ (.+?) \} for pid=(.+?) comm="(.+?)" saddr=(.+) src=(.+?) daddr=(.+?) dest=(.+?) netif=(.+?) scontext=(.+?) tcontext=(.+?) tclass=(.*)/] =
  18. [:timestamp, :permision, :pid, :comm, :saddr, :src, :daddr, :dest, :netif, :scontext, :tcontext, :tclass]
  19.  
  20. selinux_avc_types[/audit\((.*)\): avc: denied \{ (.+?) \} for pid=(.+?) exe=(.+?) path=(.+?) dev=(.+?) ino=(.+?) scontext=(.+?) tcontext=(.+?) tclass=(.+?)/] =
  21. [:timestamp, :permision, :pid, :exe, :path, :device, :inode, :scontext, :tcontext, :tclass]
  22.  
  23. log.each_line do |line|
  24. line = line.strip # remove \r\n stuff and spaces at start/end
  25. catch(:found) do #speed it a bit up when we found something
  26. selinux_avc_types.each do |regexp, mask|
  27. unless (temp = line.scan(regexp).flatten).empty?
  28. s = OpenStruct.new(Hash[*mask.zip(temp).flatten])
  29. s.timestamp = Time.at(s.timestamp.to_i)
  30. s.pid = s.pid.to_i
  31. s.inode = s.inode.to_i
  32. db << s
  33. throw :found
  34. end
  35. end
  36. end
  37. end
Add Comment
Please, Sign In to add comment