Skip to content

Commit 90ef675

Browse files
DCFW version 1.3
1 parent e447132 commit 90ef675

File tree

8 files changed

+183
-30
lines changed

8 files changed

+183
-30
lines changed

.github/workflows/generate-whitepaper.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
- Generators/pandoc/*
88
- '.github/workflows/generate-whitepaper.yml'
99

10+
env:
11+
pdf_file_name: Domain_Controller_Firewall_${{ github.ref_name }}.pdf
12+
1013
jobs:
1114
generate:
1215
name: Generate
@@ -24,7 +27,7 @@ jobs:
2427
uses: docker://pandoc/extra:3.6.0
2528
with:
2629
args: >-
27-
--output=Domain_Controller_Firewall.pdf
30+
--output="${{ env.pdf_file_name }}"
2831
--pdf-engine=xelatex
2932
--template=eisvogel
3033
--resource-path="ADDS:/.pandoc/templates"
@@ -44,5 +47,5 @@ jobs:
4447
uses: actions/upload-artifact@v4
4548
with:
4649
name: Whitepaper
47-
path: Domain_Controller_Firewall.pdf
50+
path: ${{ env.pdf_file_name }}
4851
if-no-files-found: error

.github/workflows/sign-scripts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ jobs:
5252
- name: Upload PowerShell scripts as Artifact
5353
uses: actions/upload-artifact@v4
5454
with:
55-
name: DCFWTool
55+
name: DCFWTool_${{ github.ref_name }}
5656
path: ADDS/DCFWTool

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"mechatroner.rainbow-csv",
1010
"GrapeCity.gc-excelviewer",
1111
"GitHub.copilot",
12-
"GitHub.copilot-chat"
12+
"GitHub.copilot-chat",
13+
"PKief.material-icon-theme"
1314
]
1415
}

ADDS/DCFWTool/CustomRules.Sample.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ List of client IP adresses from which inbound traffic should be allowed. This li
2020
2121
.NOTES
2222
Author: Michael Grafnetter
23-
Version: 2.6
23+
Version: 2.8
2424
2525
#>
2626

@@ -67,4 +67,19 @@ New-NetFirewallRule -GPOSession $GPOSession `
6767
-Program 'System' `
6868
-Verbose:$isVerbose > $null
6969

70+
# Create Inbound rule "Dell OpenManage Server Administrator (TCP-In)"
71+
New-NetFirewallRule -GPOSession $GPOSession `
72+
-Name 'OMSA-In-TCP' `
73+
-DisplayName 'Dell OpenManage Server Administrator (TCP-In)' `
74+
-Description 'Inbound rule for Dell OpenManage Server Administrator Web Service [TCP 1311]' `
75+
-Enabled False `
76+
-Profile Any `
77+
-Direction Inbound `
78+
-Action Allow `
79+
-Protocol TCP `
80+
-LocalPort 1311 `
81+
-RemoteAddress $RemoteManagementAddresses `
82+
-Program '%ProgramFiles%\Dell\SysMgt\oma\bin\dsm_om_connsvc64.exe' `
83+
-Verbose:$isVerbose > $null
84+
7085
#endregion Custom Rules

ADDS/DCFWTool/Set-ADDSFirewallPolicy.ps1

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ PS> .\Set-ADDSFirewallPolicy.ps1 -Verbose
1414
PS> .\Set-ADDSFirewallPolicy.ps1 -ConfigurationFileName Set-ADDSFirewallPolicy.Contoso.json -Verbose
1515
1616
.LINK
17-
Online documentation: https://github.com/MichaelGrafnetter/active-directory-firewall
17+
Online documentation: https://firewall.dsinternals.com
1818
1919
.NOTES
2020
Author: Michael Grafnetter
21-
Version: 2.8
21+
Version: 2.9
2222
2323
#>
2424

@@ -262,13 +262,29 @@ if(-not($configuration.DisableLLMNR -and $configuration.DisableMDNS)) {
262262
}
263263

264264
if(-not($configuration.LogMaxSizeKilobytes -ge 16384 -and $configuration.LogDroppedPackets -and $configuration.LogAllowedPackets)) {
265-
Write-Warning -Message 'The firewall log settings do not meet the standardized security baselines.'
265+
Write-Warning -Message 'The firewall log settings do not meet some standardized security baselines.'
266266
}
267267

268-
if($configuration.BlockWmiCommandExecution -eq $true) {
268+
if($configuration.EnableLocalIPsecRules) {
269+
Write-Warning -Message 'Local IPSec rules are enabled, which violates some standardized security baselines.'
270+
}
271+
272+
if($configuration.BlockWmiCommandExecution) {
269273
Write-Warning -Message 'SCCM client and DP do not work properly on systems where command execution over WMI is blocked.'
270274
}
271275

276+
if($configuration.RadiusClientAddresses -notcontains 'Any' -and -not $configuration.EnableNPS) {
277+
Write-Warning -Message 'Firewall rules for the Network Policy Server (NPS) are disabled, while non-default RADIUS client addresses are specified. This is probably a mistake.'
278+
}
279+
280+
if([string]::IsNullOrWhiteSpace($configuration.GroupPolicyObjectName)) {
281+
throw [System.ArgumentNullException]::new('GroupPolicyObjectName', 'The name of the target GPO must be provided.')
282+
}
283+
284+
if([string]::IsNullOrWhiteSpace($configuration.LogFilePath)) {
285+
throw [System.ArgumentNullException]::new('LogFilePath', 'The path to the firewall log file must be provided.')
286+
}
287+
272288
#endregion Configuration Validation
273289

274290
#region Create and Configure the GPO

ADDS/DCFWTool/Undo-ADDSFirewallPolicy.bat

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
REM Synopsis: This helper script resets the unmanaged domain controller policy settings to their default values.
33
REM It is intended to be executed locally on all domain controllers in the domain.
44
REM Author: Michael Grafnetter
5-
REM Version: 2.8
5+
REM Version: 2.9
66

77
echo Make sure that GPO settings are applied.
88
gpupdate.exe /Target:Computer
@@ -20,7 +20,7 @@ echo Configure the Active Directory service to use a dynamic RPC port.
2020
reg.exe delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTDS\Parameters" /v "TCP/IP Port" /f
2121

2222
echo Configure the Netlogon service to use a dynamic RPC port.
23-
reg.exe delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" /DCTcpipPort /f
23+
reg.exe delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" /v DCTcpipPort /f
2424

2525
echo Configure the legacy FRS service to use a dynamic RPC port.
2626
reg.exe delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTFRS\Parameters" /v "RPC TCP/IP Port Assignment" /f
@@ -41,6 +41,9 @@ reg.exe delete "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\NetBT\Param
4141
echo Restart the NTDS service.
4242
net.exe stop NTDS /y && net.exe start NTDS
4343

44+
echo Restart the Netlogon service.
45+
net.exe stop Netlogon /y && net.exe start Netlogon
46+
4447
echo Restart the NtFrs service.
4548
net.exe stop NtFrs /y && net.exe start NtFrs
4649

ADDS/DCFWTool/Update-ADDSFirewallPolicy.bat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
REM Synopsis: This helper script ensures that all domain controller firewall policy settings are applied, without requiring DC reboots.
33
REM It is intended to be executed locally on all domain controllers in the domain.
44
REM Author: Michael Grafnetter
5-
REM Version: 2.8
5+
REM Version: 2.9
66

77
echo Make sure that the latest GPO settings are applied.
88
gpupdate.exe /Target:Computer
@@ -13,6 +13,9 @@ gpscript.exe /startup
1313
echo Restart the NTDS service.
1414
net.exe stop NTDS /y && net.exe start NTDS
1515

16+
echo Restart the Netlogon service.
17+
net.exe stop Netlogon /y && net.exe start Netlogon
18+
1619
echo Restart the NtFrs service.
1720
net.exe stop NtFrs /y && net.exe start NtFrs
1821

ADDS/README.md

Lines changed: 130 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ keywords:
1212
- PowerShell
1313
- Group Policy
1414
- Security
15+
- Hardening
1516
- RPC
17+
- SMB
18+
- Named Pipes
19+
- Windows
1620
---
1721

1822
# Domain Controller Firewall
@@ -21,22 +25,23 @@ keywords:
2125

2226
| Date | Version | Author | Description |
2327
|------------|--------:|----------------------------|-----------------|
24-
| 2024-05-23 | 0.8 | P. Formanek, M. Grafnetter | Public draft |
25-
| 2024-08-27 | 0.9 | M. Grafnetter | Support for more server roles and external scripts |
26-
| 2024-11-20 | 1.0 | M. Grafnetter | Document ready for review |
27-
| 2024-11-23 | 1.1 | M. Grafnetter | Fixed some typos |
28-
| 2024-12-31 | 1.2 | M. Grafnetter | Added the `RestrictADWS` parameter |
28+
| 2024-05-23 | 0.8 | P. Formanek, M. Grafnetter | Public draft. |
29+
| 2024-08-27 | 0.9 | M. Grafnetter | Support for more server roles and [external scripts](#customrulefilenames). |
30+
| 2024-11-20 | 1.0 | M. Grafnetter | Document ready for review. |
31+
| 2024-11-23 | 1.1 | P. Formanek, M. Grafnetter | Fixed some typos. |
32+
| 2024-12-31 | 1.2 | M. Grafnetter | Added the [RestrictADWS](#restrictadws) parameter. |
33+
| 2025-01-11 | 1.3 | M. Grafnetter | Improved [helper scripts](#dcfwtool-distribution-contents). Added the [Port Scanning](#port-scanning) and expanded the [System Reboots](#system-reboots) sections. |
2934

3035
Script files referenced by this document are versioned independently:
3136

3237
| Script file name | Latest version |
3338
|---------------------------------|---------------:|
34-
| `Set-ADDSFirewallPolicy.ps1` | 2.8 |
35-
| `CustomRules.Sample.ps1` | 2.6 |
39+
| `Set-ADDSFirewallPolicy.ps1` | 2.9 |
40+
| `CustomRules.Sample.ps1` | 2.8 |
3641
| `RpcNamedPipesFilters.txt` | 2.1 |
3742
| `Show-WindowsFirewallLog.ps1` | 1.2 |
38-
| `Undo-ADDSFirewallPolicy.bat` | 2.8 |
39-
| `Update-ADDSFirewallPolicy.bat` | 2.8 |
43+
| `Undo-ADDSFirewallPolicy.bat` | 2.9 |
44+
| `Update-ADDSFirewallPolicy.bat` | 2.9 |
4045

4146
## Glossary {.unnumbered}
4247

@@ -1206,6 +1211,97 @@ It is located under Computer Configuration → Policies → Administrative Templ
12061211
> Value type: REG_DWORD
12071212
> Value data: 0
12081213
1214+
### Port Scanning
1215+
1216+
One way of validating a domain controller host-based firewall configuration is performing a full port scan from a [client IP address](#identifying-management-traffic).
1217+
While network administrators might prefer using Microsoft's [PortQry](https://www.microsoft.com/en-us/download/details.aspx?id=17148),
1218+
penetration testers would most probably use the [Nmap](https://nmap.org/) tool to discover remotely available protocols:
1219+
1220+
```shell
1221+
nmap -p 1-65535 adatum-dc.adatum.com
1222+
```
1223+
1224+
```txt
1225+
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-01-09 21:17 CET
1226+
Nmap scan report for adatum-dc.adatum.com (10.213.0.8)
1227+
Host is up (0.0027s latency).
1228+
Not shown: 65518 filtered tcp ports (no-response)
1229+
PORT STATE SERVICE
1230+
53/tcp open domain
1231+
88/tcp open kerberos-sec
1232+
135/tcp open msrpc
1233+
389/tcp open ldap
1234+
445/tcp open microsoft-ds
1235+
464/tcp open kpasswd5
1236+
593/tcp open http-rpc-epmap
1237+
636/tcp open ldapssl
1238+
3268/tcp open globalcatLDAP
1239+
3269/tcp open globalcatLDAPssl
1240+
38901/tcp open unknown
1241+
38902/tcp open unknown
1242+
49664/tcp open unknown
1243+
49667/tcp open unknown
1244+
49668/tcp open unknown
1245+
49672/tcp open unknown
1246+
49679/tcp open unknown
1247+
MAC Address: 00:17:FB:00:00:05 (FA)
1248+
1249+
Nmap done: 1 IP address (1 host up) scanned in 106.77 seconds
1250+
```
1251+
1252+
This sample output mostly contains well-known TCP ports like DNS (`53/TCP`), Kerberos (`88/TCP` and `464/TCP`), LDAP (`389/TCP` and `3268/TCP`),
1253+
LDAPS (`636/TCP` and `3269/TCP`), SMB (`445/TCP`), and RPC Endpoint Mapper (`135/TCP`),
1254+
which [must be reachable by Windows clients](https://learn.microsoft.com/en-us/troubleshoot/windows-server/active-directory/config-firewall-for-ad-domains-and-trusts#windows-server-2008-and-later-versions).
1255+
Ports `38901/TCP` and `38902/TCP` are organization-specific [static RPC ports](#static-rpc-ports) used by Active Directory.
1256+
All protocols that directly allow remote command execution, including RDP (`3389/TCP` and `3389/UDP`), WinRM (`5985/TCP` and `5986/TCP`), and WMI (dynamic RPC port or `24158/TCP`), are properly blocked.
1257+
1258+
Port `593/TCP` (RPC Endpoint Mapper over HTTP) is unnecessarily exposed by the built-in [Active Directory Domain Controller (RPC-EPMAP)](#active-directory-domain-controller-rpc-epmap) rule,
1259+
which is primarily used to open the core `135/TCP` port. Although we prefer not to modify this built-in rule, we typically block port `593/TCP` on firewall appliances, without any noticeable consequences.
1260+
1261+
There are 5 additional dynamic RPC ports present. An EPMAP query would have revealed more details about these ports:
1262+
1263+
| TCP Port | Transport | RPC Protocol |
1264+
|---------:|----------------|-------------------------------------------------------------------------|
1265+
| 49664 | `ncacn_ip_tcp` | [\[MS-SAMR\]: Security Account Manager (SAM) Remote Protocol] |
1266+
| 49667 | `ncacn_ip_tcp` | [\[MS-LSAD\]: Local Security Authority (Domain Policy) Remote Protocol] |
1267+
| 49668 | `ncacn_http` | [\[MS-LSAD\]: Local Security Authority (Domain Policy) Remote Protocol] |
1268+
| 49672 | `ncacn_ip_tcp` | [Key Isolation Service] |
1269+
| 49679 | `ncacn_ip_tcp` | [\[MS-RAA\]: Remote Authorization API Protocol] |
1270+
1271+
[\[MS-SAMR\]: Security Account Manager (SAM) Remote Protocol]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-samr/4df07fab-1bbc-452f-8e92-7853a3c7e380
1272+
[\[MS-LSAD\]: Local Security Authority (Domain Policy) Remote Protocol]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lsad/1b5471ef-4c33-4a91-b079-dfcbb82f05cc
1273+
[Key Isolation Service]: https://learn.microsoft.com/en-us/windows/win32/seccng/key-storage-and-retrieval
1274+
[\[MS-RAA\]: Remote Authorization API Protocol]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-raa/98ab2e01-da37-4e76-bea5-8d4d83e66e1a
1275+
1276+
These ports are allowed by the built-in [Active Directory Domain Controller (RPC)](#active-directory-domain-controller-rpc) rule.
1277+
The respective protocols are exposed through the `ncacn_np` RPC transport as well.
1278+
As a matter of fact, Windows client components seem to be using the `\PIPE\lsass` named pipe exclusively when communicating over these RPC protocols.
1279+
Consequently, the RPC dynamic port range (`49152/TCP` to `65535/TCP`) on domain controllers does not need to be accessible by member computers for AD to work properly. We therefore typically block this port range on firewall appliances.
1280+
1281+
A UDP port scan should yield far less interesting results:
1282+
1283+
```shell
1284+
nmap -sU -p 1-65535 adatum-dc.adatum.com
1285+
```
1286+
1287+
```txt
1288+
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-01-09 21:18 CET
1289+
Nmap scan report for adatum-dc.adatum.com (10.213.0.8)
1290+
Host is up (0.0035s latency).
1291+
Not shown: 65531 open|filtered udp ports (no-response)
1292+
PORT STATE SERVICE
1293+
53/udp open domain
1294+
88/udp open kerberos-sec
1295+
123/udp open ntp
1296+
389/udp open ldap
1297+
MAC Address: 00:17:FB:00:00:05 (FA)
1298+
1299+
Nmap done: 1 IP address (1 host up) scanned in 934.29 seconds
1300+
```
1301+
1302+
Contrary to what the documentation says, the Kerberos password change (kpasswd) protocol does not seem to be listening on port `464/UDP`.
1303+
More importantly, the firewall properly blocks the legacy NetBIOS protocol (ports `137/UDP`, `138/UDP`, and `139/TCP`).
1304+
12091305
## DCFWTool Distribution Contents
12101306

12111307
Below is a list of all files that are part of the solution, with their respective paths and brief descriptions.
@@ -1275,6 +1371,14 @@ Below is a list of all files that are part of the solution, with their respectiv
12751371

12761372
: PowerShell script for reading Windows Firewall log files.
12771373

1374+
`DCFWTool\Update-ADDSFirewallPolicy.bat`
1375+
1376+
: Batch script that locally applies all domain controller firewall policy settings, without requiring a DC reboot.
1377+
1378+
`DCFWTool\Undo-ADDSFirewallPolicy.bat`
1379+
1380+
: Batch script that locally resets the unmanaged domain controller policy settings to their default values.
1381+
12781382
[MSS (Legacy)]: https://techcommunity.microsoft.com/t5/microsoft-security-baselines/the-mss-settings/ba-p/701055
12791383
[MS Security Guide]: https://learn.microsoft.com/en-us/deployoffice/security/security-baseline#ms-security-guide-administrative-template
12801384

@@ -1565,7 +1669,7 @@ Here is a sample configuration file containing all the possible settings:
15651669
"ClientAddresses": [ "203.0.113.0/24", "198.51.100.0/24" ],
15661670
"ManagementAddresses": [ "198.51.100.0/24" ],
15671671
"DomainControllerAddresses": [ "192.0.2.0/24" ],
1568-
"RadiusClientAddresses": $null,
1672+
"RadiusClientAddresses": null,
15691673
"NtdsStaticPort": 38901,
15701674
"NetlogonStaticPort": 38902,
15711675
"FrsStaticPort": 38903,
@@ -2698,8 +2802,8 @@ and can be used as a template.
26982802
26992803
### System Reboots
27002804
2701-
Changes to some settings require a reboot of the target domain controller to be applied.
2702-
This is the with static port number configurations and settings that are modified through the startup script:
2805+
Changes to some settings require up to 2 reboots of the target domain controller to be applied.
2806+
This is the case with static port number configurations and settings that are modified through the startup script:
27032807
27042808
- [NtdsStaticPort](#ntdsstaticport)
27052809
- [NetlogonStaticPort](#netlogonstaticport)
@@ -2710,21 +2814,26 @@ This is the with static port number configurations and settings that are modifie
27102814
- [LogFilePath](#logfilepath)
27112815
- [EnableNPS](#enablenps)
27122816
2713-
If a full system reboot of all domain controllers is undesirable, the following steps can be performed instead:
2817+
If system reboots of all domain controllers are undesirable, the following steps can be performed instead:
27142818
27152819
1. Make sure that the Group Policy changes are replicated to all domain controllers.
27162820
2. Invoke the `gpupdate.exe /Target:Computer` command for the changed policies to be applied immediately.
27172821
3. Run the `gpscript.exe /startup` command for Group Policy startup scripts to be executed immediately.
27182822
4. Execute the `net.exe stop NTDS /y && net.exe start NTDS` command to restart the AD DS Domain Controller service.
2719-
5. Execute the `net.exe stop IAS /y && net.exe start IAS` command to restart the Network Policy Server service, if present.
2720-
6. Execute the `net.exe stop NtFrs /y && net.exe start NtFrs` command to restart the File Replication service
2823+
5. Execute the `net.exe stop Netlogon /y && net.exe start Netlogon` command to restart the Netlogon service.
2824+
6. Execute the `net.exe stop IAS /y && net.exe start IAS` command to restart the Network Policy Server service, if present.
2825+
7. Execute the `net.exe stop NtFrs /y && net.exe start NtFrs` command to restart the File Replication service
27212826
if migration to DFS-R has not been performed yet.
2722-
7. Execute the `net.exe stop Winmgmt /y && net.exe start Winmgmt` command to restart the Windows Managament
2827+
8. Execute the `net.exe stop Winmgmt /y && net.exe start Winmgmt` command to restart the Windows Managament
27232828
Instrumetation service, if its port is to be changed.
2724-
8. Repeat steps 2 to 7 on all domain controllers.
2829+
9. Repeat steps 2 to 8 on all domain controllers.
27252830
27262831
To simplify this process, the `Update-ADDSFirewallPolicy.bat` script contains all the commands discussed above.
27272832
2833+
> [!IMPORTANT]
2834+
> The Windows Managament Instrumetation (WMI) service sometimes fails to start after being reconfigured.
2835+
> When this happens, a domain controller reboot cannot be avoided.
2836+
27282837
### Multi-Domain Forests
27292838
27302839
The firewall policy can be deployed to multiple AD domains at once.
@@ -3062,12 +3171,15 @@ and server remote management:
30623171
| Group | Active Directory Domain Services |
30633172
| Direction | Inbound |
30643173
| Protocol | TCP |
3065-
| Port | 135 |
3174+
| Port | RPCEPMap |
30663175
| Program | `%systemroot%\system32\svchost.exe` |
30673176
| Service | `rpcss` |
30683177
| Description | Inbound rule for the RPCSS service to allow RPC/TCP traffic to the Active Directory Domain Controller service. |
30693178
| Remote Addresses | [Client Computers](#clientaddresses), [Management Computers](#managementaddresses), [Domain Controllers](#domaincontrolleraddresses) |
30703179
3180+
This firewall rule opens ports `135/TCP` (RPC Endpoint Mapper) and `593/TCP` (RPC Endpoint Mapper over HTTP).
3181+
Only port `135/TCP` is [used by Windows clients](#port-scanning).
3182+
30713183
#### Kerberos Key Distribution Center - PCR (UDP-In)
30723184
30733185
| Property | Value |

0 commit comments

Comments
 (0)