Zeekurity Zen – Part VIII: How to Send Zeek Logs to Elastic

Zeekurity Zen – Part VIII: How to Send Zeek Logs to Elastic

This is part of the Zeekurity Zen Zeries on building a Zeek (formerly Bro) network sensor.

Overview

In our Zeek journey thus far, we’ve:

In Part III, we sent our Zeek logs to Splunk and unlocked a new level of analysis and visualization capabilities.  But what if we don’t have access to Splunk? What if instead of Splunk, we use Elastic?

For those new to Elastic, the “Elastic Stack” or “ELK Stack” is a popular open source data analytics platform.  Elastic has become increasingly popular not just because it offers a free tier but also through the addition of significant security-focused features and an active user community.

Fortunately for us, Elastic natively supports Zeek logs and is a great way to analyze and visualize Zeek data.

To do this, we’ll walkthrough these steps:

  1. Configure Zeek to output logs in JSON format.
  2. Install and configure Filebeat to consume Zeek logs.
  3. Write simple Kibana queries.

Output Zeek logs to JSON

  1. Stop Zeek if it is currently running.
    zeekctl stop
  2. Edit /opt/zeek/share/zeek/site/local.zeek and add the following.
    # Output to JSON
    @load policy/tuning/json-logs.zeek
  3. Restart Zeek and view the logs in /opt/zeek/logs/current to confirm they are now in JSON format.
    zeekctl deploy
    cd /opt/zeek/logs/current
    less conn.log

Configure Filebeat

This guide assumes you have already installed Filebeat. If not, refer to Elastic’s documentation and then come back here when you’re done.

  1. Switch back to your normal user.
    su eric
  2. Stop Filebeat if it is currently running.
    sudo systemctl stop filebeat
  3. Enable Filebeat’s Zeek module.
    sudo filebeat modules enable zeek
  4. Add Zeek’s log paths (e.g., /opt/zeek/logs/current/http.log) to the Zeek Filebeat configuration file. Assuming you installed Filebeat from the standard Elastic repositories, the configuration file will be in /etc/filebeat/modules.d/zeek.yml. For each log type you want to capture:
    • Set the enabled field to true.
    • Set the var.paths field to the log’s specific path.

    The sample configuration file below enables all log types currently available in the Filebeat Zeek module. Note that while the “signature” log type is listed, it is currently not available and will result in an error if enabled. This Github issue discusses this in further detail.

    # Module: zeek
    # Docs: https://www.elastic.co/guide/en/beats/filebeat/7.x/filebeat-module-zeek.html
    - module: zeek
      capture_loss:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/capture_loss.log"]
      connection:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/conn.log"]
      dce_rpc:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/dce_rpc.log"]
      dhcp:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/dhcp.log"]
      dnp3:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/dnp3.log"]
      dns:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/dns.log"]
      dpd:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/dpd.log"]
      files:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/files.log"]
      ftp:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/ftp.log"]
      http:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/http.log"]
      intel:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/intel.log"]
      irc:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/irc.log"]
      kerberos:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/kerberos.log"]
      modbus:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/modbus.log"]
      mysql:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/mysql.log"]
      notice:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/notice.log"]
      ntlm:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/ntlm.log"]
      ntp:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/ntp.log"]
      ocsp:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/oscp.log"]
      pe:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/pe.log"]
      radius:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/radius.log"]
      rdp:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/rdp.log"]
      rfb:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/rfb.log"]
      signature:
        enabled: false
        var.paths: ["/opt/zeek/logs/current/signature.log"]
      sip:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/sip.log"]
      smb_cmd:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/smb_cmd.log"]
      smb_files:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/smb_files.log"]
      smb_mapping:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/smb_mapping.log"]
      smtp:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/smtp.log"]
      snmp:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/snmp.log"]
      socks:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/socks.log"]
      ssh:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/ssh.log"]
      ssl:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/ssl.log"]
      stats:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/stats.log"]
      syslog:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/syslog.log"]
      traceroute:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/traceroute.log"]
      tunnel:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/tunnel.log"]
      weird:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/weird.log"]
      x509:
        enabled: true
        var.paths: ["/opt/zeek/logs/current/x509.log"]
        # Set custom paths for the log files. If left empty,
        # Filebeat will choose the paths depending on your OS.
        #var.paths:
    
  5. Restart Filebeat to apply the configuration and confirm your Zeek logs are now properly ingested into Elasticsearch and available for analysis in Kibana.
    sudo systemctl restart filebeat

Simple Kibana Queries

Once Zeek logs are flowing into Elasticsearch, we can write some simple Kibana queries to analyze our data. Let’s convert some of our previous sample threat hunting queries from Splunk SPL into Elastic KQL. Try taking each of these queries further by creating relevant visualizations using Kibana Lens.

Connections To Destination Ports Above 1024

event.module:zeek AND event.dataset:zeek.connection AND destination.port>1024

Query Responses With NXDOMAIN

event.module:zeek AND event.dataset:zeek.dns AND dns.response_code:NXDOMAIN

Expired Certificates

event.module:zeek AND event.dataset:zeek.x509 AND file.x509.not_after < now

Stuff I Like

Web Hosting: SiteGround

ericooi.com is proudly hosted by SiteGround. Performance and customer service are top notch. Quick and easy https implementation via built-in Let's Encrypt integration.


2 thoughts on “Zeekurity Zen – Part VIII: How to Send Zeek Logs to Elastic”

  • Hi Eric,

    How would you do some of the other Splunk Queries in Zeek/Kibana? I’m having a hard time trying to do it in Kibana:

    This one for example in Splunk:
    TOP 10 SOURCES BY BYTES SENT
    Recommended visualization: Statistics view

    index=zeek sourcetype=zeek_conn
    | stats values(service) as Services sum(orig_bytes) as B by id.orig_h
    | sort -B
    | head 10
    | eval MB = round(B/1024/1024,2)
    | eval GB = round(MB/1024,2)
    | rename id.orig_h as Source
    | fields Source B MB GB Services

    or even this simple one:
    TOP 10 DESTINATIONS BY NUMBER OF CONNECTIONS
    Recommended visualization: Column Chart

    index=zeek sourcetype=zeek_conn
    | top id.resp_h
    | head 10

    Any help would be greatly appreciated.
    Thanks

    • Hi kdz,

      I suppose I should update that post with the Elastic equivalents. 🙂

      To the specific questions you asked, try this:

      Top 10 Sources by Bytes Sent
      1. In Kibana, navigate to Analyze -> Visualize Library and click on “Create visualization.”
      2. Click on “Lens.”
      3. In the top left, click on “Add filter” and add a filter for event.dataset: zeek.connection.
      4. For the visualization type select “Table.”
      5. In the right-side menu of Table options, configure “Rows” to include: “Top values” of source.ip” and “Top values of network.protocol.” You can adjust how many “Top” values you want to show for each of these values. If you just want overall top 10, you’d configure source.ip to be 10 and network.protocol to be 1.
      6. In the same menu of Table options, configure “Metrics” to include “Sum of source.bytes.” You can change the “Value format” to “Bytes (1024)” and adjust the number of “Decimals” to your liking.

      Top 10 Destinations by Number of Connections
      1 – 3: Same steps as above.
      4. For the visualization type select “Bar vertical.”
      5. In the right-side menu of options, configure “Horizontal axis” to include “Top values of event.dataset.”
      6. In the same menu of options, configure “Vertical axis” to include “Count of Records.”
      7. In the same menu of options, configure “Break down by” to include “Top values of destination.ip.”

      Give those a try and see if they work for you.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.