Get a Pentest and security assessment of your IT network.

Cyber Security

PowerShell Event Log Security: Risks & Protection

TL;DR

Yes, already opened PowerShell event logs can be targeted by hackers very quickly. While not a guaranteed instant hack, the information within those logs provides valuable clues for attackers. This guide explains how to protect your system.

Understanding the Risk

PowerShell records events like script execution, command history, and module loading in Windows Event Logs. If an attacker gains access (even limited) to a machine, they can analyse these logs to:

  • Discover what PowerShell commands have been run previously.
  • Identify sensitive data that may have been processed or stored.
  • Find potential vulnerabilities based on installed modules and scripts.
  • Reconstruct attacker activity if they’ve already compromised the system (post-exploitation).

The speed of analysis depends on log volume, but it can be done in milliseconds with appropriate tools.

Protecting Your PowerShell Event Logs: Step-by-Step Guide

  1. Enable PowerShell Logging Properly
    • Ensure ModuleLogging and ScriptBlockLogging are enabled. These record module imports and script content.
    • Use Group Policy or PowerShell itself to configure logging settings.
    • Set-PSRepository -Name PSGallery -InstallationOption Trusted

      (This helps control where scripts come from.)

  2. Restrict Access to Event Logs
    • Limit which users and groups can read the PowerShell event logs. The default ‘Everyone’ access is too permissive.
    • Use Windows Event Collector (WEC) to forward logs to a central, secure server for analysis instead of relying on local access.
    • To check current permissions: Open Event Viewer -> Right-click ‘PowerShell’ log -> Properties -> Security tab.
  3. Monitor for Suspicious Activity
    • Use a SIEM (Security Information and Event Management) system to analyse PowerShell logs in real time. Look for patterns like:
      • Execution of encoded commands.
      • Downloads from untrusted sources.
      • Attempts to disable logging.
      • Use of obfuscation techniques.
    • Consider using PowerShell-specific monitoring tools that understand common attack patterns.
  4. Implement Just Enough Administration (JEA)
    • JEA allows you to restrict what users can do in PowerShell, even if they have administrative privileges. This limits the impact of a compromised account.
    • Configure JEA roles that only allow specific commands and modules to be used.
  5. Code Signing
    • Sign your PowerShell scripts with a trusted certificate. This verifies their authenticity and prevents tampering.
    • Set-AuthenticodeSignature -FilePath "C:ScriptsMyScript.ps1" -Certificate (Get-ChildItem Cert:CurrentUserMy -CodeSigning)
  6. Regularly Review Logs
    • Don’t just collect logs; actively review them for suspicious activity. Automated alerts are helpful, but manual inspection is also important.
    • Look for anomalies and investigate anything unusual.
  7. Enable PowerShell Transcription
    • Transcription records all commands entered in a PowerShell session to a text file. This provides an additional layer of logging, even if script block logging is disabled.
    • Start-Transcript -Path "C:TranscriptsPowerShellLog.txt"
  8. Keep PowerShell Updated
    • Regularly update PowerShell to the latest version to benefit from security patches and bug fixes.

Important Considerations

While these steps significantly improve your security posture, no system is completely immune to attack. A layered approach combining technical controls with user awareness training is essential.

Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation