Windows Console History Clearing
Adversaries may clear the command history of a compromised account to conceal the actions undertaken during an intrusion on a Windows system.
Attackers can try to cover their tracks by clearing the PowerShell console history on Windows systems. PowerShell offers multiple ways to log commands, including the built-in history and the command history managed by the PSReadLine module. This activity is often part of post-compromise behavior aimed at evading detection and forensic analysis. This rule detects the execution of specific commands that clear the built-in PowerShell logs or delete the ConsoleHost_history.txt file. The rule focuses on PowerShell activity and covers scenarios where commands like Clear-History, Remove-Item, rm, and Set-PSReadlineOption are used to manipulate command history.
Attack Chain
- Initial access is gained through an unspecified method, potentially exploiting a vulnerability or using stolen credentials.
- The attacker executes PowerShell (powershell.exe, pwsh.exe, or powershell_ise.exe) to perform reconnaissance and other malicious activities.
- The attacker attempts to clear the PowerShell command history using the
Clear-Historycmdlet. - Alternatively, the attacker attempts to remove the
ConsoleHost_history.txtfile usingRemove-Itemorrm, which stores the PSReadLine command history. - Another method involves using the
Set-PSReadlineOptioncmdlet with theSaveNothingparameter to prevent the saving of future command history. - The attacker may leverage other tools and techniques to further obscure their activities and maintain persistence on the compromised system.
- The attacker attempts to move laterally to other systems within the network to increase their impact.
- The final objective is data exfiltration, deployment of ransomware, or other malicious activities, all while attempting to evade detection by clearing logs and command history.
Impact
Successful clearing of console history hinders forensic investigations and incident response efforts. If command history is cleared, administrators will have difficulty reconstructing the attacker’s actions and identifying the extent of the compromise. This can lead to prolonged incident response times, increased damage, and potential for further exploitation of the compromised systems.
Recommendation
- Deploy the Sigma rule
Detect Clearing PowerShell Historyto your SIEM to detect the use ofClear-Historycmdlet, potentially indicating an attempt to remove command history. - Deploy the Sigma rule
Detect Removal of PowerShell History Fileto detect the use ofRemove-Itemorrmcommand against the PowerShell history file. - Enable PowerShell logging and auditing policies to ensure adequate visibility into PowerShell activity as described in the setup instructions to improve detection capabilities.
Detection coverage 2
Detect Clearing PowerShell History
mediumDetects the use of Clear-History cmdlet to clear the PowerShell command history.
Detect Removal of PowerShell History File
mediumDetects the use of Remove-Item or rm command against the PowerShell history file.
Detection queries are kept inside the platform. Get full rules →