Or as we say in the north of Germany: "Moin Moin!"
I’m a Microsoft Senior Customer Engineer with a broad spectrum of interests.
Due to recent events multiple customers have questioned their infrastructure security concept and approached me with questions about possible improvements to their Microsoft Endpoint Configuration Manager (aka ConfigMgr or MECM) infrastructure.
One way of dealing with on-premises infrastructure challenges could be the move to a cloud service like Intune. But that might not be an option for everyone, or it might not be an immediate option.
This blog post is not a direct answer to every security measure possible and more dedicated to a script I wrote to semi-automate the ConfigMgr infrastructure firewall configuration based on the following documenation ConfigMgr Ports. So, it’s main purpose is to give other ConfigMgr admins the option to further harden their infrastructure firewall setup in an easy way.
It can either set rules directly, just show New-NetFirewallRule commands for a system, or add the rules to an existing Active Directory Group Policy.
Semi-Automated ConfigMgr firewall rules
Validate and set ConfigMgr firewall rules
The script in more detail
The “Default-FirewallRuleConfig.json” file in more detail
Add systems, rules or services to JSON config
Other security measures
Conclusion and GitHub link
As a Microsoft employee I’m trained to follow the three zero trust principles.
Those principles help to answer the question on how to strengthen ConfigMgr’s security setup.
Learn more about the topic via: https://aka.ms/zerotrust
#1 Verify explicitly
Always authenticate and authorize based on all available data points, including user identity, location, device health, service or workload, data classification, and anomalies.
#2 Use least privileged access
Limit user access with just-in-time and just-enough-access (JIT/JEA), risk-based adaptive polices, and data protection to help secure both data and productivity.
#3 Assume breach
Minimize blast radius and segment access. Verify end-to-end encryption and use analytics to get visibility, drive threat detection, and improve defenses.
Since we have to assume breach and we want to minimize blast radius within a ConfigMgr infrastructure we should minimize options for lateral movement and limit service access by setting the correct firewall rules on each server.
Since I’m a PowerShell enthusiast and always like a good PowerShell challenge, I decided to write a script to set the required firewall rules on each site system in a semi-automated way.
The goal was to get the required inbound rule PowerShell commands for each ConfigMgr site system with a list of IP addresses like this example:
New-NetFirewallRule -DisplayName "MECM CAS to Primary Site" -Direction "Inbound" -RemoteAddress ("10.10.10.20") -Protocol "TCP" -LocalPort 445 -Profile "Any" -Action "Allow" -Group "MECM-v1" -LocalAddress ("10.10.10.15")
Before going into the inner workings of the script, let’s have a look at possible ConfigMgr environment setups.
ConfigMgr has many different roles and can be a simple setup with just one server hosting all required roles or a complex setup with many systems and all kinds of role configurations.
The following pictures show two examples of a simple and a complex ConfigMgr setup.
Important: Not all required connections are shown in the pictures and not all required roles are visible. It is just meant to show that creating firewall rules for each system and create “communication-bubbles” (green boxes) can be challenging when having a dispersed set of roles and servers.
ConfigMgr Infrastructure Example
SAW = Secure Admin Workstation
The script should be used in the following way.
(More details about each parameter can be found in section: “The script in more detail”)
.\New-ConfigMgrFirewallRuleDefinition.ps1 -ExportConfigMgrSystemRoleInformation -ProviderMachineName "your provider machinename" -SiteCode "your sitecode"
The script might not take any possible ConfigMgr configuration into account and it is always a good idea to test settings before applying them. Here are some tips on how to validate the rules:
The script has six different modes of operation and uses a file called “Default-FirewallRuleConfig.json” to work. The file contains a list of possible firewall rules based on the official ConfigMgr port documentation.
While the script is designed for ConfigMgr, with a few tweaks in the JSON file it should also be possible to use it for any other product.
(Note: The script works more like a module and might be slightly overengineered ;) )
Six main operational modes via parameter:
Parameter -ExportConfigMgrSystemRoleInformation
Copy the script: “New-ConfigMgrFirewallRuleDefinition.ps1” and the file “Default-FirewallRuleConfig.json” to a machine with access to the SMS Provider.
(You need to be a ConfigMgr full admin to use the export parameter)
Run the following command:
.\New-ConfigMgrFirewallRuleDefinition.ps1 -ExportConfigMgrSystemRoleInformation -ProviderMachineName "your provider machinename" -SiteCode "your sitecode"
The script will then read the ConfigMgr hierarchy information as well as the “Default-FirewallRuleConfig.json” file and will create a new file in the same directory as the script itself.
The new file contains the same information as in “Default-FirewallRuleConfig.json” but with a list of systems of your ConfigMgr environment.
(You can add systems, rule entries or service definitions manually if needed)
Parameter -ShowConfig
ShowConfig will open a grid view with possible JSON definition files you can choose from.
If you pick a file and click “OK” It will open three other grid views showing the contents of the file.
Parameter -ShowCommands
This is the default parameter if no parameter has been used.
ShowCommands will open a grid view with possible JSON definition files you can choose from.
The script will then open another grid view with the list of systems of the selected file.
Choose a system and click “OK” to get a list of matching firewall rules based on roles installed of the system. The commands can be copied to the selected machine and run in PowerShell.
Parameter -ShowGPOCommands
The same as with ShowCommands but with additional commands to add the firewall rules to a group policy. You can then copy the commands to a system with access to the GPO or run them locally.
The following parameters are also required in that case:
Parameter -AddRulesLocally
The same as with ShowCommands but the firewall rules will be set directly on the system running the script.
Parameter -AddRulesToGPO
The same as with AddRulesLocally but instead of local rules, the rules will be added directly to a GPO.
This might require additional rights to be successful.
The following parameters are also required in that case:
The above parameters are the main ones, but there are some more to manipulate the output of the script no matter which main mode was chosen.
Parameter -GroupSuffix
Suffix to a firewall rule group. The group name is part of the JSON definition file.
Parameter -UseAnyAsLocalAddress
Will set the local address to ANY instead of the actual local IP address of a system
Helpful if a firewall GPO should work for multiple systems instead of just for one with a specific IP address
Parameter -ValidRulesOnly
Will only show rules with status OK
Parameter -MergeSimilarRules
When used, the script will merge similar rules based on direction, protocol, port and program. Can be used to minimize the required rules.
The list shown left will be merged to the list shown on the right side of the picture:
Merge Rule Example
Parameter -IPType
The script will lookup IP addresses for any system of the config file. The parameter can be used to either limit the results to IPv4 or IPv6 or to output both types of IP addresses. The script will try to lookup IPv4 IP addresses for each system by default.
Parameter -DefinitionFilePath
Path to a JSON definition file. If not used, a grid view will open from which a file can be chosen.
The parameter could be used in case you always work with just one file and don’t want to use the GridView selection.
Parameter -CreateOutboundRuleForeachInboundRule
To create an outbound rule for each calculated inbound rule. Not quite tested and more experimental
The file “Default-FirewallRuleConfig.json” consists of four sections:
{
"FullQualifiedDomainName": "CAS.contoso.local",
"IPAddress": "10.11.12.13",
"SiteCode": "CAS",
"ParentSiteCode": "CAS",
"Description": "Main central administration site in Europe",
"RoleList": [
"CASSQLServerRole",
"SQLServerRole",
"CentralAdministrationSite",
"SMSProvider",
"PrimarySoftwareUpdatePoint",
"CentralSoftwareUpdatePoint",
"SoftwareUpdatePoint",
"EndpointProtectionPoint"
]
},
{
"FullQualifiedDomainName": "ts01.contoso.local",
"IPAddress": "10.10.11.12",
"SiteCode": "P01",
"ParentSiteCode": "",
"Description": "Terminal Server 1",
"RoleList": [
"RDP",
"MECMConsole"
]
}
{
"RuleName": "MECM Console to SMS provider",
"Source": "MECMConsole",
"Destination": "SMSProvider",
"Direction": "Inbound",
"Action": "Allow",
"Profile": "Any",
"Group": "MECM",
"Description": "Console to WMI SMS provider connection. HTTPS for AdminService",
"IgnoreSiteCode": "",
"Services": [
"RPC",
"RPCUDP",
"RPCDynamic",
"HTTPS"
]
}
{
"Name": "HTTPS",
"Protocol": "TCP",
"Port": "443",
"Program": "",
"Description": "Https endpoint"
}
You can add as many systems, rules or services to the JSON config as you like. While this might not be necessary for ConfigMgr site systems, since those can be exported, it might be necessary for external systems with the need to access ConfigMgr.
Use the documentation which is part of the default JSON file and simply copy and paste existing entries and change them to your needs.
All possible values are part of the documentation in the JSON file, but you can also define your own roles or services.
Configuring the local firewall of a ConfigMgr site system is just one part of a security strategy.
Consult the ConfigMgr security documentation to read more about that topic: https://docs.microsoft.com/en-us/mem/configmgr/core/understand/fundamentals-of-security
Some general security tips
This is not a complete list and is mainly a summary of what is in the documentation already.
I hope the article is written understandably and I hope the solution will help you further harden your ConfigMgr infrastructure.
Download or clone the solution here: https://github.com/jonasatgit/scriptrepo/tree/master/Firewall
Feel free to check out other blogs I wrote or co-authored:
https://aka.ms/jonasohmsenblogs
https://aka.ms/stefanroellblogs
Stay safe!
Jonas Ohmsen
Microsoft Germany
Disclaimer:
This posting is provided "AS IS" with no warranties, and confers no rights.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.