Skip to content
soulemikePublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

PSHard - Enterprise PowerShell Hardening Framework

PowerShell Platform ASD Alignment

Overview

PSHard is an enterprise-grade PowerShell hardening framework designed to secure PowerShell environments across Windows Server and Windows client systems. The module provides a structured approach to implementing the Australian Signals Directorate (ASD) maturity framework for PowerShell security.

Key Features:

  • 14 public functions covering all ASD maturity levels
  • Registry-based policy enforcement
  • Comprehensive logging and auditing capabilities
  • JEA (Just Enough Administration) endpoint provisioning
  • WDAC (Windows Defender Application Control) policy generation
  • Tiered administration model support
  • Compatible with Windows PowerShell 5.1 and PowerShell 7+

Table of Contents

Installation

Prerequisites

  • Windows PowerShell 5.1 or PowerShell 7+
  • Windows Server 2016+ or Windows 10/11
  • Administrative privileges for most functions
  • Active Directory module (for GPO and Tier Model functions)

Install from Source

# Clone or download the repository
# Copy to PowerShell module path
$modulePath = "$env:ProgramFiles\WindowsPowerShell\Modules\PSHard"
Copy-Item -Path ".\PSHard" -Destination $modulePath -Recurse -Force

# Import the module
Import-Module PSHard -Force

# Verify installation
Get-Module PSHard
Get-Command -Module PSHard

Verify Installation

# Run the test suite
Invoke-Pester -Path "$env:ProgramFiles\WindowsPowerShell\Modules\PSHard\Tests\PSHard.Tests.ps1"

# Check configuration status
Test-PSHardConfiguration

Quick Start

Level 1: Basic Hardening (AllSigned + Logging)

Import-Module PSHard -Force

# Set execution policy to AllSigned
Set-PSHardExecutionPolicy -Policy AllSigned -Scope LocalMachine

# Enable comprehensive logging
Set-PSHardModuleLogging -ModuleNames "*"
Set-PSHardScriptBlockLogging -EnableInvocationLogging
Set-PSHardTranscription -OutputDirectory "C:\Logs\PowerShell" -EnableInvocationHeader

# Enable AMSI
Set-PSHardAMSI

# Verify configuration
Test-PSHardConfiguration

Level 2: System Hardening

# Configure firewall rules for remoting
Set-PSHardFirewall -BlockInboundPorts @(5985, 5986)

# Harden WinRM remoting
Set-PSHardRemoting -DisableBasicAuth -DisableUnencrypted

# Enable audit policies
Set-PSHardAuditPolicy -Subcategories @("Process Creation", "File System", "Registry")

# Remove legacy PowerShell versions
Set-PSHardLegacyRemoval -FeatureNames @("MicrosoftWindowsPowerShellV2")

Level 3: Advanced Provisioning

# Create JEA endpoint for constrained administration
New-PSHardJEAEndpoint -Name "DiagnosticsJEA" `
    -VisibleCmdlets @("Get-Process", "Get-Service", "Get-EventLog")

# Generate WDAC policy
New-PSHardWDACPolicy -OutputPath "C:\Policies\WDAC" `
    -Mode "Audit" `
    -AllowedExecutables @("pwsh.exe", "powershell.exe")

# Create tier model security groups
New-PSHardTierModel -DomainName "contoso.com" -Tiers @("T0", "T1", "T2")

# Create and link GPO
New-PSHardGpo -Name "PowerShell-Security-Policy" `
    -Comment "Enterprise PowerShell hardening" `
    -LinkTarget "OU=Servers,DC=contoso,DC=com"

ASD Framework Alignment

The Australian Signals Directorate (ASD) Securing PowerShell in the Enterprise framework defines four maturity levels. PSHard implements controls across all levels:

Maturity Level 0: Default Configuration

Status: ⚠️ Not Recommended

Level 0 represents PowerShell in its default configuration without security considerations. PSHard is designed to elevate organizations from Level 0 to higher maturity levels.

Maturity Level 1: Approved Scripts + Signing + Logging ✅

PSHard Coverage: COMPLETE

ASD Control PSHard Function Implementation Status
Script Execution Policy Set-PSHardExecutionPolicy ✅ Full implementation
AllSigned Policy -Policy AllSigned parameter ✅ Supported
RemoteSigned Policy -Policy RemoteSigned parameter ✅ Supported
Module Logging Set-PSHardModuleLogging ✅ Full implementation
Script Block Logging Set-PSHardScriptBlockLogging ✅ Full implementation
Transcription Set-PSHardTranscription ✅ Full implementation
Engine Lifecycle Logging Via Script Block Logging ✅ Captured
Centralized Logging Event Log integration ✅ Windows Event Log
PowerShell 5.0+ Module compatibility ✅ PS 5.1 & 7+

Registry Paths Configured:

  • HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
  • HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
  • HKLM:\Software\Policies\Microsoft\Windows\PowerShell\Transcription

Maturity Level 2: Role-Based Control + Hardened WinRM ✅

PSHard Coverage: PARTIAL

ASD Control PSHard Function Implementation Status
Role-Based Application Control Set-PSHardFirewall + Group Policy ⚠️ Partial
WinRM Hardening Set-PSHardRemoting ✅ Basic implementation
Kerberos/Negotiate Only WinRM configuration ⚠️ Manual configuration needed
Disable CredSSP WinRM configuration ⚠️ Manual configuration needed
Disable Basic Auth -DisableBasicAuth parameter ✅ Supported
Disable Unencrypted -DisableUnencrypted parameter ✅ Supported
Firewall Restrictions Set-PSHardFirewall ✅ Implemented
Legacy Removal Set-PSHardLegacyRemoval ✅ Implemented

WinRM Hardening Gaps:

  • IPv4/IPv6 filtering not fully implemented
  • CbtHardeningLevel configuration not exposed
  • TrustedHosts configuration not implemented
  • Client policy settings incomplete

Maturity Level 3: Constrained Endpoints ✅

PSHard Coverage: BASIC

ASD Control PSHard Function Implementation Status
Constrained Endpoints New-PSHardJEAEndpoint ✅ Basic implementation
NoLanguage Mode JEA configuration ⚠️ Default only
Role Definitions Session configuration ⚠️ Partial
Visible Cmdlets -VisibleCmdlets parameter ✅ Supported
Custom Modules Module loading ❌ Not implemented

JEA Limitations:

  • Role capability files (.psrc) not generated
  • RunAs configuration not exposed
  • Session type restrictions limited
  • WinRS bypass mitigation not addressed

ASD Appendix Coverage

Appendix Topic PSHard Coverage
Appendix A Maturity Framework ✅ Referenced in documentation
Appendix B Script Execution Policy ✅ Set-PSHardExecutionPolicy
Appendix C PowerShell Logging ✅ Set-PSHard*Logging functions
Appendix D Windows Auditing ✅ Set-PSHardAuditPolicy
Appendix E Log Analysis ❌ Not implemented
Appendix F Permissions & Transcripts ⚠️ Partial (directory creation only)
Appendix G WinRM Hardening ⚠️ Partial (basic settings)
Appendix H Constrained Endpoints ⚠️ Partial (basic JEA)

Function Reference

Registry Policy Functions

Set-PSHardExecutionPolicy

Configures PowerShell script execution policy via registry.

Set-PSHardExecutionPolicy [-Scope <LocalMachine|CurrentUser>] [-Policy <AllSigned|RemoteSigned|Unrestricted>] [-EnableScripts <bool>]

ASD Alignment: Appendix B - Script Execution Policy

Set-PSHardAMSI

Enables Anti-Malware Scan Interface (AMSI) integration.

Set-PSHardAMSI

Registry Path: HKLM:\Software\Microsoft\Windows\CurrentVersion\AMSI

Set-PSHardScriptBlockLogging

Enables logging of PowerShell script blocks.

Set-PSHardScriptBlockLogging [-EnableInvocationLogging]

ASD Alignment: Appendix C - Script Block Tracing

Set-PSHardModuleLogging

Enables module and pipeline logging.

Set-PSHardModuleLogging [-ModuleNames <string[]>]

ASD Alignment: Appendix C - Module/Pipeline Logging

Set-PSHardTranscription

Configures PowerShell session transcription.

Set-PSHardTranscription [-OutputDirectory <string>] [-EnableInvocationHeader]

ASD Alignment: Appendix C - Transcription

System Hardening Functions

Set-PSHardFirewall

Creates inbound firewall block rules.

Set-PSHardFirewall [-BlockInboundPorts <int[]>] [-RuleGroup <string>]

ASD Alignment: Appendix G - WinRM Hardening

Set-PSHardRemoting

Configures WinRM and WS-Man security settings.

Set-PSHardRemoting [-EnableWinRM] [-DisableBasicAuth] [-DisableUnencrypted]

ASD Alignment: Appendix G - WinRM Hardening

Set-PSHardAuditPolicy

Configures Windows audit policies for PowerShell.

Set-PSHardAuditPolicy [-Subcategories <string[]>]

ASD Alignment: Appendix D - Windows Security Auditing

Set-PSHardLegacyRemoval

Disables legacy Windows PowerShell features.

Set-PSHardLegacyRemoval [-FeatureNames <string[]>]

Configuration Query Functions

Test-PSHardConfiguration

Retrieves current PowerShell security configuration status.

Test-PSHardConfiguration

Returns:

  • ExecutionPolicy
  • ModuleLoggingEnabled
  • ScriptBlockLoggingEnabled
  • AMSIEnabled

Provisioning Functions

New-PSHardJEAEndpoint

Creates and registers a JEA session configuration.

New-PSHardJEAEndpoint -Name <string> -VisibleCmdlets <string[]> [-ConfigurationPath <string>]

ASD Alignment: Appendix H - Constrained Endpoints

New-PSHardWDACPolicy

Generates WDAC policy XML files.

New-PSHardWDACPolicy -OutputPath <string> [-Mode <Audit|Enforced>] [-AllowedExecutables <string[]>]

New-PSHardTierModel

Creates Active Directory security groups for tiered administration.

New-PSHardTierModel -DomainName <string> [-Tiers <string[]>] [-GroupPrefix <string>]

New-PSHardGpo

Creates and optionally links Group Policy Objects.

New-PSHardGpo -Name <string> [-Comment <string>] [-LinkTarget <string>]

Live Testing Results

Test Environment

  • Target: Windows Server 2025 Datacenter Azure Edition
  • IP Address: 20.125.96.137
  • PowerShell Version: 5.1.26100.32684
  • Test Date: 2026-04-23

Test Results Summary

Phase Tests Passed Failed Partial
Phase 1: Module Load 4 3 0 1
Phase 2: Registry Policies 6 6 0 0
Phase 3: System Hardening 6 4 0 2
Phase 4: Configuration Query 5 5 0 0
Phase 5: Provisioning 2 0 1 1
Total 23 18 1 4

Key Findings

✅ Working Correctly:

  • Module imports without errors (after fixes)
  • All 14 public functions export correctly
  • Registry-based policies (Execution Policy, AMSI, Logging)
  • Configuration querying (Test-PSHardConfiguration)
  • Firewall rule creation
  • Audit policy configuration

⚠️ Known Limitations:

  • PowerShell 5.1 class scoping (classes work internally but not via New-Object)
  • Some functions timeout on long-running operations (JEA endpoint creation)
  • WinRM configuration incomplete

❌ Issues Identified:

  • Unix-style line continuations (\) in source files needed replacement with PowerShell backticks (`)
  • Module manifest missing function exports

Remediation Actions Taken

  1. Fixed ProvisioningService.ps1: Changed \ line continuations to `
  2. Fixed SystemHardeningService.ps1: Changed \ line continuations to `
  3. Updated PSHard.psd1: Added explicit FunctionsToExport for all 14 functions

See full test results in:

  • Tests/PSHard-LiveTestPlan.md - Complete test plan
  • Tests/PSHard-LiveTestResults.md - Detailed results with evidence
  • Tests/PSHard-Remediation.md - Fix instructions and recommendations

Legacy PowerShellGrc.ps1 Comparison

Overview

The legacy PowerShellGrc.ps1 script is a comprehensive PowerShell hardening implementation that served as inspiration for PSHard. This section identifies gaps between the legacy script and the current PSHard module.

Features in PowerShellGrc.ps1 but NOT in PSHard

Feature PowerShellGrc.ps1 PSHard Priority
Code Signing Certificate Creation ✅ Self-signed cert generation ❌ Not implemented High
Certificate Trust GPO ✅ GPO for trusted publishers ❌ Not implemented High
Device Guard Integration ✅ Code integrity policies ❌ Not implemented Medium
AppLocker Policy ✅ XML policy generation ❌ Not implemented Medium
SSH Remoting Configuration ✅ OpenSSH server setup ❌ Not implemented Medium
PowerShell Core Installation ✅ MSI installation ❌ Not implemented Low
Protected Event Logging ✅ Mentioned in comments ❌ Not implemented Medium
Log Analysis Functions ✅ Set-PSHardLogAnalysis stub ❌ Not implemented Low
Constrained Exception Handling ✅ Set-PSHardConstrainedException stub ❌ Not implemented Low
AMSI Verification ✅ Set-PSHardVerifyAmsi stub ❌ Not implemented Medium
Event Log Creation ✅ Install-EventLog function ❌ Not implemented Low
Transcript Directory ACLs ✅ DACL/SACL configuration ⚠️ Partial (directory only) High
Scheduled Task for Transcripts ✅ Cleanup task ❌ Not implemented Low
WinRS Mitigation ✅ Network logon restrictions ❌ Not implemented Medium
Outbound Firewall Rules ✅ Block internet for PowerShell ❌ Not implemented Medium
WSMAN Security Descriptor ✅ SDDL configuration ❌ Not implemented High
Registry ACLs ✅ Permission hardening ❌ Not implemented High
SCENoApplyLegacyAuditPolicy ✅ Legacy audit check ⚠️ Partial Medium
Audit Security Descriptor ✅ Admin SID injection ⚠️ Partial High

