T1070.003

Clear Command History

Adversaries clear command history to conceal actions taken during an intrusion. On Windows, PowerShell maintains two history stores: the in-session history (cleared by Clear-History) and the PSReadLine history file at %APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt. Attackers may delete or truncate this file or use Remove-Item (Get-PSReadlineOption).HistorySavePath — the method used by Medusa Group ransomware. On Linux/macOS, history -c clears the in-memory history, HISTFILE= unsets the history file, and rm ~/.bash_history deletes the persistent record. Setting HISTSIZE=0 or HISTFILESIZE=0 prevents future history recording. TeamTNT, Aquatic Panda, APT41, Kobalos, and APT5 (ESXi) have all been observed clearing command history as post-exploitation cleanup.

Microsoft Sentinel / Defender
kusto
DeviceProcessEvents
| where Timestamp > ago(24h)
| where (
    // PowerShell history file deletion or manipulation
    (FileName in~ ("powershell.exe", "pwsh.exe")
     and ProcessCommandLine has_any ("ConsoleHost_history", "PSReadLine", "Get-PSReadlineOption", "Clear-History", "Remove-Item"))
    or
    // Linux/macOS bash history clearing via shell
    (FileName in~ ("bash", "sh", "zsh", "fish")
     and ProcessCommandLine has_any ("history -c", "history -w", "HISTFILE=", "HISTSIZE=0", "HISTFILESIZE=0"))
    or
    // Direct deletion of history files
    (ProcessCommandLine has_any ("bash_history", ".zsh_history", ".ash_history", ".fish_history")
     and ProcessCommandLine has_any ("rm ", "del ", "Remove-Item", "unlink"))
)
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
         InitiatingProcessFileName, InitiatingProcessCommandLine
| sort by Timestamp desc
| union (
    DeviceFileEvents
    | where Timestamp > ago(24h)
    | where ActionType in ("FileDeleted", "FileModified")
    | where FolderPath has_any ("PSReadLine", "ConsoleHost_history")
       or FileName in~ (".bash_history", ".zsh_history", ".ash_history")
    | project Timestamp, DeviceName, InitiatingProcessAccountName,
             FileName, FolderPath, ActionType, InitiatingProcessFileName
)
| sort by Timestamp desc
medium severity medium confidence

Data Sources

Process: Process Creation File: File Deletion File: File Modification Microsoft Defender for Endpoint

Required Tables

DeviceProcessEvents DeviceFileEvents

False Positives

  • Administrators running Clear-History during interactive PowerShell sessions for legitimate housekeeping
  • Shell profile scripts that set HISTSIZE=0 for service accounts that should not record history
  • Backup or rotation scripts that delete and recreate .bash_history files
  • Security tools that sanitize history files after removing credentials accidentally typed at the command line

Unlock Pro Content

Get the full detection package for T1070.003 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections