Clearing Windows Console History

Identifies when a user attempts to clear console history. An adversary may clear the command history of a compromised account to conceal the actions undertaken during an intrusion.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2021/11/22"
  3integration = ["endpoint", "windows", "system"]
  4maturity = "production"
  5updated_date = "2024/05/21"
  6
  7[rule]
  8author = ["Austin Songer"]
  9description = """
 10Identifies when a user attempts to clear console history. An adversary may clear the command history of a compromised
 11account to conceal the actions undertaken during an intrusion.
 12"""
 13from = "now-9m"
 14index = [
 15    "winlogbeat-*",
 16    "logs-endpoint.events.process-*",
 17    "logs-windows.*",
 18    "endgame-*",
 19    "logs-system.security*",
 20]
 21language = "eql"
 22license = "Elastic License v2"
 23name = "Clearing Windows Console History"
 24note = """## Triage and analysis
 25
 26### Investigating Clearing Windows Console History
 27
 28PowerShell is one of the main tools system administrators use for automation, report routines, and other tasks. This makes it available for use in various environments, and creates an attractive way for attackers to execute code.
 29
 30Attackers can try to cover their tracks by clearing PowerShell console history. PowerShell has two different ways of logging commands: the built-in history and the command history managed by the PSReadLine module. This rule looks for the execution of commands that can clear the built-in PowerShell logs or delete the `ConsoleHost_history.txt` file.
 31
 32#### Possible investigation steps
 33
 34- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
 35- Identify the user account that performed the action and whether it should perform this kind of action.
 36- Contact the account owner and confirm whether they are aware of this activity.
 37- Investigate other alerts associated with the user/host during the past 48 hours.
 38  - Verify if any other anti-forensics behaviors were observed.
 39- Investigate the PowerShell logs on the SIEM to determine if there was suspicious behavior that an attacker may be trying to cover up.
 40
 41### False positive analysis
 42
 43- This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
 44
 45### Response and remediation
 46
 47- Initiate the incident response process based on the outcome of the triage.
 48- Isolate the involved host to prevent further post-compromise behavior.
 49- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
 50- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 51- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 52- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
 53  - Ensure that PowerShell auditing policies and log collection are in place to grant future visibility.
 54"""
 55references = [
 56    "https://stefanos.cloud/kb/how-to-clear-the-powershell-command-history/",
 57    "https://www.shellhacks.com/clear-history-powershell/",
 58    "https://community.sophos.com/sophos-labs/b/blog/posts/powershell-command-history-forensics",
 59]
 60risk_score = 47
 61rule_id = "b5877334-677f-4fb9-86d5-a9721274223b"
 62setup = """## Setup
 63
 64If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2,
 65events will not define `event.ingested` and default fallback for EQL rules was not added until version 8.2.
 66Hence for this rule to work effectively, users will need to add a custom ingest pipeline to populate
 67`event.ingested` to @timestamp.
 68For more details on adding a custom ingest pipeline refer - https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html
 69"""
 70severity = "medium"
 71tags = [
 72    "Domain: Endpoint",
 73    "OS: Windows",
 74    "Use Case: Threat Detection",
 75    "Tactic: Defense Evasion",
 76    "Tactic: Execution",
 77    "Resources: Investigation Guide",
 78    "Data Source: Elastic Endgame",
 79    "Data Source: Elastic Defend",
 80]
 81timestamp_override = "event.ingested"
 82type = "eql"
 83
 84query = '''
 85process where host.os.type == "windows" and event.type == "start" and
 86  (process.name : ("powershell.exe", "pwsh.exe", "powershell_ise.exe") or ?process.pe.original_file_name == "PowerShell.EXE") and
 87     (process.args : "*Clear-History*" or
 88     (process.args : ("*Remove-Item*", "rm") and process.args : ("*ConsoleHost_history.txt*", "*(Get-PSReadlineOption).HistorySavePath*")) or
 89     (process.args : "*Set-PSReadlineOption*" and process.args : "*SaveNothing*"))
 90'''
 91
 92
 93[[rule.threat]]
 94framework = "MITRE ATT&CK"
 95[[rule.threat.technique]]
 96id = "T1070"
 97name = "Indicator Removal"
 98reference = "https://attack.mitre.org/techniques/T1070/"
 99[[rule.threat.technique.subtechnique]]
100id = "T1070.003"
101name = "Clear Command History"
102reference = "https://attack.mitre.org/techniques/T1070/003/"
103
104
105
106[rule.threat.tactic]
107id = "TA0005"
108name = "Defense Evasion"
109reference = "https://attack.mitre.org/tactics/TA0005/"
110[[rule.threat]]
111framework = "MITRE ATT&CK"
112[[rule.threat.technique]]
113id = "T1059"
114name = "Command and Scripting Interpreter"
115reference = "https://attack.mitre.org/techniques/T1059/"
116[[rule.threat.technique.subtechnique]]
117id = "T1059.001"
118name = "PowerShell"
119reference = "https://attack.mitre.org/techniques/T1059/001/"
120
121
122
123[rule.threat.tactic]
124id = "TA0002"
125name = "Execution"
126reference = "https://attack.mitre.org/tactics/TA0002/"

Triage and analysis

Investigating Clearing Windows Console History

PowerShell is one of the main tools system administrators use for automation, report routines, and other tasks. This makes it available for use in various environments, and creates an attractive way for attackers to execute code.

Attackers can try to cover their tracks by clearing PowerShell console history. PowerShell has two different ways of logging commands: the built-in history and the command history managed by the PSReadLine module. This rule looks for the execution of commands that can clear the built-in PowerShell logs or delete the ConsoleHost_history.txt file.

Possible investigation steps

  • Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
  • Identify the user account that performed the action and whether it should perform this kind of action.
  • Contact the account owner and confirm whether they are aware of this activity.
  • Investigate other alerts associated with the user/host during the past 48 hours.
    • Verify if any other anti-forensics behaviors were observed.
  • Investigate the PowerShell logs on the SIEM to determine if there was suspicious behavior that an attacker may be trying to cover up.

False positive analysis

  • This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Isolate the involved host to prevent further post-compromise behavior.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
  • Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
  • Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
    • Ensure that PowerShell auditing policies and log collection are in place to grant future visibility.

References

Related rules

to-top