Install any skill in seconds. Free to start, no credit card required.
Get Started Free →In addition to clearing system logs, an adversary may clear the command history of a compromised account to conceal the actions undertaken during an intrusion.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 14% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 20% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 59% | 0% |
| case-22 | ✗→✓ | ▲ Improved | -14% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 38% | 0% |
> Sub-technique of: T1070
In addition to clearing system logs, an adversary may clear the command history of a compromised account to conceal the actions undertaken during an intrusion. Various command interpreters keep track of the commands users type in their terminal so that users can retrace what they've done.
On Linux and macOS, these command histories can be accessed in a few different ways. While logged in, this command history is tracked in a file pointed to by the environment variable <code>HISTFILE</code>. When a user logs off a system, this information is flushed to a file in the user's home directory called <code>~/.bash_history</code>. The benefit of this is that it allows users to go back to commands they've used before in different sessions. Adversaries may delete their commands from these logs by manually clearing the history (<code>history -c</code>) or deleting the bash history file <code>rm ~/.bash_history</code>.
Adversaries may also leverage a Network Device CLI on network devices to clear command history data (<code>clear logging</code> and/or <code>clear history</code>). On ESXi servers, command history may be manually removed from the /var/log/shell.log file.
On Windows hosts, PowerShell has two different command history providers: the built-in history and the command history managed by the <code>PSReadLine</code> module. The built-in history only tracks the commands used in the current session. This command history is not available to other sessions and is deleted when the session ends.
The <code>PSReadLine</code> command history tracks the commands used in all PowerShell sessions and writes them to a file (<code>$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt</code> by default). This history file is available to all sessions and contains all past history since the file is not deleted when the session ends.
Adversaries may run the PowerShell command <code>Clear-History</code> to flush the entire command history from a current PowerShell session. This, however, will not delete/flush the <code>ConsoleHost_history.txt</code> file. Adversaries may also delete the <code>ConsoleHost_history.txt</code> file or edit its contents to hide PowerShell commands they have run.
Platforms: ESXi, Linux, macOS, Network Devices, Windows
The following tests are from Atomic Red Team and provide actionable ways to test this technique:
Clears bash history via rm
Supported Platforms: linux, macos
bashrm #{history_path}
Clears bash history via echo
Supported Platforms: linux
bashecho "" > #{history_path}
Clears bash history via cat /dev/null
Supported Platforms: linux, macos
bashcat /dev/null > #{history_path}
Clears bash history via a symlink to /dev/null
Supported Platforms: linux, macos
bashln -sf /dev/null #{history_path}
Clears bash history via truncate
Supported Platforms: linux
bashtruncate -s0 #{history_path}
If Atomic Red Team tests are not applicable, manually verify the technique by:
Forward logging of historical data to remote data store and centralized logging solution to preserve historical command line log data.
Preventing users from deleting or writing to certain files can stop adversaries from maliciously altering their <code>~/.bash_history</code> or <code>ConsoleHost_history.txt</code> files.
Making the environment variables associated with command history read only may ensure that the history is preserved.
| Finding | Severity | Impact | | ------------------------------------------ | -------- | --------------- | | Clear Command History technique applicable | Low | Defense Evasion |
| CWE ID | Title | | ------- | ---------------------------- | | CWE-693 | Protection Mechanism Failure |
Other measured skills in the registry, with their headline benchmark lift.