CoCoineticBack to coinetic.io

Event ID 5157: the Windows Filtering Platform has blocked a connection

Event 5157 is the Windows Firewall telling you it blocked a connection: which program, which direction, from which address to which port. It is the most direct record of what knocks on a Server or PC – and of programs that tried to go out and were stopped. It is not on by default, and switching it on the wrong way floods the log.

In short
  • What it is: a connection blocked by the Windows Filtering Platform (the engine behind the Windows Firewall).
  • Switch it on: audit subcategory Filtering Platform Connection – Failure only. Success would log every allowed connection (5156).
  • Key fields: Direction (inbound / outbound), Application, Source and Destination Address and Port, Protocol.
  • Its sibling: 5152 (a packet dropped) comes from Filtering Platform Packet Drop and is even noisier.

1. Switch it on (without flooding the log)

As administrator:

auditpol /set /subcategory:"{0CCE9226-69AE-11D9-BED3-505054503030}" /success:disable /failure:enable

The GUID is Filtering Platform Connection – using it instead of the name works on every Windows language. In Group Policy: Computer Configuration › Policies › Windows Settings › Security Settings › Advanced Audit Policy Configuration › Object Access › Audit Filtering Platform Connection = Failure.

Do not tick Success: that writes Event 5156 for every allowed connection – thousands per minute on a busy Server. And make the Security log big enough (several hundred MB on a Server exposed to the internet): blocked connections from internet scanners add up.

2. The fields

FieldMeaning
Application NameThe program, as a device path (\device\harddiskvolume3\...). System for connections to Windows itself (e.g. SMB on 445).
DirectionInbound = someone tried to reach this computer; Outbound = a program on this computer tried to go out.
Source Address / PortWhere the connection came from (inbound: the other side).
Destination Address / PortWhere it was going (inbound: this computer and the port that was knocked on).
Protocol6 = TCP, 17 = UDP, 1 = ICMP.
Filter Run-Time ID / LayerWhich firewall filter blocked it. Default-block shows no named rule; a block rule you created can be found with netsh wfp show filters.

3. PowerShell: who knocks, on which ports

As administrator; fields are read by name. The Direction value is a code: %%14592 = inbound, %%14593 = outbound.

function Get-EventFields($e) { $d = [ordered]@{}; ([xml]$e.ToXml()).Event.EventData.Data | ForEach-Object { $d[$_.Name] = $_.'#text' }; [pscustomobject]$d }
$blocked = Get-WinEvent -FilterHashtable @{LogName='Security'; Id=5157; StartTime=(Get-Date).AddHours(-1)} -ErrorAction SilentlyContinue |
  ForEach-Object { Get-EventFields $_ }
# inbound: the most blocked addresses and the ports they tried
$blocked | Where-Object Direction -eq '%%14592' | Group-Object SourceAddress |
  Sort-Object Count -Descending | Select-Object -First 15 Count, Name, @{n='Ports';e={($_.Group.DestPort | Sort-Object -Unique) -join ','}}
# outbound: programs that tried to go out and were stopped
$blocked | Where-Object Direction -eq '%%14593' | Group-Object Application | Sort-Object Count -Descending | Select-Object Count, Name

4. How to read what you see

5. Let Coinetic watch it for you

Coinetic reads these blocked connections for you, all the time:

Protect this Server or PC in 5 minutes

Download Coinetic, install, done: it starts protecting at once. 30 days free with all features, no payment details. From $20 per computer per year.

Start the free 30-day trial →

More guides: all Coinetic guides.

Frequently asked

Why do I not see any Event 5157?

It is off by default. Switch on the audit subcategory Filtering Platform Connection for Failure (see above). The Windows Firewall log file (pfirewall.log) is a separate setting and does not create these events.

What is the difference between 5157 and 5152?

5157 is a blocked connection (Filtering Platform Connection), 5152 a dropped packet (Filtering Platform Packet Drop). 5152 is much noisier; for most purposes 5157 is enough.

Does 5157 mean I am under attack?

Usually not. Every computer reachable from the internet is scanned all day; 5157 shows the firewall doing its job. Look for one address trying many ports, or for outbound blocks from unknown programs.

Why is the Application Name a \device\harddiskvolume path?

The Filtering Platform works below drive letters. Map the volume to a drive letter with the mountvol command or Get-Partition | Select DriveLetter, AccessPaths, or simply look at the file name at the end of the path.