Windows firewall logging with ELK and Logstash

More than often I run into customers who have this situation where they cannot or do not have visibility within a network, by a network in this context I am referring to a layer two domain or a Vlan. Having visibility at layer 3 is no problem as most of at least my customers have some sort of SELM solution combined with firewall logs that show the traffic passing through the firewall. However, when it comes down to layer 2(in terms of arping through the network and not using gateway) it becomes a bit tricky as you really only have two options. I guess you have more than two as well but the most common ones are Ipfix and Netflow data. To achieve this sort of visibility you network equipment and infrastructure must support these features at the distribution layer. I am aware that that you normally would be interested in traffic being generated by a server, but in some scenarios you might also be interested in traffic from clients. These clients can be you Windows 10 machines, Linux or even MACs. Luckily most of the operating systems support quite comprehensive logging at OS level, logging each packet being sent to the network or being received by the network. This flexibility provides immense help in situations where you are performing troubleshooting for a complex problem with limited visibility into network traffic.

Elastic search or rightly described ELK stack includes the beats module which supports almost all the popular OSes. You just need to install the beats client on your OS and then you can leverage the different modules to ship your logs to you ELK solution. You have the option to directly send to Elastic Search or send data through Logstash. I have always utilized the Logstash channel for processing and enrichment of data. Image below shows Windows firewall log data in Kibana. The data is being read from Windows Firewall logs and is being shipped in real time. The image below shows all the hosts this server has communicated with during the last 24 hours. Rightly so it does also include data about layer 2(data within same subnet using arp) and layer 3 connections, but its here where Logstash comes into the picture and where you can create a Logstash filter to exclude logging data already being gathered by the firewalls.

windows firewall - logs in ELK
windows firewall – logs in ELK

To give you a better idea of how useful this data can be, we can use one of my favorite Kibana visualizations i.e. the pie diagrams.

Windows firewall - logs with ELK in Kibana
Windows firewall – logs with ELK in Kibana

The great feature becomes apparent when you exclude traffic that you are not interested in and then hover over the pie diagrams. When you do this the destination server address and port address becomes highlighted, which makes it very easy to see and work with. As you can see, I have chosen to exclude port 53 (dns traffic), and ports 135-138 (Windows netbios ports) and port 123 (ntp traffic) as I am not interested in this type of traffic within the vlan. As ELK beats supports not only forwarding of log files but also security log files, only the imagination sets your boundaries. In this blog post we will first enable Windows firewall logging, thereafter we will configure Filebeats to forward logs data to Logstash. And finally configure Logstash to filter and enrich the data before submitting it to Elastic search. Let us start with the process of enabling firewall logging on a Windows host.

Windows firewall logging

This can be set up either per machine or for a group of machines using the group policy management console. I am quickly going through the steps to set it up for machines using group policy. Create a new group policy in group policy management console and navigate to Computer Configuration\Security settings\Windows Firewall with Advanced Security

Windows firewall - group policy management console
Windows firewall – group policy management console

Right click and choose properties

Windows Firewall with advanced security
Windows Firewall with advanced security

Configure the setting according to your needs i.e. allow or deny in and outbound traffic. After that has been done choose the customize button under logging

Windows firewall - group policy management console 3
Windows firewall – group policy management console 3

Under the logging setting specify a name if you want to keep the defaults. For log size define a size, i think the log size has a maximum limit of 32 MB or something near that limit.

Windows firewall - group policy management console 4
Windows firewall – group policy management console 4

Important thing here is to set yes on either or both of “Log dropped packets” and/or “Log successful connections”. You can go through the setting for private network profile firewall settings and for public. For our purpose which is to configure firewall logging on, it does not matter if you log to 3 different files or just to a single file as we are going to gather the logs by filebeats anyway. After a successful configuration of group policy and next GPO refresh cycle you would be able to see following files (or something similar) depending on your configuration.

Windows firewall - log files folder
Windows firewall – log files folder

Pfirewall is the file currently being written to this is reflected in the timestamp. Now we er done configuring the firewall part. Now we can install and configure filebeat.

Windows firewall logging with ELK and Logstash

This first thing is to install filebeats on the server where you want to gather and forward Windows firewall log files. It is a pretty straight forward process and thoroughly documented by Elastic. You can find the guide along with installations file here

After you have installed Filebeats you must configure filebeat.yml file. I have only configured the minimum sections required for the solution to work. The complete contents of the files are as

###################### Filebeat Configuration Example #########################

# This file is an example configuration file highlighting only the most common
# options. The filebeat.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
# You can find the full configuration reference here:

# For more available modules and options, please see the filebeat.reference.yml sample
# configuration file.

# ============================== Filebeat inputs ===============================


# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.

- type: log

  # Change to true to enable this input configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
    #- /var/log/*.log
    - c:\Windows\System32\LogFiles\Firewall\*.log

  # Exclude lines. A list of regular expressions to match. It drops the lines that are
  # matching any regular expression from the list.
  exclude_lines: ['^#']

  # Include lines. A list of regular expressions to match. It exports the lines that are
  # matching any regular expression from the list.
  #include_lines: ['^ERR', '^WARN']
  #include_lines: ['^0-9']

  # Exclude files. A list of regular expressions to match. Filebeat drops the files that
  # are matching any regular expression from the list. By default, no files are dropped.
  #exclude_files: ['.gz$']

  # Optional additional fields. These fields can be freely picked
  # to add additional information to the crawled log files for filtering
  #  level: debug
  #  review: 1

  ### Multiline options

  # Multiline can be used for log messages spanning multiple lines. This is common
  # for Java Stack Traces or C-Line Continuation

  # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
  #multiline.pattern: ^\[

  # Defines if the pattern set under pattern should be negated or not. Default is false.
  #multiline.negate: false

  # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern
  # that was (not) matched before or after or as long as a pattern is not matched based on negate.
  # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash
  #multiline.match: after