Implementation Quality Comparison

Aspect PowerShellGrc.ps1 PSHard Notes
Architecture Monolithic script Modular (Classes + Functions) PSHard is more maintainable
Error Handling Try/catch in some functions Consistent error handling PSHard more robust
ShouldProcess Limited Full SupportsShouldProcess PSHard safer for production
Validation Manual validation Parameter validation attributes PSHard more PowerShell-idiomatic
Documentation Inline comments External documentation PSHard better documented
Testing None Pester tests + Live tests PSHard production-ready
GPO Integration Direct GPO creation Basic GPO creation PowerShellGrc more complete
Logging Verbose logging Verbose + structured logging Comparable

PowerShellGrc.ps1 Unique Features to Port

High Priority

  1. Code Signing Infrastructure

    # From PowerShellGrc.ps1
    $cert = New-SelfSignedCertificate -CertStoreLocation "Cert:\LocalMachine\My" `
        -Subject "CN=PowerShell-Signing" -KeyUsage DigitalSignature `
        -Type CodeSigningCert
  2. Transcript Directory Security

    # DACL/SACL configuration for transcript folders
    # Application Packages: Read and Execute
    # Creator Owner: Deny All
    # Authenticated Users: Write and Read
    # SYSTEM: Full Control
    # Administrators: Full Control
  3. Registry ACL Hardening

    # Protect PowerShell registry keys from modification
    # HKLM:\Software\Policies\Microsoft\Windows\PowerShell

Medium Priority

  1. SSH Remoting Setup

    # OpenSSH server installation and configuration
    # PowerShell subsystem configuration
    # Default shell configuration
  2. Device Guard/WDAC Integration

    # Code integrity policy creation
    # Certificate-based signing enforcement
  3. Outbound Network Restrictions

    # Block PowerShell internet access via firewall
    New-NetFirewallRule -Direction Outbound -Program "pwsh.exe" -Action Block

Recommended Migration Path

For organizations using PowerShellGrc.ps1:

  1. Immediate: Use PSHard for Level 1 maturity (logging + execution policy)
  2. Short-term: Port high-priority features (signing, ACLs) to PSHard
  3. Medium-term: Implement SSH remoting and Device Guard support
  4. Long-term: Full feature parity with PowerShellGrc.ps1

Security Considerations

Execution Policy Limitations

The PowerShell execution policy is not a security boundary. It can be bypassed using various techniques:

# Bypass examples that PSHard cannot prevent:
powershell -ExecutionPolicy Bypass -File script.ps1
powershell -Command "Invoke-Expression (Get-Content script.ps1 -Raw)"

Recommendation: Use execution policy as part of defense-in-depth, not as primary security control.

Class Scoping in PowerShell 5.1

PowerShell classes defined in modules have limited accessibility in PowerShell 5.1:

# This will FAIL in PowerShell 5.1:
$service = New-Object PolicyRegistryService

# This will SUCCEED:
Import-Module PSHard
Set-PSHardAMSI  # Uses PolicyRegistryService internally

Workaround: Use module functions rather than direct class instantiation.

JEA Endpoint Security

Constrained endpoints can be bypassed by users with local administrator privileges via WinRS. To mitigate:

  1. Strictly control local administrator access
  2. Use role-based delegation instead
  3. Restrict network logon privileges

Transcript Security

Transcripts contain sensitive information. Ensure:

  1. Transcript directory has appropriate ACLs
  2. Regular cleanup of old transcripts
  3. Protected Event Logging for sensitive data

Contributing

Development Setup

# Clone the repository
git clone <repository-url>
cd PSHard

# Import for development
Import-Module .\PSHard.psm1 -Force

# Run tests
Invoke-Pester .\Tests\PSHard.Tests.ps1

Coding Standards

  • Use PowerShell backticks (`) for line continuation, not \
  • Include [CmdletBinding(SupportsShouldProcess = $true)] for destructive operations
  • Add parameter validation attributes
  • Write verbose logging for all configuration changes

Testing Requirements

Before submitting changes:

  1. Run unit tests: Invoke-Pester .\Tests\
  2. Test on Windows PowerShell 5.1
  3. Test on PowerShell 7+
  4. Verify registry changes
  5. Test WhatIf functionality

License

This project is licensed under the terms specified in the repository.

Acknowledgments

  • Australian Signals Directorate (ASD) for the PowerShell security framework
  • Microsoft PowerShell team for JEA and logging capabilities
  • Legacy PowerShellGrc.ps1 contributors

References

  1. ASD Securing PowerShell in the Enterprise
  2. Microsoft PowerShell Documentation
  3. PowerShell JEA Documentation
  4. Windows Defender Application Control

Note: This module is designed for enterprise environments. Always test in a non-production environment before deploying to production systems.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages