This document explains how to monitor Windows firewall and network activity on local system.
Note: all of these programs must be run as Administrator:
[capture=yes | no](#captureyesno) |
[persistent=yes | no](#persistentyesno) |
[fileMode=single | circular | append](#filemodesinglecircularappend) |
[overwrite=yes | no](#overwriteyesno) |
As you might already know, Windows firewall does not give us any easy to use tools to monitor
what the firewall is doing.
However there are few programs and techniques available to monitor firewall activity in live.
Note that there isn’t an “All in one” solution, an ultimate program that does all the job. instead we have to deal with multiple tools, each specialized for certain purpose, if you’re serious you will need them all.
Some tools are easy to use, some require learning how to use them, some have graphical interface
some are command line programs.
Some tools do the same job as other tools but complement missing features of other programs,
while having other drawbacks.
For each program listed here you have a reference link (for tools built into Windows) and download link (for external programs).
All of the tools listed here are digitally signed, the only exceptions are as follows:
mTail, to mark mTail as trusted you can verify it’s behavior with process monitor or check it’s user base online.
An alternative for mTail (described later) is a combination of VSCode extensions and predefined extension settings.
Config\procmon
directory you will find process monitor configuration specialized
for firewall monitoring which you can import into your copy of process monitor.Config\mTail
directory in repository,
the config file is named mtail_CC.ini
,
just place it next to mTail executable, restart mTail and open firewall log,
which is by default placed into C:\Windows\System32\LogFiles\Firewall\pfirewall.log\
However Complete-Firewall.ps1
script will instruct firewall to write separate logs for each
firewall profile.mtail.ini
which first need to be edited to update hardcoded
paths and then (re)placed into: C:\Users\ADMINUSERNAME\Roaming\mtail\
,
this config file contains configuration to monitor firewall activity for individual firewall
profiles as well as number of personalized settings.FirewallLogsFolder
in Config\ProjectSettings.ps1
to value $LogsFolder\Firewall
DefaultUser
points to your account username in Config\ProjectSettings.ps1
Scripts\Complete-Firewall.ps1
and reboot systemLogs\Firewall
directory in repository, but before doing this ensure specified location asScripts\Grant-Logs.ps1 YOUR_USERNAME
Logs\Firewall
nodeCTRL + SHIFT + P
, type “Filter line by Config File”
and press enter.FILENAME.filterline.log
.vscode\filterline.json
and supports regex to fine tune your filter.docs\Regex.md
Yet another standard and quick way to monitor logs is with PowerShell commands, ex:
Get-Content "%SystemRoot%\System32\LogFiles\Firewall\pfirewall.log" -Last 10 -Wait | Select-String "DROP"
secpol.msc
, right click and “Run as Administrator”To open Event viewer to monitor configured packet filtering events follow steps below:
compmgmt.msc
, right click and “Run as Administrator”Are you unable to figure out why your rules don’t work and why packets are dropped?
If so here is another powerful tool which will let you gather more information about specific
firewall event.
click on image to enlarge:
netsh wfp show state
to show current state, such as detailed information about dropped or
allowed network packets.
netsh wfp show filters
to show current firewall filters
(filters define firewall rules, rules by themself are just high level representation)wfpstate.xml
file, then press CTRL + F to open “find box” and CTRL + V to paste
the number, and hit enter to jump to this event.<item></item>
node<displayData></displayData>
node which will tell what
caused the drop, this will be the name of a firewall rule or default firewall action such as default
action or boot time filter.<layerKey></layerKey>
key will tell you which WFP filter caused the drop, for example the
value FWPM_LAYER_ALE_AUTH_CONNECT_V4
means IPv4 authorizing connect requests for outgoing connection,
based on the first packet sent. Which btw. tells us there was no adequate allow rule so the
default outbound action was hit.For detailed information on how to interpret WFP log see “Firewall” section in docs\Reference.md
And of course we have Windows firewall.
Monitoring: (control panel firewall, Active store)
Management (Local group policy, GPO store)
To open GPO firewall follow steps below:
secpol.msc
secpol.msc
and click Run as administrator
Windows Defender Firewall with Advanced Security
Windows Defender Firewall with Advanced Security - Local Group Policy Object
Inbound
, Outbound
or Windows Defender Firewall...
nodeWhen you open GPO firewall first thing you should do is add columns that are by default not visible and remove those which are useless and only waste space, for example add:
Inside Config\System
there is a Firewall.msc
settings file, which saves you from doing these
things every time you open GPO firewall, you can customize it and re-save your preferences.
TCP view is another tool that wil let you see which programs are listening on which ports on local system
A few useful commands are as follows:
Show all TCP connections and executables involved
netstat -obnq -p tcp
Show ICMP statistics:
netstat -s -p icmp
In some special scenarios you might want to have much more power than what you have with firewall logs.
For example if you want to see ICMP traffic one way is to set firewall to log both allowed and
dropped packets and then filter logs as needed, (ex. with filterline
extension)
Other times you might want to analyse firewall or network performance.
To handle these and similar scenarios there is network capture and tracing solution.
To view and analyse an *.etl
file you’ll need to install “Windows Performance Analyzer” which
is availabe as an optional installment of Windows 10 SDK or Windows ADK
Once you install it and open ETL (Event Trace Log) file here is sample traffic analysis screenshot:
To generate an ETL file use “Windows Performance Recorder” which is part of same package in either Windows SDK or Windows ADK.
Other two (less useful) methods are described in two sections that follow in this guide.
netsh trace
option is similar to capturing “WFP state” and “Packet analysis” discused before.
There is no benefit to use this legacy program.
Here are few examples for netsh trace start
Capture UDP traffic where source or destination IP matches IPv4.Address
value
netsh trace start capture=yes Ethernet.Type=IPv4 IPv4.Address=192.168.33.33 protocol=17 tracefile=c:\temp\trace.etl
Capture only ICMPv6 traffic
netsh trace start capture=yes protocol=58 tracefile=c:\temp\trace.etl
Capture all network traffic on a specific Network Interface and stop when capture file grows to 300 MB
netsh trace start capture=yes tracefile=c:\temp\trace.etl CaptureInterface="Ethernet interface" maxSize=300
To view status after running netsh trace
run:
netsh trace show status
To stop tracing run:
netsh trace stop
For more information run:
netsh trace show capturefilterHelp
The meaning of options is as follows:
Specifies whether packet capturing is enabled in addition to tracing events.
The default is no
Specifies IP protocol for which to trace or capture traffic.
For valid values and their meaning see: Assigned Internet Protocol Numbers
Specifies the location and file name where to save the output.
The default is: %LOCALAPPDATA%\Temp\NetTraces\NetTrace.etl
Specifies whether the tracing session resumes upon restarting the computer.
The default is no
Specifies which file mode is applied when tracing output is generated.
The meaning of options (probably) is as follows:
single
Overwrite existing file and fill it with up to maxSize
valuecircular
Discard older entries to make space for new ones once maxSize
is reachedappend
Append to file up to maxSize
valueThe default is circular
Specifies maximum log file size in MB (Mega Bytes).\
To specify the maxSize=0, you must also specify filemode=single
If the value is set to 0, then there is no maximum.`
The default value is 250.
Specifies whether an existing trace output file will be overwritten.
If parameter traceFile is not specified, then the default location and filename and any pre-existing version of the trace file is automatically overwritten.
NetEventPacketCapture is a PowerShell module that is a replacement for netsh trace
Almost everything netsh trace
can do can be also done with NetEventPacketCapture module.
Inside Scripts\Experiment
directory there are experimental Start-PacketTrace.ps1
and Stop-PacketTrace.ps1
scripts which make use of NetEventPacketCapture
module, you can use them to quickly start and stop
packet capture.
Keep in mind that both the netsh trace
and NetEventPacketCapture
generate an ETL file
(Event Trace Log), problem in both cases is the lack of executable involved in traffic.
This problem can be solved with “Windows Performance Recorder” which generates required symbols.