-
Notifications
You must be signed in to change notification settings - Fork 162
Group Policy
Official link to download Microsoft Security Compliance Toolkit
Microsoft Security Compliance Toolkit 1.0 - How to use
This set of tools allows enterprise security administrators to download, analyze, test, edit and store Microsoft-recommended security configuration baselines for Windows and other Microsoft products, while comparing them against other security configurations.
Microsoft Security Compliance Toolkit includes multiple files and useful programs, here are the 3 main components that are important to us and are used in this script.
Microsoft is dedicated to providing its customers with secure operating systems, such as Windows and Windows Server, and secure apps, such as Microsoft 365 apps for enterprise and Microsoft Edge. In addition to the security assurance of its products, Microsoft also enables you to have fine control over your environments by providing various configuration capabilities.
Even though Windows and Windows Server are designed to be secure out-of-the-box, many organizations still want more granular control over their security configurations. Continue reading more in the Microsoft website
When you unzip the Microsoft Security Baseline file, you will find this folder structure:
-
Documentation## - contains PDF and Excel files describing the differences between the previous baseline release and the new settings that were added. contains the default
policyrules
file, which is used with the Security Compliance Toolkit, you can view it using Policy Analyzer program. - GP Reports - contains reports in HTML format, describes the GPO settings that can be applied for each category
- GPOs – contains GPO objects for different scenarios, these are the actual policies that will be applied
-
Scripts - contains multiple PowerShell scripts for different scenarios and helps us easily import GPO settings to our system. the most important PowerShell script here is
Baseline-LocalInstall.ps1
-
Templates – contains additional Group Policy Object templates that are not available by default on Windows, such as
MSS-legacy.admx
, these are inADMX
andADML
formats. they will be copied toC:\Windows\PolicyDefinitions
, where they belong, so that the new Security Baselines GPOs can be interpreted.
Quoting from the PDF file supplied by LGPO:
LGPO.exe is a command-line utility that is designed to help automate management of Local Group Policy. It can import and apply settings from Registry Policy (Registry.pol) files, security templates, Advanced Auditing backup files, as well as from formatted “LGPO text” files and Policy Analyzer “.PolicyRules” XML files. It can export local policy to a GPO backup. It can export the contents of a Registry Policy file to the “LGPO text” format that can then be edited, and can build a Registry Policy file from an LGPO text file. (The syntax for LGPO text files is described later in this document.)
LGPO.exe has four command-line forms: for importing and applying settings to local policy – including to Multiple Local Group Policy Objects (MLGPO)1 ; for creating a GPO backup; for parsing a Registry Policy file and outputting “LGPO” text; for producing a Registry Policy file from an LGPO text file.
All output is written to LGPO.exe’s standard output, and all diagnostic and error information is written to its standard error. Both can be redirected to files using standard command shell operations. To support batch file use, LGPO.exe’s exit code is 0 on success and non-zero on any error.
LGPO
is the most crucial program for our workflow, it is part of the Security Compliance Toolkit (SCT)
What is the Local Group Policy Object (LGPO) tool?
LGPO.exe - Local Group Policy Object Utility
Use this command to back up the currently set local group policies to drive C
.\LGPO.exe /b C:
.\LGPO.exe /g 'Path to the backup'
# example:
.\LGPO.exe /g 'C:\{841474E6-33EC-418C-B884-EA0F7C8195DB}'
(This only contains everything in Computer (Machine) Configuration -> Administrative Templates)
# Example command
.\LGPO.exe /m ".\GPOX\DomainSysvol\GPO\Machine\registry.pol"
(This only contains everything in Computer (Machine) Configuration -> Windows Settings => Security Settings => everything in the subfolders except for the Advanced Audit Policy Configuration)
# Example command
.\LGPO.exe /s ".\GPOX\DomainSysvol\GPO\Machine\microsoft\windows nt\SecEdit\GptTmpl.inf"
Quoting from the PDF file supplied by Policy Analyzer:
Policy Analyzer is a lightweight utility for analyzing and comparing sets of Group Policy Objects (GPOs). It can highlight when a set of Group Policies has redundant settings or internal inconsistencies and can highlight the differences between versions or sets of Group Policies. It can also compare one or more GPOs against local effective state. You can export all its findings to a Microsoft Excel spreadsheet. Policy Analyzer lets you treat a set of GPOs as a single unit, and represents all settings in one or more GPOs in a single “.PolicyRules” XML file. You can also use .PolicyRules files with LGPO.exe v3.0 to apply those GPOs to a computer’s local policy, instead of having to copy GPO backups around.
What is the Policy Analyzer tool?
In Policy Analyzer, there is an option called Compare to Effective State
. Quoting from the PDF file that ships with Policy Analyzer program regarding that option:
Enable one or more of the Policy Rule sets’ checkboxes and click “Compare to Effective State” to compare the selected baselines against the local computer’s current configured state. The operation will require UAC elevation if any of the selected baselines include security template or advanced auditing settings that require elevation to retrieve.
The Policy Viewer will show the combined settings from all the selected Policy Rule sets in one column under the heading “Baseline(s),” and the corresponding current settings on the local computer and the logged-on user in a separate column under the heading “Effective state.”
The effective state settings are also saved to a new .PolicyRules file with a name combining “EffectiveState_,” the current computer name, and the current date and time in the format “yyyyMMdd- HHmmss.” For example, “EffectiveState_WKS51279_20200210-183947.PolicyRules.”
- The PowerShell script downloads the official Microsoft Security Baselines from Microsoft servers and applies them to the system.
- It then downloads Group Policies from this GitHub repository, which represent the configurations explained in the main Readme page, and applies them to the system, on top of Microsoft Security Baselines, so where there is a conflict of policy, Hardening script will replace the configurations set by Microsoft Security Baselines.
- The script proceeds with applying the rest of the configurations (as explained in the main Readme page) to the system. these configurations aren't available in Group Policy or can only be applied using PowerShell.
- Installed the newest available Windows build on a fresh Hyper-V VM, fully updated it, created a standard checkpoint.
- Opened Group Policy editor and started applying security measures described in the Readme page.
- After completing each category, used
LGPO.exe /b C:
to backup Group Policies of the system by creating a full GPO. - Then I took only files needed from the backup,
registry.pol
andGptTmpl.inf
and put them in a zip file, renamed it toSecurity-Baselines-X.zip
- As long as the VM is still using the latest available build of Windows, I use the standard checkpoint I had created to revert the VM back to that new state. If there is a newer build of Windows available, I delete that old VM, download the new Windows ISO file from Microsoft servers, then I create a fresh Hyper-V VM using it.
- I copy the Group Policy files,
registry.pol
orGptTmpl.inf
to the VM, import them by using.\LGPO.exe /m "path"
forregistry.pol
files or.\LGPO.exe /s "path"
forGptTmpl.inf
files. - Open Group Policy editor and change anything that is needed, once I'm done, I create a full backup of Group Policies of the system using
LGPO.exe /b C:
command, again take out the modified file, eitherregistry.pol
orGptTmpl.inf
. - use
PolicyAnalyzer
to double check everything by comparing the old file with the new one and making sure the correct change is applied. - Replace the old Group Policy file with the new file and create a new
Security-Baselines-X
to upload to the GitHub repository.
-
Use folder options in Control Panel or File Explorer to show hidden files and folder.
-
Open Policy Analyzer program, Navigate to Add -> File -> Add files from GPO(s)... -> Browser for this folder "C:\Windows\System32\GroupPolicy", Select the folder -> Import -> save the Policy Rules file in
\Documents\PolicyAnalyzer\
-
Back at the main window, use View/Compare button to view applied Group Policies. the result that you will see is all of the Group Policies that are applied to your system.
Another way to verify the applied Group Policies is to perform the 3 tasks above, what it will give you is the Policy Rules file which is generated from Group Policy state after using the script. If we take this policy rules file to a different machine where we just clean installed Windows and use Policy Analyzer to compare it to the Effective State of the system, we will see what Group Policy settings have changed as a result of using the script.
Note: At first, when we clean install Windows, the Group Policy folder C:\Windows\System32\GroupPolicy
is empty, it will get populated with empty folders and a 1kb file that contains only 1 word, when we first open the local Group Policy editor. It will get more populated with actual policies once we start modifying any group policies.
-
Download the
security-baselines-x.zip
file, extract it. -
Open Policy Analyzer, Navigate to Add -> File -> Select either
Add User Configuration (registry.pol)
orAdd Security Template (*.inf)
-> Browser for the folder that was extracted from thesecurity-baselines-x.zip
, navigate to the category you want. -
Select either
.pol
or.inf
file, Import it, give it a name, save it in\Documents\PolicyAnalyzer\
-
Back at the main window, use "Compare to Effective State" button to view what policies are included in the file.
-
As you will see, everything is according to what has been explicitly stated in the GitHub's Readme page.
This command gets the information about all installed provisioning packages on your system.
Get-ProvisioningPackage -AllInstalledPackages
Configuration service providers for IT pros
Settings changed when you uninstall a provisioning package
Why Intune and CSPs are the future of Windows management instead of Group Policy
Link to Microsoft Employee's comment
Download Windows Configuration Designer from Microsoft Store or from Windows ADK or from Windows insiders ADK, to easily create provisioning packages for your device(s)
You can use gpresult to see more info about Group Policies on your computer
# What policies are applied to your computer:
gpresult /z
# or
gpresult /v
# What policies are applied to the current user:
gpresult /scope user /v
We can manually backup and restore Group Policy settings by copying this folder and all of its content:
C:\Windows\System32\GroupPolicy
- Create AppControl Policy
- Create Supplemental Policy
- System Information
- Configure Policy Rule Options
- Simulation
- Allow New Apps
- Build New Certificate
- Create Policy From Event Logs
- Create Policy From MDE Advanced Hunting
- Create Deny Policy
- Merge App Control Policies
- Deploy App Control Policy
- Get Code Integrity Hashes
- Get Secure Policy Settings
- Update
- Sidebar
- Introduction
- App Control for Lightly Managed Devices
- App Control for Fully managed device - Variant 1
- App Control for Fully managed device - Variant 2
- App Control for Fully managed device - Variant 3
- App Control for Fully managed device - Variant 4
- App Control Notes
- How to Create and Deploy a Signed App Control Policy
- Fast and Automatic Microsoft Recommended Driver Block Rules updates
- App Control policy for BYOVD Kernel mode only protection
- EKUs in App Control for Business Policies
- App Control Rule Levels Comparison and Guide
- Script Enforcement and PowerShell Constrained Language Mode in App Control Policies
- How to Use Microsoft Defender for Endpoint Advanced Hunting With App Control
- App Control Frequently Asked Questions (FAQs)
- Create Bootable USB flash drive with no 3rd party tools
- Event Viewer
- Group Policy
- How to compact your OS and free up extra space
- Hyper V
- Overrides for Microsoft Security Baseline
- Git GitHub Desktop and Mandatory ASLR
- Signed and Verified commits with GitHub desktop
- About TLS, DNS, Encryption and OPSEC concepts
- Things to do when clean installing Windows
- Comparison of security benchmarks
- BitLocker, TPM and Pluton | What Are They and How Do They Work
- How to Detect Changes in User and Local Machine Certificate Stores in Real Time Using PowerShell
- Cloning Personal and Enterprise Repositories Using GitHub Desktop
- Only a Small Portion of The Windows OS Security Apparatus
- Rethinking Trust: Advanced Security Measures for High‐Stakes Systems
- Clean Source principle, Azure and Privileged Access Workstations
- How to Securely Connect to Azure VMs and Use RDP
- Basic PowerShell tricks and notes
- Basic PowerShell tricks and notes Part 2
- Basic PowerShell tricks and notes Part 3
- Basic PowerShell tricks and notes Part 4
- Basic PowerShell tricks and notes Part 5
- How To Access All Stream Outputs From Thread Jobs In PowerShell In Real Time
- PowerShell Best Practices To Follow When Coding
- How To Asynchronously Access All Stream Outputs From Background Jobs In PowerShell
- Powershell Dynamic Parameters and How to Add Them to the Get‐Help Syntax
- RunSpaces In PowerShell
- How To Use Reflection And Prevent Using Internal & Private C# Methods in PowerShell