T1562.003

Impair Command History Logging

Adversaries may impair command history logging to hide commands they run on a compromised system. On Linux and macOS, this involves manipulating HISTFILE, HISTFILESIZE, HISTSIZE, and HISTCONTROL environment variables, or redirecting history to /dev/null. On Windows, adversaries may modify PSReadLine settings to disable PowerShell command history. On network devices, adversaries may disable command logging entirely.

Microsoft Sentinel / Defender
kusto
let HistoryTampering = dynamic(["unset HISTFILE", "export HISTFILE=/dev/null", "export HISTFILESIZE=0", "export HISTSIZE=0", "HISTCONTROL=ignoreboth", "HISTCONTROL=ignorespace", "set +o history", "history -c", "history -w /dev/null", "rm -f ~/.bash_history", "truncate -s 0", "ln -sf /dev/null", "Set-PSReadlineOption -HistorySaveStyle SaveNothing", "Set-PSReadLineOption -HistorySavePath", "Remove-Item*ConsoleHost_history.txt", "del*ConsoleHost_history.txt"]);
DeviceProcessEvents
| where Timestamp > ago(24h)
| where ProcessCommandLine has_any (HistoryTampering)
| extend Platform = case(
    ProcessCommandLine has_any ("PSReadline", "ConsoleHost_history"), "Windows",
    ProcessCommandLine has_any ("HISTFILE", "bash_history", "history -c", "set +o history"), "Linux/macOS",
    "Unknown")
| extend TamperMethod = case(
    ProcessCommandLine has "unset HISTFILE" or ProcessCommandLine has "HISTFILE=/dev/null", "HISTFILE Disabled",
    ProcessCommandLine has "HISTFILESIZE=0" or ProcessCommandLine has "HISTSIZE=0", "History Size Zeroed",
    ProcessCommandLine has "HISTCONTROL", "HISTCONTROL Modified",
    ProcessCommandLine has "history -c", "History Cleared",
    ProcessCommandLine has "set +o history", "History Disabled",
    ProcessCommandLine has "rm" or ProcessCommandLine has "truncate" or ProcessCommandLine has "ln -sf /dev/null", "History File Deleted/Redirected",
    ProcessCommandLine has "SaveNothing", "PSReadLine Disabled",
    ProcessCommandLine has "HistorySavePath", "PSReadLine Redirected",
    ProcessCommandLine has "ConsoleHost_history", "PS History File Deleted",
    "Other")
| project Timestamp, DeviceName, AccountName, ProcessCommandLine, Platform, TamperMethod, InitiatingProcessFileName
| sort by Timestamp desc
medium severity medium confidence

Data Sources

Process: Process Creation Command: Command Execution Sensor Health: Host Status

Required Tables

DeviceProcessEvents

False Positives

  • Developers or sysadmins who habitually set HISTCONTROL=ignorespace for convenience when typing sensitive commands (e.g., inline passwords)
  • Automated provisioning or hardening scripts that configure shell history settings as part of baseline configuration
  • Docker container entrypoint scripts that disable history logging in ephemeral environments

Unlock Pro Content

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

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections