Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden windows security module v.0.2.5 #154

Merged
merged 34 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a1f890e
Updated BitLocker category
HotCakeX Nov 12, 2023
7b80dd8
Module version increase
HotCakeX Nov 12, 2023
2e6dd85
Changed total number of items to verify
HotCakeX Nov 12, 2023
7ce9dae
Using quiet mod for LGPO.exe on unprotect cmdlet
HotCakeX Nov 12, 2023
4a3552a
Improved the message text
HotCakeX Nov 12, 2023
ba30e2b
WinVerifyTrust Signature Validation uses Registry now
HotCakeX Nov 12, 2023
a77d047
Improved Unprotect-WindowsSecurity cmdlet
HotCakeX Nov 13, 2023
82537d9
variable types updates
HotCakeX Nov 13, 2023
893429b
Significantly improved BitLocker Category
HotCakeX Nov 14, 2023
bc724f1
Making sure variables follow PascalCasing
HotCakeX Nov 15, 2023
ec72f77
Minor improvements to the BitLocker category
HotCakeX Nov 15, 2023
6e6d758
BitLocker category now has multifactor Auth
HotCakeX Nov 16, 2023
e6b42e1
Finalizing BitLocker category multifactor Auth
HotCakeX Nov 16, 2023
5fe3b5a
Added Steps recorder removal info to Readme
HotCakeX Nov 16, 2023
9251e79
Updated Readme with new BitLocker info changes
HotCakeX Nov 16, 2023
2015470
Added Steps recorder removal
HotCakeX Nov 16, 2023
5b51810
Added BitLocker MFA to compliance checking
HotCakeX Nov 16, 2023
ec21739
Added steps recorder removal verification to Compliance checking
HotCakeX Nov 16, 2023
30877a5
Revert "Added BitLocker MFA to compliance checking"
HotCakeX Nov 17, 2023
b96f5df
Fixed the previous commit
HotCakeX Nov 17, 2023
1330bd8
Fixed Hibernate file size detection
HotCakeX Nov 17, 2023
91b042b
Version bump
HotCakeX Nov 17, 2023
07f279b
Updated Scheduled task code
HotCakeX Nov 17, 2023
9dfc426
Overall improvements to the code
HotCakeX Nov 17, 2023
9c3a2e0
Execution policy adjustment
HotCakeX Nov 17, 2023
bc1fad0
Adding changes to the module script
HotCakeX Nov 17, 2023
7a5eb0b
Minor improvement to the code
HotCakeX Nov 17, 2023
1458599
Improved Harden Windows Security module
HotCakeX Nov 17, 2023
3a98b8f
Fixed a regression in one of the previous commits
HotCakeX Nov 17, 2023
6cc8e48
Added logic for detecting write-protected drives
HotCakeX Nov 17, 2023
75f4db2
Made variable names more unique
HotCakeX Nov 17, 2023
b52c59b
Adjusted the names of the security levels
HotCakeX Nov 17, 2023
c527c21
Improved Hyper-V groups member detection
HotCakeX Nov 18, 2023
6fa0809
Code optimization
HotCakeX Nov 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
397 changes: 223 additions & 174 deletions Harden-Windows-Security Module/Main files/Confirm-SystemCompliance.psm1

Large diffs are not rendered by default.

71 changes: 29 additions & 42 deletions Harden-Windows-Security Module/Main files/Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,18 @@ $global:ErrorActionPreference = 'Stop'

