PowerShell has become an indispensable tool in Digital Forensics and Incident Response (DFIR), offering unparalleled flexibility and efficiency for investigating and responding to cyber incidents. As a robust command-line shell and scripting language, PowerShell is built into Windows operating systems, making it readily accessible for both system administrators and DFIR analysts.
Its importance lies in its ability to query, interact with, and manipulate nearly every aspect of a Windows system. PowerShell provides analysts with powerful cmdlets and scripts to gather forensic artefacts, analyse logs, investigate execution activity, and automate repetitive tasks. Furthermore, its deep integration with Windows APIs and system internals allows for rapid data collection and analysis during an active investigation.
In addition to its forensic capabilities, PowerShell is a critical tool for incident response. It can be used to identify active threats, terminate malicious processes, block network connections, and remediate compromised systems in real-time. However, its power also makes it a favourite tool of attackers, emphasising the need for DFIR professionals to understand its capabilities fully—not only to leverage it for defence but also to detect its misuse.
Mastering PowerShell equips DFIR practitioners with the skills to efficiently analyse systems, respond to threats, and bolster an organisation\u2019s cybersecurity posture in today\u2019s fast-paced and complex threat landscape.
Get General insight and System Information
Get System Information:
Get-ComputerInfo
Get Operating System Details:
Get-WmiObject -Class Win32_OperatingSystem
Get Hardware Information:
Get-WmiObject -Class Win32_ComputerSystem
Get Installed Software:
Get-WmiObject -Class Win32_Product
Check For Local User Accounts:
Get-LocalUser
Get the last logon time for the user “John” by using
net user
net user John | Select-String "Last logon"
Retrieve information about users and their last logon times:
To determine if a scheduled task is suspicious, focus on understanding its purpose, verifying its actions, and comparing it against known legitimate tasks in your environment.
"You need to specifically look at the Clean file system entry. This is highly suspicious and attempts to destroy evidence or something like that. You can use PowerShell commands effectively to gather detailed information about a scheduled task, including its properties and actions.
Display all properties for a detailed analysis of the task now
$task = Get-ScheduledTask | Where-Object { $_.TaskName -eq "NameOfSuspiciousTask" }
$task | Format-List * # Display all properties for detailed analysis
$task.Actions # Display actions configured for the task
$task.Triggers # Display triggers configured for the task
You can perform a detailed analysis of a task by running the following
# Retrieve the scheduled task object
$task = Get-ScheduledTask -TaskName "Clean file system"
# Display all properties of the scheduled task
$task | Format-List *
# Display actions configured for the task
$task.Actions
# Display triggers configured for the task
$task.Triggers
# Display settings and security descriptor
$task.Settings
$task.SecurityDescriptor
# Display task principal and version
$task.Principal
$task.Version
The MSFT_TaskDailyTrigger class provides properties that define how often the task runs, at what time, and any intervals or repetitions required. Here are some key properties of MSFT_TaskDailyTrigger
To access and display the values under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
# Define the path to the registry key
$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
# Get the registry key properties
Get-ItemProperty -Path $registryPath
Get Processes
Get-Process
Review the security event logs for login activities related to the user “John”:
To reveal registry added or changing activity using Get-WinEvent for the System log, you can filter for specific Event IDs related to registry changes. Common Event IDs for registry changes include:
4656: A handle to an object was requested.
4657: A registry value was modified.
4663: An attempt was made to access an object.
4659: A handle to an object was requested with the intent to delete. You can use:
Circular Log Type: This indicates that the log file is configured to overwrite old entries with new ones once the log reaches its maximum size. This is useful for logs that accumulate data continuously.
Size: The size of the log file in bytes.
Number of Entries: The number of events currently logged in that file. For example, We found events recorded as Admin and Operational. Investigate it:
If you want to search for specific patterns in the log files, you can use Select-String as follows:
# Search for a specific pattern in the PrintService Operational log
Get-WinEvent -LogName "Microsoft-Windows-PrintService/Admin" | Select-Object -ExpandProperty Message | Select-String "Print"
Verify that a file, for example, ualapi.dll is legitimate and hasn’t been tampered with:
- The repository contains multiple PowerShell scripts that can help you respond to cyber attacks on Windows Devices. (Credit Bert-JanP)
- Learn different PowerShell Commands that can be used in Incident Response to remediate the machine. (written by )
How to Run PowerShell Script on Remote Computers - The article looks at several examples of how to use PowerShell Remoting interactive session mode and persistent connections to run PS1 a script on a remote computer. (written by )
- Digital Forensics and Incident Response (written by Jai Minton)