T1070.003 Clear Command History
Sub-technique of: T1070
High-Level Description
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 HISTFILE. When a user logs off a system, this information is flushed to a file in the user's home directory called ~/.bash_history. 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 (history -c) or deleting the bash history file rm ~/.bash_history.
Adversaries may also leverage a Network Device CLI on network devices to clear command history data (clear logging and/or clear history). 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 PSReadLine 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 PSReadLine command history tracks the commands used in all PowerShell sessions and writes them to a file ($env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt 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 Clear-History to flush the entire command history from a current PowerShell session. This, however, will not delete/flush the ConsoleHost_history.txt file. Adversaries may also delete the ConsoleHost_history.txt file or edit its contents to hide PowerShell commands they have run.
Kill Chain Phase
- Defense Evasion (TA0005)
Platforms: ESXi, Linux, macOS, Network Devices, Windows
What to Check
- Identify if Clear Command History technique is applicable to target environment
- Check ESXi systems for indicators of Clear Command History
- Check Linux systems for indicators of Clear Command History
- Check macOS systems for indicators of Clear Command History
- Verify mitigations are bypassed or absent (3 known mitigations)
- Assess detection coverage (1 detection strategies)
How to Test
Atomic Red Team Tests
The following tests are from Atomic Red Team and provide actionable ways to test this technique:
Atomic Test 1: Clear Bash history (rm)
Clears bash history via rm
Supported Platforms: linux, macos
rm #{history_path}
Atomic Test 2: Clear Bash history (echo)
Clears bash history via echo
Supported Platforms: linux
echo "" > #{history_path}
Atomic Test 3: Clear Bash history (cat dev/null)
Clears bash history via cat /dev/null
Supported Platforms: linux, macos
cat /dev/null > #{history_path}
Atomic Test 4: Clear Bash history (ln dev/null)
Clears bash history via a symlink to /dev/null
Supported Platforms: linux, macos
ln -sf /dev/null #{history_path}
Atomic Test 5: Clear Bash history (truncate)
Clears bash history via truncate
Supported Platforms: linux
truncate -s0 #{history_path}
Manual Testing
If Atomic Red Team tests are not applicable, manually verify the technique by:
Identify Attack Surface: Determine if the target environment is susceptible to Clear Command History by examining the target platforms (ESXi, Linux, macOS).
Assess Existing Defenses: Review whether mitigations for T1070.003 are in place. If defenses are absent or misconfigured, this technique may be exploitable.
Execute Test: Use tools and methods described in the MITRE ATT&CK page and external references below.
Remediation Guide
M1029 Remote Data Storage
Forward logging of historical data to remote data store and centralized logging solution to preserve historical command line log data.
M1022 Restrict File and Directory Permissions
Preventing users from deleting or writing to certain files can stop adversaries from maliciously altering their ~/.bash_history or ConsoleHost_history.txt files.
M1039 Environment Variable Permissions
Making the environment variables associated with command history read only may ensure that the history is preserved.
Detection
Behavioral Detection of Command History Clearing
Risk Assessment
| Finding | Severity | Impact |
|---|---|---|
| Clear Command History technique applicable | Low | Defense Evasion |
CWE Categories
| CWE ID | Title |
|---|---|
| CWE-693 | Protection Mechanism Failure |