Advertisement
D0cEvil

Logstash - DNS parcer for Suricata log

Sep 23rd, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.28 KB | Cybersecurity | 0 0
  1. ### DNS parcer for Suricata log
  2. #
  3. # Читаем локальный файл, пишем в Elastic
  4. #
  5. #
  6. input {
  7.     file {
  8.         path => [ "/var/log/suricata/dns.log" ]
  9.         sincedb_path => "/dev/null"
  10.         start_position => "beginning" #Поменять на end#
  11.     }
  12. }
  13.  
  14. filter {
  15.     ##### Simple DNS query #####
  16.     if "Query" in [message] and "AAAA" not in [message] {
  17.         grok {
  18.             match => {
  19.                 "message" => "%{GREEDYDATA:timestamp}  ?\[?\*?\*?\] %{WORD:dns.message.type} %{WORD} %{WORD} ?\[?\*?\*?\] %{HOSTNAME:dns.request} ?\[?\*?\*?\] %{WORD:dns.record.type} ?\[?\*?\*?\] %{IP:dns.client.ip}:%{WORD:dns.client.port} %{GREEDYDATA} %{IP:dns.server.ip}:%{WORD:dns.server.port}"
  20.             }
  21.         }
  22.         if "_grokparsefailure" in [tags] {
  23.             drop { }
  24.         }
  25.     }
  26.     if "Query" in [message] and "AAAA" in [message] {
  27.         grok {
  28.             match => {
  29.                 "message" => "%{GREEDYDATA:timestamp}  ?\[?\*?\*?\] %{WORD:dns.message.type} %{WORD} %{WORD} ?\[?\*?\*?\] %{DATA:dns.request} ?\[?\*?\*?\] %{WORD:dns.record.type} ?\[?\*?\*?\] %{IP:dns.client.ip}:%{WORD:dns.client.port} %{GREEDYDATA} %{IP:dns.server.ip}:%{WORD:dns.server.port}"
  30.             }
  31.         }
  32.         if "_grokparsefailure" in [tags] {
  33.             drop { }
  34.         }
  35.     }
  36.     ##### Simple DNS response #####
  37.     else if "Response" in [message] and "AAAA" not in [message] and "CNAME" not in [message] {
  38.         grok {
  39.             match => {
  40.                 "message" => "%{GREEDYDATA:timestamp}  ?\[?\*?\*?\] %{WORD:dns.message.type} %{WORD} %{WORD} ?\[?\*?\*?\] %{DATA:dns.request} ?\[?\*?\*?\] %{WORD:dns.record.type} ?\[?\*?\*?\] %{WORD} %{WORD:dns.ttl} ?\[?\*?\*?\] %{DATA:dns.reply.ip} ?\[?\*?\*?\] %{IP:dns.server.ip}:%{WORD:dns.server.port} %{GREEDYDATA} %{IP:dns.client.ip}:%{WORD:dns.client.port}"
  41.             }
  42.             add_tag => ["ip.v4"]           
  43.         }
  44.         geoip {
  45.             source => "dns.reply.ip"
  46.         }
  47.         if "_grokparsefailure" in [tags] {
  48.             drop { }
  49.         }
  50.     }
  51.     ##### IPv6 DNS response #####
  52.     else if "Response" in [message] and "AAAA" in [message] and "CNAME" not in [message] {
  53.         grok {
  54.             match => {
  55.                 "message" => "%{GREEDYDATA:timestamp}  ?\[?\*?\*?\] %{WORD:dns.message.type} %{WORD} %{WORD} ?\[?\*?\*?\] %{DATA:dns.request} ?\[?\*?\*?\] %{WORD:dns.record.type} ?\[?\*?\*?\] %{WORD} %{WORD:dns.ttl} ?\[?\*?\*?\] %{DATA:dns.reply.ip} ?\[?\*?\*?\] %{IP:dns.server.ip}:%{WORD:dns.server.port} %{GREEDYDATA} %{IP:dns.client.ip}:%{WORD:dns.client.port}"
  56.             }
  57.             add_tag => ["ip.v6"]
  58.         }
  59.         if "_grokparsefailure" in [tags] {
  60.             drop {}
  61.         }
  62.     }
  63.     ##### IPv4 DNS response with CNAME ######
  64.     else if "Response" in [message] and "AAAA" not in [message] and "CNAME" in [message] {
  65.         grok {
  66.             match => {
  67.                 "message" => "%{GREEDYDATA:timestamp}  ?\[?\*?\*?\] %{WORD:dns.message.type} %{WORD} %{WORD} ?\[?\*?\*?\] %{HOSTNAME:dns.cname.response} ?\[?\*?\*?\] %{WORD:dns.record.type} ?\[?\*?\*?\] %{WORD} %{WORD:dns.ttl} ?\[?\*?\*?\] %{HOSTNAME:dns.name.orig} ?\[?\*?\*?\] %{IP:dns.server.ip}:%{WORD:dns.server.port} %{GREEDYDATA} %{IP:dns.client.ip}:%{WORD:dns.client.port}"
  68.             }
  69.         }
  70.         if "_grokparsefailure" in [tags] {
  71.             drop {}
  72.         }
  73.     }
  74. # гребанный timestam....
  75.     date {
  76.         match => ["timestamp", "MM/dd/yyyy-HH:mm:ss.SSSSSS"]
  77.         timezone => "America/Toronto"
  78.         target => ["@timestamp"]
  79.     }
  80. }
  81. output {
  82.         elasticsearch {
  83.                 hosts => ['IP этого сранного эластик-сервака:9200']
  84.         }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement