Registration is open - Live, Instructor-led Online Classes - Elasticsearch in March - Solr in April - OpenSearch in May. See all classes

Network Security with Bro (now Zeek) and Elasticsearch

Intrusion detection systems generate highly valuable logs with network usage details and alerts.
They collect vast amounts of data and typically store them in structures with a large number of fields.  To make sense of so much data and to make such information actionable requires advanced analytics, alerts, and search functionality. Because of that the IDS systems and Log Management systems are a perfect match!

Nevertheless, parsing, shipping and analyzing logs could be challenging.
In this blog post we’ll show an easy way to set up for the popular trio – Bro Network Security Monitor, Logagent, and Elasticsearch – and get you started with IDS log analysis within just a few minutes!

Meet the Bro Intrusion Detection System

Bro is a powerful network analysis framework that is much different from the typical IDS you may know.

While focusing on network security monitoring, Bro provides a comprehensive platform for more general network traffic analysis as well. Well grounded in more than 15 years of research, Bro has successfully bridged the traditional gap between academia and operations since its inception. Today, it is relied upon operationally in particular by many scientific environments for securing their cyberinfrastructure. Bro’s user community includes major universities, research labs, supercomputing centers, and open-science communities.

Bro has originally been developed by Vern Paxson, who continues to lead the project now jointly with a core team of researchers and developers at the International Computer Science Institute in Berkeley, CA; and the National Center for Supercomputing Applications in Urbana-Champaign, IL.


IDS systems like Bro produce vast amounts of information for network security. A simple network connection log message might contain key information for security incident post-mortem analysis, so that, along many other things, needs to be logged. One can use various existing and custom Bro IDS scripts to detect nearly any anomaly in the network from the collected data, but they have a few downsides, such as:

  • You don’t know in advance which events should be reported
  • To write a custom script you need to learn Bro scripting language and available field names for each protocol

To make our lives with Bro easier we want to make the resulting IDS logs searchable. Doing that allowed iterative, interactive, ad-hoc querying, which results in a big productivity boost for security incident post-mortems. It also lets us create  alert queries on the continuous stream of this log data, thus enabling near real-time reactions to reported issues.

This post provide the recipe for making Bro logs searchable with Elasticsearch. The idea is to configure Bro IDS to generate logs in JSON format and then use a log shipper to forward them to Elasticsearch or Logsene. We will start with some Bro IDS basics, then configure Logagent as the log shipper, and finally show the results in Logsene, a handy ELK as a Service we’ll use to avoid needing to run our own Elasticearch.

Step 1:  Get started with a few Bro IDS basics:

Install Bro on Debian/Ubuntu Linux

$ apt-get install bro 

Run Bro to capture packets on the eth0 interface

$ sudo bro -i eth0 

Note that there is no output on the console because all information is written to various log files in the current directory. Press CTRL+C to terminate Bro and run ls *.log to see the generated log files and display e.g. the connection log:

$ cat conn.log
#separator \x09
#set_separator ,
#empty_field (empty)
#unset_field -
#path conn
#open 2017-01-12-13-09-36
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p proto service duration orig_bytes resp_bytes conn_state local_orig local_resp missed_bytes history orig_pkts orig_ip_bytes resp_pkts
 resp_ip_bytes tunnel_parents
#types time string addr port addr port enum string interval count count string bool bool count string count count count count set[string]
1484222976.365029 C2mUt14hC9iOrC8se 62663 443 tcp - - - - OTH - - 0 d 0 0 1 494 (empty)
1484222975.423814 CDpOCg4wzHbeAbQn4 49904 443 tcp - 0.000002 0 976 OTH - - 0 d 0 0 2 1080 (empty)
1484222974.911667 C75yx91lD2bArc9CKj 56717 443 tcp - - - - OTH - - 0 a 0 0 1 52 (empty)
1484222974.852917 CQISpU3YnsqbRkLAf5 56911 443 tcp - - - - OTH - - 0 a 0 0 1 52 (empty)
1484222976.235060 Cdl9TTqFYx2fdG7Gi 51730 443 tcp - 0.097194 0 4330 OTH - - 0 ad 0 0 4 4538 (empty)
1484222975.149426 Cgw13b4NHZwoK73N41 49699 443 tcp - 0.072127 0 62 OTH - - 0 ad 0 0 2 166 (empty)
#close 2017-01-12-13-09-36

Now let’s adjust Bro log format to JSON and run Bro again

$ sudo bro -i eth0 -e 'redef LogAscii::use_json=T;' 

Check that JSON format is used

$ cat conn.log

This was easy! Bro logs all info in different Bro log files like conn.log, http.log, dns.log, weird.log etc.

Step 2:  Install & Configure Logagent

Install Logagent

Install Node.js runtime including npm package manager:

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

Install Logagent package and create a service for Logagent:

sudo npm i @sematext/logagent -g

# create logagent service, but stop it until we are done with the whole setup

sudo logagent-setup bro_ids_logs && sudo service service logagent stop

We will create the configuration for Logagent in the following steps and, once done, we’ll start the run Logagent service again.

Logagent Configuration

Having the IDS information in separate log files and in JSON makes it easy to configure a log shipper to index those logs in Elasticsearch or Logsene. Using Logagent we’ll do the following:

  1. Start Bro IDS using Logagent input-command plugin and collect all Bro logs
  2. Convert the timestamp (ts field) from Bro logs to a date and put it in the @timestamp field for Elasticsearch
  3. Configure bulk indexing for Elasticsearch

We will use Logagent input-command plugin to start Bro with Logagent. The Logagent input-command plugin can execute any command, watch the process, and even restart it if it terminates. If the command produces output on the console, Logagent will capture that output.  This way we will capture any error messages Bro outputs to console and index them to Elasticsearch as well. To capture the network event logs produced by Bro we’ll use the Logagent file input plugin. Bro always logs to files in the current directory, so we combine a few commands to start Bro, create a directory, and then run Bro in that directory. With this setup we collect the logs from the directory specified in the run command:

    module: command
    # store BRO logs in /tmp/bro in JSON format
    command: mkdir /tmp/bro; cd /tmp/bro; bro -i eth0 -e 'redef LogAscii::use_json=T;'
    sourceName: bro
    restart: 1
  # read the BRO logs from the file system ...
      - '/tmp/bro/*.log'

To index logs in Elasticsearch we need a valid date for the timestamp. Bro provides a UNIX timestamp in the ts field, which needs to be converted to a JavaScript Date object with a JavaScript transform function in the Logagent parser configuration. In addition, let’s set the _type for logs based on the Bro logs file names so we can use that for filtering. For example, for all logs from /tmp/bro/dns.log we’ll use “dns” as _type. Here is the relevant parser config and the JS transform function:

    enabled: true
    transform: !!js/function >
      function (sourceName, parsed, config) {
        var src = sourceName.split('/')
        // generate Elasticsearch _type out of the log file sourceName
        // e.g. "dns" from /tmp/bro/dns.log
        if (src && src[src.length-1]) {
        parsed._type = src[src.length-1].replace(/\.log/g,'')
        // store log file path in each doc
        parsed.logSource = sourceName
        // convert Bro timestamps to JavaScript timestamps
        if (parsed.ts) {
        parsed['@timestamp'] = new Date(parsed.ts * 1000)

Finally, let’s define where to store logs using the Elasticsearch output plugin and, in addition, let’s activate output to the console in YAML format so we can see the logs on the console:

  stdout: yaml
    module: elasticsearch 
    url: http://localhost:9200
    index: bro_ids_logs

To ship data to Logsene and avoid having to run your own Elasticsearch cluster simply replace url and index parameters. Use the Logsene App token as index name and HTTPS so your logs are encrypted on their way to Logsene:

  stdout: yaml
    module: elasticsearch 
    index: 4f70a0c7-9458-43e2-bbc5-xxxxxxxxx

After we store the whole config as bro-ids.yaml we can run Logagent with Bro to test the configuration:

$ sudo logagent --config bro-ids.yaml
2017-01-12T12:34:12.205Z pid[26732] add command to plugin list
2017-01-12T12:34:12.207Z pid[26732] init plugins
2017-01-12T12:34:12.207Z pid[26732] init plugins
2017-01-12T12:34:12.208Z pid[26732] init plugins
2017-01-12T12:34:12.208Z pid[26732] ../lib/plugins/input/stdin
2017-01-12T12:34:12.227Z pid[26732] ../lib/plugins/output/stdout
2017-01-12T12:34:12.237Z pid[26732] ../lib/plugins/input/command.js
2017-01-12T12:34:12.245Z pid[26732] ../lib/plugins/input/command.js
2017-01-12T12:34:12.248Z pid[26732] ../lib/plugins/output/elasticsearch.js
2017-01-12T12:34:12.429Z pid[26732] ../lib/plugins/input/files
2017-01-12T12:34:12.522Z pid[26732] using glob pattern: /tmp/bro/*.log
2017-01-12T12:34:12.603Z pid[26732] Watching file:/tmp/bro/conn.log from position: 85285
2017-01-12T12:34:12.604Z pid[26732] Watching file:/tmp/bro/dns.log from position: 12106
2017-01-12T12:34:12.604Z pid[26732] Watching file:/tmp/bro/files.log from position: 24284
2017-01-12T12:34:12.604Z pid[26732] Watching file:/tmp/bro/http.log from position: 10745
2017-01-12T12:34:12.605Z pid[26732] Watching file:/tmp/bro/packet_filter.log from position: 89
2017-01-12T12:34:12.605Z pid[26732] Watching file:/tmp/bro/reporter.log from position: 556
2017-01-12T12:34:12.605Z pid[26732] Watching file:/tmp/bro/ssl.log from position: 26345
2017-01-12T12:34:12.605Z pid[26732] Watching file:/tmp/bro/weird.log from position: 5299
2017-01-12T12:34:12.606Z pid[26732] Watching file:/tmp/bro/x509.log from position: 35791
ts: 1484222526.821381
uid: ChYffm3LeTFNXIvVBg
id.orig_p: 2185
id.resp_p: 59096
proto: tcp
duration: 0.110198
orig_bytes: 0
resp_bytes: 0
conn_state: OTH
missed_bytes: 0
history: HA
orig_pkts: 2
orig_ip_bytes: 112
resp_pkts: 0
resp_ip_bytes: 0
 (empty array)
@timestamp: Thu Jan 12 2017 13:02:06 GMT+0100 (CET)
_type: conn
logSource: /tmp/bro/conn.log

For permanent network monitoring, use the Logagent Linux (or Mac OS X) service:

sudo cp bro-ids.yml /etc/sematext/logagent.conf
sudo service logagent start

After a minute we should see Bro logs indexed in Logsene. Now we can easily search all data provided by Bro or use Kibana to create charts that provide insights about our network activity.

Kibana Dashboard in Logsene

Got other, better,  or more interesting Kibana dashboards and charts?  Ping @sematext or leave a comment, we’d love to see them!

Start Free Trial