# Function to test if current session has administrator privileges
Function Test-IsAdmin {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
$Identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = New-Object Security.Principal.WindowsPrincipal $Identity
$Principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

# Hiding Invoke-WebRequest progress because it creates lingering visual effect on PowerShell console for some reason
# https://github.com/PowerShell/PowerShell/issues/14348

# https://stackoverflow.com/questions/18770723/hide-progress-of-Invoke-WebRequest
# Create an in-memory module so $ScriptBlock doesn't run in new scope
$null = New-Module {
function Invoke-WithoutProgress {
[CmdletBinding()]
param (
[Parameter(Mandatory)][scriptblock]$ScriptBlock
)
# Save current progress preference and hide the progress
$prevProgressPreference = $global:ProgressPreference
$global:ProgressPreference = 'SilentlyContinue'
try {
# Run the script block in the scope of the caller of this module function
. $ScriptBlock
}
finally {
# Restore the original behavior
$global:ProgressPreference = $prevProgressPreference
}
}
}

# Make sure the latest version of the module is installed and if not, automatically update it, clean up any old versions
function Update-self {

[version]$CurrentVersion = (Test-ModuleManifest "$psscriptroot\Harden-Windows-Security-Module.psd1").Version
[System.Version]$CurrentVersion = (Test-ModuleManifest -Path "$psscriptroot\Harden-Windows-Security-Module.psd1").Version

try {
Invoke-WithoutProgress {
[version]$global:LatestVersion = Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/HotCakeX/Harden-Windows-Security/main/Harden-Windows-Security%20Module/version.txt'
}
[System.Version]$global:LatestVersion = Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/HotCakeX/Harden-Windows-Security/main/Harden-Windows-Security%20Module/version.txt' -ProgressAction SilentlyContinue
}
catch {
Write-Error -Message "Couldn't verify if the latest version of the module is installed, please check your Internet connection."
Expand Down Expand Up @@ -105,26 +78,40 @@ function Update-self {
# Self update the module
Update-self

# Requirements Check
#Region Requirements-Check

# check if user's OS is Windows Home edition
if ((Get-CimInstance -ClassName Win32_OperatingSystem).OperatingSystemSKU -eq '101') {
Write-Error 'Windows Home edition detected, exiting...'
break
}

# check if user's OS is latest version
if (-NOT ([System.Environment]::OSVersion.Version -ge [version]'10.0.22621')) {
Write-Error "You're not using the latest version of the Windows OS, exiting..."
# Check if user's OS is the latest build
# Minimum OS build number required for the hardening measures used in this script
[System.Decimal]$Requiredbuild = '22621.2428'

# Get OS build version
[System.Decimal]$OSBuild = [System.Environment]::OSVersion.Version.Build

# Get Update Build Revision (UBR) number
[System.Decimal]$UBR = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'UBR'

# Create full OS build number as seen in Windows Settings
[System.Decimal]$FullOSBuild = "$OSBuild.$UBR"

# Make sure the current OS build is equal or greater than the required build
if (-NOT ($FullOSBuild -ge $Requiredbuild)) {
Write-Error -Message "You're not using the latest build of the Windows OS. A minimum build of $Requiredbuild is required but your OS build is $FullOSBuild`nPlease go to Windows Update to install the updates and then try again."
break
}

if (Test-IsAdmin) {
# check to make sure TPM is available and enabled
[bool]$TPMFlag1 = (Get-Tpm).tpmpresent
[bool]$TPMFlag2 = (Get-Tpm).tpmenabled
if (!$TPMFlag1 -or !$TPMFlag2) {
Write-Error 'TPM is not available or enabled, please go to your UEFI settings to enable it and then try again.'
break
$TPM = Get-Tpm
if (-not ($TPM.tpmpresent -and $TPM.tpmenabled)) {
Write-Error -Message 'TPM is not available or enabled, please enable it in UEFI settings and try again.'
break
}
}
}

#Endregion Requirements-Check
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '0.2.4'
ModuleVersion = '0.2.5'

# Supported PSEditions
CompatiblePSEditions = @('Core')
Expand Down Expand Up @@ -81,7 +81,7 @@ Harden Windows Safely, Securely, only with Official Microsoft methods
'@

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '7.3.8'
PowerShellVersion = '7.4.0'

# Name of the PowerShell host required by this module
# PowerShellHostName = ''
Expand Down
Loading