Event ID 4946
Event ID 4946: Firewall Rule Added
A change was made to the Windows Firewall exception list. A rule was added
- Log source
- Security
- How to enable it
- Policy Change > Audit MPSSVC Rule-Level Policy Change (Success)
- Category
- Defense Evasion
- Priority
- Medium
- Typical volume
- Medium
- MITRE ATT&CK
What Event ID 4946 means
4946 is written when a rule is added to Windows Defender Firewall. It announces that the host's exposure has changed, but it is sparse: it gives a profile, an identifier and a name, with no port, program or account.
The name is chosen by whoever adds the rule, so it can say anything. Look up RuleId in the registry or with Get-NetFirewallRule on the live host to learn what the rule really allows. If the host is gone, the Firewall operational log (event 2004, or 2097 on newer versions) holds the full definition including the program that made the change.
Applications add rules for themselves all the time, above all browsers, games and meeting software. Rules that arrive outside an installation, or that concern remote administration, are the ones to examine.
Key fields to inspect
| Field | Meaning | Suspicious when |
|---|---|---|
RuleName | Display name of the rule. | Names like RDP, test, Open Port 4444, or a vendor that is not installed. |
RuleId | Unique identifier of the rule. | Use it to fetch the real definition. |
ProfileChanged | Profiles affected: All, Domain, Private or Public. | All or Public on a server. |
Computer | Host whose rules changed, from the event header. | A server with a fixed role, where new rules are not expected. |
Detection queries
Find new rules whose names mention remote access or that appear on only a few hosts. Adjust names and thresholds to your environment. About these queries.
Splunk SPL
index=windows source="XmlWinEventLog:Security" EventCode=4946
| stats dc(Computer) AS hosts earliest(_time) AS first values(ProfileChanged) AS profiles values(Computer) AS computers BY RuleName
| where hosts<=2 OR match(RuleName, "(?i)rdp|remote desktop|winrm|psexec|ssh|vnc|port") Microsoft Sentinel KQL
SecurityEvent
| where EventID == 4946
| extend RuleName = extract(@'Name="RuleName">([^<]*)<', 1, EventData)
| extend RuleId = extract(@'Name="RuleId">([^<]*)<', 1, EventData)
| extend ProfileChanged = extract(@'Name="ProfileChanged">([^<]*)<', 1, EventData)
| summarize Hosts = dcount(Computer), First = min(TimeGenerated), Computers = make_set(Computer, 10), Profiles = make_set(ProfileChanged) by RuleName
| where Hosts <= 2 or RuleName matches regex @"(?i)rdp|remote desktop|winrm|psexec|ssh|vnc|port" PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4946; StartTime = (Get-Date).AddDays(-7) } |
ForEach-Object { $d = @{ Time = $_.TimeCreated }; ([xml]$_.ToXml()).Event.EventData.Data | ForEach-Object { $d[$_.Name] = $_.'#text' }; [pscustomobject]$d } |
Select-Object Time, RuleName, RuleId, ProfileChanged | Format-Table -AutoSize Attack scenarios
Opening Remote Desktop
netsh advfirewall firewall add rule for TCP 3389 prepares interactive access. It is usually accompanied by enabling Remote Desktop in the registry and by adding an account to Remote Desktop Users (4732).
Exposing a tunnel or listener
A rule for a high port and an unusual program lets a reverse proxy or bind shell receive connections. The program path in the full definition is the useful part.
Blocking a security agent
An outbound block rule for the program of an EDR cuts it off from its console, while the agent still runs and looks healthy on the host. Tools built for this purpose use the same firewall platform.
Investigation checklist
- Fetch the rule with Get-NetFirewallRule -Name and its RuleId, with port and application filters.
- Read event 2004 or 2097 in the Firewall operational log for the program that made the change.
- Find netsh.exe or New-NetFirewallRule in 4688 and 4104 at that time.
- Remove the rule, and check whether connections (5156) already used it.
Common benign causes
- Browsers, games and meeting software that register themselves.
- Windows features, which add a group of rules when they are enabled.
- Virtualization and container software.
Event ID 4946 FAQ
Does event 4946 show which port was opened?
No. It contains only the rule's name, identifier and profile. Look up the identifier on the host, or use event 2004 or 2097 in the Windows Firewall With Advanced Security log for the full definition.
Does event 4946 show who added the rule?
No. There is no subject. Correlate with process creation for netsh.exe or PowerShell, and with the Firewall operational log, which records the user and the program.
Are rules from Group Policy logged as 4946?
Rules that arrive through Group Policy are kept in a separate store and are reported by other events, such as 4945 and 4954. 4946 mainly concerns local rules.