# ============================== Filebeat modules ==============================

  # Glob pattern for configuration loading
  path: ${path.config}/modules.d/*.yml

  # Set to true to enable config reloading
  reload.enabled: false

  # Period on which files under path should be checked for changes
  #reload.period: 10s

# ======================= Elasticsearch template setting =======================

  index.number_of_shards: 1
  #index.codec: best_compression
  #_source.enabled: false

# ================================== General ===================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.

# The tags of the shipper are included in their own field with each
# transaction published.
#tags: ["service-X", "web-tier"]
tags: ["windowsfirewall"]
# Optional fields that you can specify to add additional information to the
# output.
#  env: staging
  #firewall: windowsfirewall
  OSIlayer: 2

# ================================= Dashboards =================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here or by using the `setup` command.
#setup.dashboards.enabled: false

# The URL from where to download the dashboards archive. By default this URL
# has a value which is computed based on the Beat name and version. For released
# versions, this URL points to the dashboard archive on the
# website.

# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.

  # Kibana Host
  # Scheme and port can be left out and will be set to the default (http and 5601)
  # In case you specify and additional path, the scheme is required: http://localhost:5601/path
  # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
  #host: "localhost:5601"

  # Kibana Space ID
  # ID of the Kibana Space into which the dashboards should be loaded. By default,
  # the Default Space will be used.

# =============================== Elastic Cloud ================================

# These settings simplify using Filebeat with the Elastic Cloud (

# The setting overwrites the `output.elasticsearch.hosts` and
# `` options.
# You can find the `` in the Elastic Cloud web UI.

# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.

# ================================== Outputs ===================================

# Configure what output to use when sending the data collected by the beat.

# ---------------------------- Elasticsearch Output ----------------------------
  # Array of hosts to connect to.
  #hosts: [""]

  # Protocol - either `http` (default) or `https`.
  #protocol: "https"

  # Authentication credentials - either API key or username/password.
  #api_key: "id:api_key"
  #username: "elastic"
  #password: "changeme"

# ------------------------------ Logstash Output -------------------------------
  # The Logstash hosts
  hosts: [""]

  # Optional SSL. By default is off.
  # List of root certificates for HTTPS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

  # Certificate for SSL client authentication
  #ssl.certificate: "/etc/pki/client/cert.pem"

  # Client Certificate Key
  #ssl.key: "/etc/pki/client/cert.key"

# ================================= Processors =================================

# Configure processors to enhance or manipulate events generated by the beat.

##  - add_host_metadata: ~
##  - add_cloud_metadata: ~
##  - add_docker_metadata: ~
## - add_kubernetes_metadata: ~

# ================================== Logging ===================================

# Sets log level. The default log level is info.
# Available log levels are: error, warning, info, debug
#logging.level: debug
logging.level: info
# At debug level, you can selectively enable logging only for some components.
# To enable all selectors use ["*"]. Examples of other selectors are "beat",
# "publish", "service".
#logging.selectors: ["*"]

# ============================= X-Pack Monitoring ==============================
# Filebeat can export internal metrics to a central Elasticsearch monitoring
# cluster.  This requires xpack monitoring to be enabled in Elasticsearch.  The
# reporting is disabled by default.

# Set to true to enable the monitoring reporter.
#monitoring.enabled: false

# Sets the UUID of the Elasticsearch cluster under which monitoring data for this
# Filebeat instance will appear in the Stack Monitoring UI. If output.elasticsearch
# is enabled, the UUID is derived from the Elasticsearch cluster referenced by output.elasticsearch.

# Uncomment to send the metrics to Elasticsearch. Most settings from the
# Elasticsearch output are accepted here as well.
# Note that the settings should point to your Elasticsearch *monitoring* cluster.
# Any setting that is not set is automatically inherited from the Elasticsearch
# output configuration, so if you have the Elasticsearch output configured such
# that it is pointing to your Elasticsearch monitoring cluster, you can simply
# uncomment the following line.

# ================================= Migration ==================================

# This allows to enable 6.7 migration aliases
#migration.6_to_7.enabled: true

As you can see, all the logfiles under default Windows firewall path c:\Windows\System32\LogFiles\Firewall*.log are being gathered and forwarded to Logstash. Furthermore, lines starting with # are being skipped, as the Windows Firewall log always starts with a description of its contents.

Windows firewall - log files contents
Windows firewall – log files contents

We do not want to send these files to Logstash, hence any line starting with # are being skipped. The rest of the lines are being sent forward. I am also adding a OsiLayer field with value 2. The next step in the configuration is to create a Logstash filter to process Windows firewall log files.

input {
  beats {
    port => 5044

filter {

grok {
        match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{WORD:action} %{WORD:protocol} %{IP:src_IP} %{IP:dst_ip} %{INT:src_port} %{INT:dst_port}" }
        remove_field => [ "message" ]
        #add_field => { "ISOlayer" => "2" }

#Filter ends above!

output {
if "windowsfirewall" in [tags] {

elasticsearch {
    hosts => [ "" ]
    index => "beats-%{+YYYY.MM.dd}"



As you can see, fields can also be added here in Logstash filter if you rather prefer that. You can perform an IP lookup or matching if you so wish, but as you primarily are interested only in intra Vlan traffic you can safely drop log entries to or from public IP addresses. Happy log gathering with filebeats and Logstash. If you have any comments or questions feel free to post them in the comments section below and also feel free to share the blog post so that other needing guidance can make use of the wonderful tool called Elastic Search.

Leave a Reply

Your email address will not be published. Required fields are marked *