Skip to content

T1070.003 Clear Command History

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).3

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.2

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.14

Item Value
ID T1070.003
Sub-techniques T1070.001, T1070.002, T1070.003, T1070.004, T1070.005, T1070.006, T1070.007, T1070.008, T1070.009
Tactics TA0005
Platforms Linux, Network, Windows, macOS
Version 1.4
Created 31 January 2020
Last Modified 07 April 2023

Procedure Examples

ID Name Description
G0096 APT41 APT41 attempted to remove evidence of some of its activity by deleting Bash histories.12
S0601 Hildegard Hildegard has used history -c to clear script shell logs.7
S0641 Kobalos Kobalos can remove all command history on compromised hosts.6
G0032 Lazarus Group Lazarus Group has routinely deleted log files on a compromised router, including automatic log deletion through the use of the logrotate utility.8
G0059 Magic Hound Magic Hound has removed mailbox export requests from compromised Exchange servers.9
G0045 menuPass menuPass has used Wevtutil to remove PowerShell execution logs.13
G0139 TeamTNT TeamTNT has cleared command history with history -c.1110

Mitigations

ID Mitigation Description
M1039 Environment Variable Permissions Making the environment variables associated with command history read only may ensure that the history is preserved.5
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.

Detection

ID Data Source Data Component
DS0017 Command Command Execution
DS0022 File File Deletion
DS0002 User Account User Account Authentication

References


  1. jak. (2020, June 27). Live Discover - PowerShell command audit. Retrieved August 21, 2020. 

  2. Microsoft. (2020, May 13). About History. Retrieved September 4, 2020. 

  3. US-CERT. (2018, April 20). Alert (TA18-106A) Russian State-Sponsored Cyber Actors Targeting Network Infrastructure Devices. Retrieved October 19, 2020. 

  4. Vikas, S. (2020, August 26). PowerShell Command History Forensics. Retrieved September 4, 2020. 

  5. Mathew Branwell. (2012, March 21). Securing .bash_history file. Retrieved July 8, 2017. 

  6. M.Leveille, M., Sanmillan, I. (2021, February 2). Kobalos – A complex Linux threat to high performance computing infrastructure. Retrieved August 24, 2021. 

  7. Chen, J. et al. (2021, February 3). Hildegard: New TeamTNT Cryptojacking Malware Targeting Kubernetes. Retrieved April 5, 2021. 

  8. Vyacheslav Kopeytsev and Seongsu Park. (2021, February 25). Lazarus targets defense industry with ThreatNeedle. Retrieved October 27, 2021. 

  9. DFIR Report. (2022, March 21). APT35 Automates Initial Access Using ProxyShell. Retrieved May 25, 2022. 

  10. Darin Smith. (2022, April 21). TeamTNT targeting AWS, Alibaba. Retrieved August 4, 2022. 

  11. Fiser, D. Oliveira, A. (n.d.). Tracking the Activities of TeamTNT A Closer Look at a Cloud-Focused Malicious Actor Group. Retrieved September 22, 2021. 

  12. Fraser, N., et al. (2019, August 7). Double DragonAPT41, a dual espionage and cyber crime operation APT41. Retrieved September 23, 2019. 

  13. GREAT. (2021, March 30). APT10: sophisticated multi-layered loader Ecipekac discovered in A41APT campaign. Retrieved June 17, 2021.