Welcome!

Blog Feed Post

Network Security: Analyze & Search Bro IDS Logs with 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.

Source: www.bro-ids.org

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 192.168.1.20 62663 212.47.225.70 443 tcp - - - - OTH - - 0 d 0 0 1 494 (empty)
1484222975.423814 CDpOCg4wzHbeAbQn4 192.168.1.20 49904 148.62.3.119 443 tcp - 0.000002 0 976 OTH - - 0 d 0 0 2 1080 (empty)
1484222974.911667 C75yx91lD2bArc9CKj 192.168.1.20 56717 192.30.253.124 443 tcp - - - - OTH - - 0 a 0 0 1 52 (empty)
1484222974.852917 CQISpU3YnsqbRkLAf5 192.168.1.20 56911 192.30.253.124 443 tcp - - - - OTH - - 0 a 0 0 1 52 (empty)
1484222976.235060 Cdl9TTqFYx2fdG7Gi 192.168.1.20 51730 62.210.117.148 443 tcp - 0.097194 0 4330 OTH - - 0 ad 0 0 4 4538 (empty)
1484222975.149426 Cgw13b4NHZwoK73N41 192.168.1.20 49699 52.51.142.18 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
{"ts":1484223222.732681,"uid":"Ck1oOc4AkxwRQIhe02","id.orig_h":"192.168.1.20","id.orig_p":49195,"id.resp_h":"66.216.68.35","id.resp_p":443,"proto":"tcp","duration":0.47905,"orig_bytes":0,"resp_bytes":4636,"conn_state":"OTH","missed_bytes":0,"history":"had","orig_pkts":0,"orig_ip_bytes":0,"resp_pkts":8,"resp_ip_bytes":5060,"tunnel_parents":[]}
{"ts":1484223223.436714,"uid":"CVVNxv3HfxowhGv4fb","id.orig_h":"52.22.52.138","id.orig_p":2184,"id.resp_h":"192.168.1.20","id.resp_p":65531,"proto":"tcp","conn_state":"SH","missed_bytes":0,"history":"F","orig_pkts":1,"orig_ip_bytes":52,"resp_pkts":0,"resp_ip_bytes":0,"tunnel_parents":[]}
{"ts":1484223225.144888,"uid":"CeAYWLh7tFYcbLfCi","id.orig_h":"192.168.1.20","id.orig_p":49699,"id.resp_h":"52.51.142.18","id.resp_p":443,"proto":"tcp","duration":0.081048,"orig_bytes":0,"resp_bytes":62,"conn_state":"OTH","missed_bytes":0,"history":"ad","orig_pkts":0,"orig_ip_bytes":0,"resp_pkts":2,"resp_ip_bytes":166,"tunnel_parents":[]}
{"ts":1484223222.117376,"uid":"CyPA2L31a9zA8qpVt5","id.orig_h":"192.168.1.20","id.orig_p":65387,"id.resp_h":"107.20.222.136","id.resp_p":443,"proto":"tcp","duration":0.00009,"orig_bytes":0,"resp_bytes":0,"conn_state":"SHR","missed_bytes":0,"history":"af","orig_pkts":0,"orig_ip_bytes":0,"resp_pkts":3,"resp_ip_bytes":168,"tunnel_parents":[]}

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 https://deb.nodesource.com/setup_7.x | 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:

input:
  bro-start: 
    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 ...
  files:
      - '/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:

parser:
  json: 
    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:

output:
  stdout: yaml
  es-secure-local:
    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:

output:
  stdout: yaml
  es-secure-local:
    module: elasticsearch 
    url: https://logsene-receiver.sematext.com
    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
Password:
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_h: 52.22.52.138
id.orig_p: 2185
id.resp_h: 192.168.1.20
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
tunnel_parents: 
 (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.

https://sematext.com/wp-content/uploads/2017/02/image02-300x180.png 300w, https://sematext.com/wp-content/uploads/2017/02/image02-768x461.png 768w, https://sematext.com/wp-content/uploads/2017/02/image02-1024x615.png 1024w" sizes="(max-width: 1999px) 100vw, 1999px" />
https://sematext.com/wp-content/uploads/2017/02/image01-300x143.png 300w, https://sematext.com/wp-content/uploads/2017/02/image01-768x367.png 768w, https://sematext.com/wp-content/uploads/2017/02/image01-1024x489.png 1024w" sizes="(max-width: 1999px) 100vw, 1999px" />

https://sematext.com/wp-content/uploads/2017/02/image00-300x188.png 300w, https://sematext.com/wp-content/uploads/2017/02/image00-768x480.png 768w, https://sematext.com/wp-content/uploads/2017/02/image00-1024x640.png 1024w" sizes="(max-width: 1280px) 100vw, 1280px" />

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!


Read the original blog entry...

More Stories By Sematext Blog

Sematext is a globally distributed organization that builds innovative Cloud and On Premises solutions for performance monitoring, alerting and anomaly detection (SPM), log management and analytics (Logsene), and search analytics (SSA). We also provide Search and Big Data consulting services and offer 24/7 production support for Solr and Elasticsearch.

Latest Stories
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
As you move to the cloud, your network should be efficient, secure, and easy to manage. An enterprise adopting a hybrid or public cloud needs systems and tools that provide: Agility: ability to deliver applications and services faster, even in complex hybrid environments Easier manageability: enable reliable connectivity with complete oversight as the data center network evolves Greater efficiency: eliminate wasted effort while reducing errors and optimize asset utilization Security: imple...
Mobile device usage has increased exponentially during the past several years, as consumers rely on handhelds for everything from news and weather to banking and purchases. What can we expect in the next few years? The way in which we interact with our devices will fundamentally change, as businesses leverage Artificial Intelligence. We already see this taking shape as businesses leverage AI for cost savings and customer responsiveness. This trend will continue, as AI is used for more sophistica...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Companies are harnessing data in ways we once associated with science fiction. Analysts have access to a plethora of visualization and reporting tools, but considering the vast amount of data businesses collect and limitations of CPUs, end users are forced to design their structures and systems with limitations. Until now. As the cloud toolkit to analyze data has evolved, GPUs have stepped in to massively parallel SQL, visualization and machine learning.
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
Modern software design has fundamentally changed how we manage applications, causing many to turn to containers as the new virtual machine for resource management. As container adoption grows beyond stateless applications to stateful workloads, the need for persistent storage is foundational - something customers routinely cite as a top pain point. In his session at @DevOpsSummit at 21st Cloud Expo, Bill Borsari, Head of Systems Engineering at Datera, explored how organizations can reap the bene...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
Kubernetes is an open source system for automating deployment, scaling, and management of containerized applications. Kubernetes was originally built by Google, leveraging years of experience with managing container workloads, and is now a Cloud Native Compute Foundation (CNCF) project. Kubernetes has been widely adopted by the community, supported on all major public and private cloud providers, and is gaining rapid adoption in enterprises. However, Kubernetes may seem intimidating and complex ...
In his session at 21st Cloud Expo, Michael Burley, a Senior Business Development Executive in IT Services at NetApp, described how NetApp designed a three-year program of work to migrate 25PB of a major telco's enterprise data to a new STaaS platform, and then secured a long-term contract to manage and operate the platform. This significant program blended the best of NetApp’s solutions and services capabilities to enable this telco’s successful adoption of private cloud storage and launching ...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
In his general session at 21st Cloud Expo, Greg Dumas, Calligo’s Vice President and G.M. of US operations, discussed the new Global Data Protection Regulation and how Calligo can help business stay compliant in digitally globalized world. Greg Dumas is Calligo's Vice President and G.M. of US operations. Calligo is an established service provider that provides an innovative platform for trusted cloud solutions. Calligo’s customers are typically most concerned about GDPR compliance, application p...
Digital transformation is about embracing digital technologies into a company's culture to better connect with its customers, automate processes, create better tools, enter new markets, etc. Such a transformation requires continuous orchestration across teams and an environment based on open collaboration and daily experiments. In his session at 21st Cloud Expo, Alex Casalboni, Technical (Cloud) Evangelist at Cloud Academy, explored and discussed the most urgent unsolved challenges to achieve f...
You know you need the cloud, but you’re hesitant to simply dump everything at Amazon since you know that not all workloads are suitable for cloud. You know that you want the kind of ease of use and scalability that you get with public cloud, but your applications are architected in a way that makes the public cloud a non-starter. You’re looking at private cloud solutions based on hyperconverged infrastructure, but you’re concerned with the limits inherent in those technologies.